Commit graph

86 commits

Author SHA1 Message Date
Tiago Yamamoto
89036d7b39 docs: add detailed mermaid diagrams for db, backend and marketplace 2025-12-27 01:13:11 -03:00
Tiago Yamamoto
53385670a3 feat: consolidate admin/seller dashboard, remove bff, fix backoffice docker, update docs 2025-12-27 00:58:06 -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
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
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
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
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
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
32f6fde529 Fix shipping settings validation 2025-12-23 15:08:46 -03:00
Tiago Yamamoto
abf636ab65 fix(backend): handle NULL shipping fields in orders queries with COALESCE 2025-12-22 15:50:02 -03:00
Tiago Yamamoto
9fc9b211bf fix(backend): add db tags to TopProduct struct for sqlx mapping 2025-12-22 15:38:56 -03:00
Tiago Yamamoto
6df111abfa chore(backend): add lib/pq dependency for PostgreSQL array support 2025-12-22 15:32:47 -03:00
Tiago Yamamoto
2a602ab09e fix(backend): use pq.Array for PostgreSQL array syntax in dashboard queries 2025-12-22 15:27:30 -03:00
Tiago Yamamoto
b0b96d469c Add review and shipment admin listing endpoints 2025-12-22 10:15:27 -03:00
Tiago Yamamoto
35495b4728 fix(backend): properly load .env file manually in config.go 2025-12-22 09:47:17 -03:00
Tiago Yamamoto
08d98aaeca fix: improve login error handling for invalid credentials 2025-12-22 09:31:33 -03:00
Tiago Yamamoto
4ccfa629cc feat: add admin reviews, logistics, profile pages and update seeder 2025-12-22 09:08:42 -03:00
Tiago Yamamoto
e624d642aa feat: RBAC implementation and Seeder refactor 2025-12-22 01:30:55 -03:00
Tiago Yamamoto
9ad6d87590 fix(backend): add missing Username field to admin seeding 2025-12-22 00:45:30 -03:00
Tiago Yamamoto
a160321ca2 chore(backend): remove unused go dependencies 2025-12-22 00:38:55 -03:00
Tiago Yamamoto
c9a08c8621 test: add automated tests for admin login
Backend:
- TestAdminLogin_Success: verify admin login with username
- TestAdminLogin_WrongPassword: verify 401 for wrong password

Frontend (Marketplace):
- auth.test.ts: mocked tests for login/logout (5 tests)
- auth.integration.test.ts: real API tests (3 tests, skipped in CI)
2025-12-22 00:31:26 -03:00
Tiago Yamamoto
9997aed18a fix(backend): fix build errors, update tests, and improve documentation
- Add GetUserByEmail to Repository interface for password reset flow
- Add username to UpdateUser query
- Fix config_test.go: remove references to deleted DB pool fields
- Fix handler_test.go: add GetUserByUsername to MockRepository
- Fix usecase_test.go: add GetUserByUsername and update auth tests
- Update backend README with auth and admin seeding info
- Create seeder-api README with usage and warnings
2025-12-21 23:11:33 -03:00
Tiago Yamamoto
4612172b3c feat(backend): switch auth to username and cleanup db config 2025-12-21 23:04:47 -03:00
Tiago Yamamoto
b72f8f3099 Add full auth endpoints and swagger updates 2025-12-21 22:37:54 -03:00
Tiago Yamamoto
276b6bb923 refactor(backend): rename SWAGGER_HOST to BACKEND_HOST
Renames SWAGGER_HOST to BACKEND_HOST in .env.example and config. Updates main.go to use the new configuration variable.
2025-12-21 22:21:37 -03:00
Tiago Yamamoto
73ebe3ec6d Add swagger host/scheme env config 2025-12-21 22:16:11 -03:00
Tiago Yamamoto
8ab398723d Relax CSP for Swagger docs 2025-12-21 22:10:03 -03:00
Tiago Yamamoto
fd237cd9c4 fix(backend): resolving hardcoded values and test failures
Updates .env.example with missing variables. Adds missing security headers in middleware. Fixes repository tests including timezone issues and sqlmock expectations.
2025-12-21 21:43:50 -03:00
Tiago Yamamoto
4ad6a0aae5 Add marketplace record search and audit trigger 2025-12-21 17:36:17 -03:00
Tiago Yamamoto
ab138b6436 chore(deps): update go modules 2025-12-20 11:13:53 -03:00
Tiago Yamamoto
bad6d15a60 refactor: move seeder to api, improve coverage and security 2025-12-20 11:13:53 -03:00
Tiago Yamamoto
e73d423b16 refactor: move seeder to api, improve coverage and security 2025-12-20 11:13:53 -03:00
Tiago Yamamoto
fd60888706 Add shipping settings and calculation 2025-12-20 10:47:37 -03:00