Commit graph

351 commits

Author SHA1 Message Date
Tiago Yamamoto
93da628362 chore: optimize Dockerfiles (distroless) and align JWT config
- Optimized Backoffice Dockerfile: node:22-alpine -> gcr.io/distroless/nodejs22-debian12
- Optimized BFF Dockerfile: python:3.12-slim -> gcr.io/distroless/python3-debian12
- Updated Backoffice Auth to use JWT_SECRET for local verification
- Updated .env.example with correct env vars
2025-12-27 00:36:26 -03:00
Tiago Yamamoto
d1d2f3f338 chore: remove unused parseShippingMethodType function 2025-12-27 00:31:54 -03:00
Tiago Yamamoto
7105549faf test: add handler tests (+9.6% coverage: 36.9% → 46.5%)
Added 26 new handler tests:
- SearchProducts: MissingLatLng, InvalidLat/Lng, Success, WithFilters
- Auth: RegisterCustomer, RegisterTenant, ForgotPassword, ResetPassword, VerifyEmail, Logout
- Pagination: ListProducts, ListCompanies, ListOrders
- Shipping: CalculateShipping, GetShippingSettings
- Reviews: CreateReview, GetCompanyRating
- Dashboard: GetSellerDashboard
- Payments: CreatePaymentPreference, HandlePaymentWebhook
- Shipments: CreateShipment, GetShipmentByOrderID

Handler coverage: 36.9% → 46.5% (+9.6%)
Seeder already has 'Aparecida de Goiânia' (verified)
2025-12-27 00:29:03 -03:00
Tiago Yamamoto
ebd6d903ec test: add comprehensive Asaas gateway tests (+45% payments coverage)
Added 17 new tests for Asaas payment gateway:
- TestNewAsaasGateway, TestAsaasBaseURL_Sandbox/Production
- TestAsaasCreatePreference, TestAsaasCreatePixPayment
- TestAsaasCreateBoletoPayment, TestAsaasConfirmPayment
- TestAsaasRefundPayment, TestAsaasCreateSubaccount
- Context cancellation tests for all methods

Coverage results:
- Payments: 50% → 95.3% (+45%)
- Middleware: 90.8%
- Config: 85.7%
- Server: 69.1%
- Handler: 36.9%
2025-12-27 00:22:52 -03:00
Tiago Yamamoto
3c49df55e4 feat: complete payment gateway implementation (Asaas, Stripe, MercadoPago)
Payment Gateways:
- asaas.go: Pix (QR code), Boleto, Credit Card with split
- Seller subaccount creation for split payments
- 6 new domain types: PixPaymentResult, BoletoPaymentResult, SellerPaymentAccount, Customer, PaymentGatewayConfig

Documentation:
- docs/PAYMENT_GATEWAYS.md: Complete comparison (MercadoPago vs Stripe vs Asaas)
- Admin routes for gateway config
- Seller onboarding routes
- Environment variables reference

Coverage: 50% payments
2025-12-27 00:11:48 -03:00
Tiago Yamamoto
c53cd5a4dd test: add Stripe and Mock gateway tests (+79% payments coverage)
Added 12 new tests for payment gateways:
- TestNewStripeGateway, TestStripeCreatePreference, TestStripeCreatePaymentIntent
- TestNewMockGateway, TestMockCreatePreference, TestMockConfirmPayment, TestMockRefundPayment
- Context cancellation tests for all gateways

Coverage increases:
- Payments: 11.8% → 91.4% (+79.6%)
- Handler: 32.6% → 36.9%
- Middleware: 90.8%
- Config: 85.7%
- Server: 69.1%

Frontend: 95 tests passing
2025-12-26 23:42:38 -03:00
Tiago Yamamoto
8f1e893142 feat: major implementation - seeder, payments, docs
Seeder API:
- 110 pharmacies across 5 cities (Goiânia 72, Anápolis 22, Nerópolis 10, Senador Canedo 5, Aparecida 1)
- 3-300 products per pharmacy
- Dynamic city/state in company records

Payment Gateways:
- stripe.go: Stripe integration with PaymentIntent
- mock.go: Mock gateway with auto-approve for testing
- PaymentResult and RefundResult domain types

Documentation:
- docs/BACKEND.md: Architecture, invisible fee, endpoints
- docs/SEEDER_API.md: City distribution, product counts
- docs/MARKETPLACE.md: Frontend structure, stores, utils
- docs/BACKOFFICE.md: Admin features, encrypted settings
2025-12-26 23:39:49 -03:00
Tiago Yamamoto
12e2503244 feat: implement invisible 12% buyer fee
Business model:
- Seller registers R$10,00 → Seller sees R$10,00 → Seller receives R$10,00
- Buyer searches → sees R$11,20 (+12%) → pays R$11,20
- Marketplace keeps R$1,20 (12%)

