Commit graph

69 commits

Author SHA1 Message Date
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
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
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
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
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
Tiago Yamamoto
77f414bf02 Add database migrations runner 2025-12-20 10:32:54 -03:00
Tiago Yamamoto
25cee3911c chore: refactor backend config, unignore .env, update config loading 2025-12-20 10:10:55 -03:00
Tiago Yamamoto
4bb848788f feat: tenant model, seeder, and product search with distance
Tenant Model:
- Renamed Company→Tenant (Company alias for compatibility)
- Added: lat/lng, city, state, category
- Updated: postgres, handlers, DTOs, schema SQL

Seeder (cmd/seeder):
- Generates 400 pharmacies in Anápolis/GO
- 20-500 products per tenant
- Haversine distance variation ±5km from center

Product Search:
- GET /products/search with advanced filters
- Filters: price (min/max), expiration, distance
- Haversine distance calculation (approx km)
- Anonymous seller (only city/state shown until checkout)
- Ordered by expiration date (nearest first)

New domain types:
- ProductWithDistance, ProductSearchFilter, ProductSearchPage
- HaversineDistance function

Updated tests for Category instead of Role
2025-12-20 09:03:13 -03:00
Tiago Yamamoto
beffeb8268 feat(security): add rate limiting and security headers middleware
Rate Limiting (ratelimit.go):
- Token bucket algorithm per IP
- Default: 100 requests/minute
- X-Forwarded-For support
- Cleanup for stale buckets
- 7 tests (ratelimit_test.go)

Security Headers (security.go):
- X-Content-Type-Options: nosniff
- X-Frame-Options: DENY
- X-XSS-Protection: 1; mode=block
- Content-Security-Policy: default-src 'none'
- Referrer-Policy: strict-origin-when-cross-origin
- Cache-Control: no-store, max-age=0

Middleware coverage: 97.3% -> 95.8% (new code added)
2025-12-20 08:41:36 -03:00
Tiago Yamamoto
45d34f36c8 feat(pagination): add pagination to all list endpoints
Added pagination support to:
- ListCompanies: filter by role, search
- ListProducts: filter by seller, search
- ListOrders: filter by buyer, seller, status
- ListInventory: filter by expiring date, seller

New domain types:
- ProductFilter, ProductPage
- CompanyFilter, CompanyPage
- OrderFilter, OrderPage
- InventoryPage

All endpoints now return paginated responses with:
- items array
- total count
- current page
- page size

Updated MockRepository in both test files to match new signatures
2025-12-20 08:37:59 -03:00
Tiago Yamamoto
b713d8fbed test(middleware): expand coverage 95.9% -> 97.3%
Added tests for:
- Expired token handling
- Wrong signing method rejection (None type attack)
2025-12-20 08:24:03 -03:00
Tiago Yamamoto
16a9ff7ffe test(handler): expand handler test coverage 6.6% -> 44.9%
Added 40+ new handler tests covering:
- Auth: Register, Login (invalid JSON, missing company)
- Company: Get, Update, Delete, Verify, Rating, MyCompany
- Product: Get, Update, Delete (not found, invalid UUID)
- Inventory: List, Adjust (invalid params)
- Order: Create, Get, Update, Delete (validation)
- Payment: Preference, Webhook, Shipment
- Dashboard: Seller, Admin (authorization)
- User: CRUD operations (admin/seller scoping)
- Cart: Add, Get, Delete (context validation)
- Review: Create (validation)

Fixed MockRepository to return errors for not found entities
2025-12-20 08:21:25 -03:00
Tiago Yamamoto
a0720fb4a6 refactor(handler): complete package decomposition - 92% extracted
Final handler package structure (9 files):
- handler.go: 111 lines (Auth: Register, Login)
- dto.go: 220 lines (DTOs, helpers)
- company_handler.go: 228 lines (Companies CRUD)
- product_handler.go: 216 lines (Products + Inventory)
- order_handler.go: 147 lines (Orders CRUD)
- cart_handler.go: 127 lines (Cart + Reviews)
- payment_handler.go: 117 lines (Payments + Shipments)
- dashboard_handler.go: 81 lines (Seller/Admin dashboards)
- user_handler.go: 256 lines (Users CRUD)

Total: 1471 -> 111 lines in handler.go (~92% extracted)
All tests passing
2025-12-20 08:10:56 -03:00
Tiago Yamamoto
a3f00cd8ff refactor(handler): extract order and cart handlers
- Extract 5 order handlers to order_handler.go (147 lines)
  - CreateOrder, ListOrders, GetOrder, UpdateOrderStatus, DeleteOrder
- Extract 4 cart/review handlers to cart_handler.go (127 lines)
  - CreateReview, AddToCart, GetCart, DeleteCartItem
- handler.go reduced from 806 to 548 lines
- Total refactoring: ~63% of original (1471 -> 548)

All tests passing
2025-12-20 08:06:07 -03:00
Tiago Yamamoto
19c636164b refactor(handler): extract product and inventory handlers
- Extract 7 handlers to product_handler.go (216 lines)
  - CreateProduct, ListProducts, GetProduct, UpdateProduct, DeleteProduct
  - ListInventory, AdjustInventory
- handler.go reduced from 1025 to 806 lines
- Total refactoring: ~60% of original (1471 -> 806)

All tests passing
2025-12-20 08:02:02 -03:00
Tiago Yamamoto
e40517aac4 refactor(handler): extract company handlers + update READMEs
Backend:
- Extract 8 company handlers to company_handler.go (228 lines)
- handler.go reduced from 1254 to ~1026 lines
- Total refactoring: ~35% of original handler.go

READMEs updated:
- Backend: new architecture, test coverage table
- Marketplace: new pages (Orders, Inventory, Company, SellerDashboard), Vitest info
2025-12-20 07:58:37 -03:00
Tiago Yamamoto
23df78d9c3 refactor(handler): extract DTOs and helpers to dto.go
- Move 18 request/response structs to dto.go
- Move utility functions (writeJSON, decodeJSON, parseUUID, etc)
- Reduce handler.go from 1471 to 1254 lines (~15% reduction)
- All tests passing
2025-12-20 07:54:35 -03:00
Tiago Yamamoto
b8973739ab feat(backend): add comprehensive test suite for 80% coverage
- Add config_test.go (5 tests for env parsing)
- Add middleware_test.go (16 tests for CORS, Auth, Gzip, Logger)
- Add usecase_test.go (30+ tests for business logic)
- Add payments_test.go (6 tests for MercadoPago gateway)

Coverage: config 100%, middleware 95.9%, payments 100%, usecase 64.7%

feat(marketplace): add test framework and new pages

- Setup Vitest with jsdom environment
- Add cartStore.test.ts (15 tests for Zustand store)
- Add usePersistentFilters.test.ts (5 tests for hook)
- Add apiClient.test.ts (7 tests for axios client)
- Add Orders page with status transitions
- Add Inventory page with stock adjustments
- Add Company page with edit functionality
- Add SellerDashboard page with KPIs

Total marketplace tests: 27 passing
2025-12-20 07:43:56 -03:00