Changes:
- config.go: Add BuyerFeeRate (default 0.12)
- handler.go: Add buyerFeeRate field to Handler struct
- product_handler.go: SearchProducts inflates prices for buyers
- server.go: Pass cfg.BuyerFeeRate to handler.New()
- handler_test.go: Fix 3 New() calls with fee rate

Env var: BUYER_FEE_RATE (default: 0.12)
2025-12-26 23:23:18 -03:00
Tiago Yamamoto
285f586371 fix: cart price display showing cents as reais (R19 instead of R.19)
Root cause: Cart.tsx used formatCurrency(819) -> '819,00' instead of formatCents(819) -> 'R$ 8,19'

Changes:
- Cart.tsx: Replace formatCurrency with formatCents at all 5 price display points
- Cart.tsx: Add debug logging (logPrice) to trace price values
- cartStore.ts: Add debug logging for addItem, updateQuantity, etc.
- cartStore.ts: Document unitPrice as CENTS in interface
- cartStore.test.ts: Add 7 new price conversion tests for cents handling

All 95 tests pass.
2025-12-26 23:08:55 -03:00
Tiago Yamamoto
670af4ea67 test: increase test coverage +10% frontend, +2% backend
Backend (+1.8%):
- Add shipping handler tests (GetShippingSettings, UpsertShippingSettings, CalculateShipping)
- Add ListOrders with role filters tests
- Handler coverage: 32.6% → 37.2%

Frontend (+16 tests, 72 → 88):
- Add jwt.test.ts (6 tests)
- Add logger.test.ts (8 tests)
- Add useDebounce.test.ts (5 tests)
2025-12-26 23:02:18 -03:00
Tiago Yamamoto
114e8dc5bc fix: add payment_method column to orders table
Migration 0008: adds payment_method column with default 'pix'
Fixes 500 error: column "payment_method" does not exist
2025-12-26 22:56:46 -03:00
Tiago Yamamoto
f0d64d1801 fix(tests): fix failing tests and increase coverage
Backend:
- Fix TestCreateCompany (added Phone, OperatingHours, Is24Hours)
- Fix TestCreateProduct (added EANCode, Manufacturer, Category, etc)
- Add TestCreateUser, TestListUsers, TestListOrders, TestGetShippingSettings
- All 9 repository tests now pass

Frontend:
- Add shippingService.test.ts (4 tests)
- Add ordersService.test.ts (5 tests)
- Add format.test.ts (9 tests)
- Total tests increased from 54 to 72
2025-12-26 22:54:51 -03:00
Tiago Yamamoto
630bcc9da5 debug: add detailed logging with emojis for orders endpoint
Backend (order_handler.go):
- Log URL, method, pagination
- Log requester role and company ID
- Log role query param and filter values
- Log service call results and errors

Frontend (Orders.tsx):
- Styled console logs with colors
- Log tab, endpoint, response data
- Detailed error logging with response data
2025-12-26 22:44:34 -03:00
Tiago Yamamoto
aaa304c256 feat: add test/coverage and build verification options to start.sh
- Option 7: Run tests with coverage (go test + vitest)
- Option 8: Verify build for backend, marketplace, and backoffice
- Also accessible via --test/-t and --build/-B CLI flags
2025-12-26 22:39:53 -03:00
Tiago Yamamoto
59c0fe7449 fix: filter users by company for ALL non-Admin roles
Previously only 'Seller' role was filtered, but Owner/Colaborador/Entregador roles
were not filtered, causing global admin to appear in pharmacy user lists.
2025-12-26 22:37:23 -03:00
Tiago Yamamoto
61f73c3421 fix: allow buyers to view shipping settings and filter orders by role
- shipping_handler: Remove auth restriction on GetShippingSettings (buyers need to see sellers' shipping options)
- order_handler: Add role query param parsing (buyer/seller) to filter orders by requester's company ID

Fixes 500 errors on:
- GET /api/v1/shipping/settings/{vendor_id}
- GET /api/v1/orders?role=buyer
- GET /api/v1/orders?role=seller
2025-12-26 22:35:27 -03:00
Tiago Yamamoto
240ce9a7e5 feat: add quantity selector, fix offer display, swap filter/location layout
- ProductOffersModal: Add quantity input for each offer when purchasing
- ProductOffersModal: Display offer info in single line with flex-wrap
- GroupedProductCard: Add whitespace-nowrap to prevent 'oferta' badge wrapping
- ProductSearch: Swap Filters and Location components (Filters now first)
- Backend: Refactored admin routes to use role-based access control
- review_handler: New handler with role-based filtering
- shipping_handler: Added ListShipments with role-based filtering
- domain/models: Added SellerID to ReviewFilter and ShipmentFilter
- postgres.go: Updated ListReviews and ListShipments for SellerID filtering
- server.go: Removed /api/v1/admin routes, updated handlers
2025-12-26 22:16:48 -03:00
Tiago Yamamoto
41862b3d5c chore(backend): change swagger endpoint from /swagger to /docs 2025-12-26 22:00:10 -03:00
Tiago Yamamoto
803d371b59 Fix checkout summary rendering 2025-12-26 18:13:01 -03:00
Tiago Yamamoto
ed4349a938 feat: Implement Payment Methods, Shipping Improvements, Swagger Audit, and UUIDv7 Migration
- Payment Methods: Added Pix/Credit/Debit selection in checkout, updated backend models and handlers.

- Shipping: Updated Checkout UI, added shipping_settings table and seed data.

- Swagger: Updated API docs, regenerated swagger.yaml.

- UUIDv7: Migrated seeder and backend tests to use uuid.NewV7().
2025-12-26 17:48:50 -03:00
Tiago Yamamoto
fd305c00a8 fix(marketplace): ensure auth token is set before initial requests 2025-12-26 17:24:57 -03:00
Tiago Yamamoto
e64b3a4855 fix(tests): update mock repo to match interface 2025-12-26 17:09:09 -03:00
Tiago Yamamoto
51a8293a11 fix(auth): support login with email in addition to username 2025-12-26 17:05:12 -03:00
Tiago Yamamoto
73ad7296ca feat(web): redesign login page, fix search bug and enhance seeder 2025-12-23 18:34:46 -03:00
Tiago Yamamoto
baa60c0d9b feat: overhaul shipping module, add seeder, and improve order UI 2025-12-23 18:23:32 -03:00
Tiago Yamamoto
8a5ec57e9c feat: redesign Orders page with tabs for purchases/sales
- Add tabs: 'Pedidos Feitos' (compras) and 'Pedidos Recebidos' (vendas)
- Add stats bar with totals and pending count
- Add progress tracker for purchase orders
- Improved UI with icons and better styling
- Actions only visible on sales tab
2025-12-23 17:32:55 -03:00
Tiago Yamamoto
e39ed59264 fix: use ES module import for logo in Shell.tsx
- Import logoImg from assets instead of hardcoded path
- Fixes logo not displaying in production build
2025-12-23 17:25:00 -03:00
Tiago Yamamoto
607d942072 feat: implement 2-step product registration with new catalog fields
Backend:
- Add ean_code, manufacturer, category, subcategory, observations to Product model
- Create migration 0006_product_catalog_fields.sql
- Update repository queries (CreateProduct, ListProducts, ListRecords)

Frontend:
- Create ProductCreate.tsx with 2-step wizard form
- Add route /products/new
- Add 'Cadastrar Produto' button to Inventory page

Seeder:
- Update CREATE TABLE products with new columns
- Update generateProducts with EAN codes and manufacturers

Docs:
- Update database-schema.md with new fields
2025-12-23 17:09:38 -03:00
Tiago Yamamoto
091e8093c0 feat: apply logo, document database schema, update docs
- Move logo to marketplace/src/assets/
- Apply logo in Shell.tsx header
- Add favicon and meta tags to index.html
- Create docs/database-schema.md with ER diagram
- Update README.md with database section
- Update marketplace/README.md with assets section
- Update seeder-api/README.md with new fields
2025-12-23 17:01:16 -03:00
Tiago Yamamoto
15eb6d42e5 feat(seeder): add phone, operating_hours, is_24_hours to companies table
- Updated SeedLean and SeedFull CREATE TABLE statements
- Added new fields to INSERT statements
- Updated generateTenants to include phone (random), operating_hours, is_24_hours
- Fixes 404 on /api/v1/companies/me due to missing columns
2025-12-23 16:52:06 -03:00
Tiago Yamamoto
8d4731268e feat(marketplace): add company management and user editing features
Backend:
- Add phone, operating_hours, is_24_hours fields to Tenant model
- Create migration 0005_tenants_operating_hours.sql for new columns
- Update postgres repository queries for new fields

Frontend Company.tsx:
- Expand company edit form with phone, city, state
- Add operating hours section with 24h toggle
- Add user edit/delete buttons with Actions column
- Add user edit modal with name, email, role fields
- Add handleDeleteUser and handleSaveUser functions
2025-12-23 16:44:51 -03:00
Tiago Yamamoto
352ef86617 fix(marketplace): filter own products by company_id from JWT
- Add companyId field to AuthUser interface in AuthContext
- Extract company_id from JWT payload in Login.tsx
- Use user.companyId to filter products where seller_id matches
- This properly excludes own store products using UUID comparison
2025-12-23 16:31:46 -03:00
Tiago Yamamoto
2bbb715ebb fix(marketplace): filter out own store products by 0km distance
- For owners/sellers, exclude products at exactly 0km (own pharmacy)
- This correctly hides own products without needing company_id in JWT
2025-12-23 16:29:08 -03:00
Tiago Yamamoto
e7b02f24e7 fix(marketplace): fix modal z-index and button colors
- Change modal z-index from z-50 to z-[1000] to appear above Leaflet map
- Replace bg-primary with bg-blue-600 for visible button styling
- Fix 'Adicionar' button in ProductOffersModal
- Fix 'Ver ofertas' button in GroupedProductCard
2025-12-23 16:23:59 -03:00
Tiago Yamamoto
8ec820c383 feat(marketplace): add cart hover dropdown preview
- Add CartDropdownContent component showing cart items on hover
- Show 'carrinho vazio' message when empty
- Display up to 4 items with name, quantity, price
- Add remove button for each item in dropdown
- Show total and 'Ver carrinho completo' link
- Badge only shows when cart has items (already implemented)
2025-12-23 16:21:48 -03:00
Tiago Yamamoto
299001d8bc feat(marketplace): add functional sort dropdown to ProductSearch
- Add sortBy state with options: price, distance, expiry
- Replace static text with interactive select dropdown
- Implement sorting logic for each option in groupedProducts memo
2025-12-23 16:19:47 -03:00
Tiago Yamamoto
1600591f86 feat(marketplace): improve ProductSearch with grouping, modal, and filters
- Add Shell layout to restore header navigation
- Filter out products from logged-in user's own pharmacy
- Group medications by name (e.g., Losartana 50mg shows as 1 card with '3 offers')
- Create GroupedProductCard component with offer count badge
- Create ProductOffersModal with sorted offers and add-to-cart
- Implement advanced filters (price range, minimum expiry days)
- Add GroupedProduct interface to types
- Sort grouped products by lowest price
2025-12-23 16:13:19 -03:00
Tiago Yamamoto
3a618fa466 chore(marketplace): remove Checkout page and route
- Remove CheckoutPage import from App.tsx
- Remove /checkout route from routing configuration
2025-12-23 16:04:46 -03:00
Tiago Yamamoto
cad6010965 feat(marketplace): replace cart text with icon + badge counter
- Remove Checkout link from header navigation
- Replace 'Carrinho' text with cart SVG icon
- Add red badge showing cart item count (max 99+)
- Import and use cartStore for real-time count updates
2025-12-23 16:01:54 -03:00
Tiago Yamamoto
77d23dac7e feat(marketplace): enable ProductSearch page for pharmacy owners and employees
- Add ProductSearch route at /search with access for owner, seller, employee roles
- Add 'Comprar Medicamentos' button to SellerDashboard header
- Add 'Comprar Medicamentos' button and card to EmployeeDashboard
- Remove redirect that was blocking access to the product search page
2025-12-23 15:59:51 -03:00
Tiago Yamamoto
14eb6c61c8
Merge pull request #49 from rede5/codex/investigate-shipping-data-save-error
Improve shipping settings validation (backend + frontend)
2025-12-23 15:09:08 -03:00
Tiago Yamamoto
32f6fde529 Fix shipping settings validation 2025-12-23 15:08:46 -03:00
Tiago Yamamoto
af99035b8f
Merge pull request #48 from rede5/codex/create-internal-product-display-page
Add internal purchases page with product grouping and distance to customer
2025-12-23 14:46:35 -03:00
Tiago Yamamoto
949398b867 Add internal purchases products page 2025-12-23 14:46:18 -03:00
Tiago Yamamoto
69ec17cd91
Merge pull request #47 from rede5/codex/add-profile-editing-page
Add `/meu-perfil` page and update profile links/routes
2025-12-23 14:36:29 -03:00
Tiago Yamamoto
cc29efa8a0 Add meu-perfil page for profile editing 2025-12-23 14:36:09 -03:00
Tiago Yamamoto
9b5c600f98
Merge pull request #46 from rede5/codex/add-company-configuration-overview
Add company page tabs for overview, users and shipping settings
2025-12-23 14:31:11 -03:00
Tiago Yamamoto
36c0742735 Add company tabs for users and shipping settings 2025-12-23 14:30:55 -03:00
Tiago Yamamoto
f7b56db4dd
Merge pull request #45 from rede5/codex/create-404-and-500-error-pages
Add custom 404 and 500 pages with console logging
2025-12-23 14:17:42 -03:00
Tiago Yamamoto
d059f44d9e Add 404 and 500 error pages with logging 2025-12-23 14:17:20 -03:00