Ho Ngoc Hai
97b54ebd39
fix(security): fix 5 P1 backend issues — BACK-C-01/03/04, BACK-W-02
...
BACK-W-02: Replace string-interpolated SET LOCAL SQL with parameterized
set_config() calls in TenantMiddleware across 5 services (order, wallet,
inventory, catalog, fnb-engine). Eliminates SQL injection pattern;
set_config(key, $1, true) is local-to-transaction, same semantics as SET LOCAL.
BACK-C-01: Remove AllowAnyOrigin() from all 26 services. Switch to
WithOrigins() reading AllowedOrigins config array, with dev-only fallback
to localhost. In production, set AllowedOrigins=["https://goodgo.vn ",
"https://admin.goodgo.vn "] via environment config.
BACK-C-03: Standardize OrdersController GET /orders/{id} 404 response
from {Message:...} to {success:false, error:{code,message}} per API contract.
BACK-C-04: Add complete ProblemDetails exception mappings to _template_dot_net:
ValidationException -> 400, DomainException -> 422, with TODO comments
for service-specific types (EntityNotFoundException -> 404, etc.).
BACK-C-02: wallet-service and booking-service already have full
IRequestManager idempotency implementation — no changes needed.
Co-Authored-By: Paperclip <noreply@paperclip.ing >
2026-03-23 09:48:22 +07:00
Ho Ngoc Hai
25f68781ad
fix(security): fix 5 P0 security blockers — SEC-C-01 through SEC-C-05
...
SEC-C-01: Replace Neon PostgreSQL credentials (npg_Ssfy6HKO0cXI) with local
dev connection strings in all 19 appsettings.json files. Production credentials
must be injected via ConnectionStrings__DefaultConnection env var. Add
appsettings.Production.json and appsettings.Staging.json to .gitignore.
SEC-C-02: Add services/goodgo-mcp-server/.env to root .gitignore. Create
.env.example with safe placeholder values documenting required variables.
SEC-C-03: Wrap AddDeveloperSigningCredential() in env check — development only.
Non-development environments must provide X.509 certificate via
IdentityServer:SigningCertificatePath and IdentityServer:SigningCertificatePassword.
SEC-C-04: Remove 4 unauthenticated debug endpoints from StaffController:
GET debug/all, POST debug/seed, POST debug/update-userid, POST debug/update-merchant.
These endpoints allowed privilege escalation and data exfiltration without auth.
SEC-C-05: Removed endpoints containing SQL injection via string interpolation
(lines 307, 367 in StaffController). Also removed [AllowAnonymous] from
GET lookup endpoint — inherits class-level [Authorize].
BREAKING: debug/* endpoints are permanently removed. BFF lookup endpoint now
requires authentication.
Co-Authored-By: Paperclip <noreply@paperclip.ing >
2026-03-23 09:47:07 +07:00
Ho Ngoc Hai
f8606e0447
fix(P0): security hardening + critical bug fixes across 22 services
...
Wave 1 — 6 parallel agents fixing P0 issues from code audit:
Auth (18 services secured):
- Added JWT Bearer auth + [Authorize] to all unprotected controllers
- Webhook endpoints (Facebook/WhatsApp/Zalo/X) stay [AllowAnonymous]
- Health checks remain public for Docker/K8s probes
- Services: catalog, order, booking, fnb-engine, inventory, social,
ads-manager, ads-serving, ads-billing, ads-tracking, ads-analytics,
mkt-facebook, mkt-whatsapp, mkt-x, mkt-zalo, promotion
Template artifacts (4 services):
- mission-service: myservice_db → mission_service
- mkt-facebook: Dockerfile MyService.API → FacebookService.API
- mkt-whatsapp: MyServiceContext.cs → WhatsAppServiceContext.cs
- promotion: UserSecretsId fixed
Critical handler bugs (7 fixes):
- ads-tracking: TrackPixelEventHandler now persists to DB
- ads-tracking: RecordConversion endpoint exposed via controller
- booking: UpdateResource now applies Name + Capacity changes
- ads-manager: ListPendingAds uses correct enum (pending_review)
- mining: BanMiner calls Ban() not Suspend()
- mining: ResetMinerStreak now actually resets streak
- mkt-x: 8 missing repository DI registrations added
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-13 20:18:09 +07:00
Ho Ngoc Hai
f3779c4ebe
docs: add SERVICE_DOCS.md for all 24 microservices from per-service code audit
...
Each SERVICE_DOCS.md documents: Overview, API Endpoints, Commands, Queries,
Domain Model, Database Schema, Integration Events, Dependencies, Configuration.
Generated by 23 parallel audit agents reading actual source code.
Key corrections from audit:
- inventory-service: 12 commands/6 queries (was listed as scaffold)
- promotion-service: 12 commands/10 queries (was listed as 0)
- mission-service: 4 commands/7 queries (was listed as 0)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-13 17:54:53 +07:00
Ho Ngoc Hai
aba5ee1162
fix: resolve inventory display bugs — transaction history & item type mapping
...
- Fix DTO field mismatch: QuantityChange→Quantity, Reason→Notes in PosDataService
- Fix ItemType enum mismatch: FinishedProduct→FinishedGood, Supply→Consumable in ShopInventory
- Add ResolveTransactionTypeName fallback in InventoryMapper when Type nav property is null
- Add "In"/"Out" alternative matches for TransactionType in history display
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-13 13:54:44 +07:00
Ho Ngoc Hai
0d03feeffd
feat: Phase 2 multi-vertical expansion — Spa appointments, Retail POS, Cafe loyalty
...
Spa/Beauty (booking-service) — Therapist + Appointment scheduling:
- Therapist aggregate: specialties (text[]), workingHours (jsonb), CRUD
- Appointment: notes field, Pending initial status, MarkNoShow() behavior
- TherapistsController (4 endpoints), 9 FluentValidation validators
- EF config: PostgreSQL native text[] + jsonb column types
Retail POS (catalog + inventory + order) — Barcode, stock, returns:
- Product: barcode/SKU fields, GetProductByBarcodeQuery (lookup endpoint)
- Inventory: bulk stock check, low stock alert threshold (SetReorderLevel)
- Order: return/exchange flow with ProcessReturn(), Returned status (id=8)
- CreateReturnCommand, CreateExchangeCommand (same UnitOfWork)
- 2 domain events: OrderReturnedDomainEvent, OrderExchangedDomainEvent
- 6 new API endpoints across 3 services
Cafe (membership + fnb-engine) — Loyalty stamps + barista queue:
- StampCard aggregate: AddStamp(), ClaimReward(), Reset(), 4 domain events
- Auto-create card on first stamp (friction-free UX)
- StampCardsController (6 endpoints), 4 commands, 2 queries
- BaristaQueueItem: 5-status workflow (Queued→Preparing→Ready→Delivered)
- BaristaController (6 endpoints), 5 commands, 2 queries
- Tenant isolation (shop-level) on both features
ROADMAP: Phase 1 closed out, Phase 2 vertical tasks IN-PROGRESS
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 16:45:43 +07:00
Ho Ngoc Hai
a7a753bf38
feat: EOD reports, security audit (rate limiting + 44 validators), and 30 critical path tests
...
EOD Reports & Daily Close (order-service + Blazor UI):
- GetEodReportQuery: Dapper query for revenue, orders, payment breakdown, top items, hourly chart
- CloseDayCommand: check pending orders, generate final report
- EodReport.razor: 6 KPI cards, donut/bar charts, top 10 table, close-day dialog
- FluentValidation for both query and command
- BFF proxy endpoints for reports
Security Audit — Rate Limiting:
- Tighten auth-ratelimit from 100 to 10 req/min (brute force protection)
- Add payment-ratelimit (30/min), api-ratelimit (100/min), hub-ratelimit (500/min)
- Apply rate limits to ALL Traefik routers (previously many had none)
Security Audit — Input Sanitization (44 missing validators created):
- iam-service: 14 validators (auth, user, role commands)
- merchant-service: 11 validators (admin, attendance commands)
- wallet-service: 7 validators (wallet, points commands)
- fnb-engine: 7 validators (session, table, ticket, reservation)
- catalog-service: 6 validators (product, category CRUD)
- storage-service: 6 validators (upload, share, quota)
- order-service: 2 validators (complete order/payment)
Critical Path Unit Tests (30 new tests):
- inventory-service: 12 tests (deduction, partial stock, idempotency)
- wallet-service: 14 tests (create payment, process callback, domain events)
- fnb-engine: 8 tests (kitchen-served event handler, inventory client integration)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 16:33:39 +07:00
Ho Ngoc Hai
653322b26c
fix: resolve 12 critical/high issues from code review across backend, frontend, and infra
...
Backend (7 fixes):
- wallet-service: remove conflicting EF Ignore() calls for mapped backing fields
- fnb-engine: remove KitchenTicket short constructor that set productId=orderItemId
- fnb-engine: replace fire-and-forget Task.Run with direct await for inventory deduction
- TenantMiddleware: implement PostgreSQL RLS SET LOCAL in 4 services (wallet, fnb, inventory, catalog)
- order-service: fix SQL injection pattern in TenantMiddleware with Guid.ToString("D")
- order-service: add ValidateShopAccess() authorization check in SignalR PosHub
- 4 services: register IDbConnection (NpgsqlConnection) in DI for RLS middleware
Frontend (3 fixes):
- PosDataService: return Success=false (not true) when PayOrder response parsing fails
- QrPayment: add _disposed guard to prevent timer race condition after component disposal
- BFF OrderController: add [Authorize] attribute to require JWT for all endpoints
Infrastructure (3 fixes):
- docker-compose: upgrade PostgreSQL 15-alpine to 16-alpine per project spec
- init-databases.sh: add 4 missing marketing service databases (mkt_*)
- Traefik routes: add wallet, catalog, booking routers and /api/v1/stock path
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 16:22:08 +07:00
Ho Ngoc Hai
6061164873
feat: add multi-tenant row-level security across 5 services and 96 FnB engine unit tests
...
Security (P0-5):
- Implement ITenantProvider + HttpContextTenantProvider per service (order, fnb, inventory, catalog, wallet)
- Add EF Core global query filters for tenant isolation (shop_id/user_id based)
- Add TenantMiddleware setting PostgreSQL session variables for RLS
- Create PostgreSQL RLS policies script (scripts/db/rls-policies.sql)
- Adapter pattern bridges API-layer to Infrastructure-layer (Clean Architecture)
- Bypass mechanisms for admin roles, service-to-service calls, and migrations
Testing (P1-12):
- Add 96 unit tests for fnb-engine (up from 3)
- 57 domain entity tests: Table(18), KitchenTicket(12), Session(8), Reservation(13), Recipe(6)
- 39 command handler tests: CRUD operations, status transitions, validation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 13:40:34 +07:00
Ho Ngoc Hai
8af86e9e89
feat: implement Phase 1 payment gateway, real-time SignalR, kitchen-inventory deduction, and order payment flow
...
- wallet-service: IPaymentGateway abstraction + VN Pay implementation (HMAC-SHA512, sandbox), Payment aggregate root, PaymentsController with create/callback/query endpoints
- order-service: PosHub SignalR hub with Redis backplane + MessagePack, strongly-typed clients, 3 group types (shop/kds/pos), integrated into Create/Pay/Complete/Cancel order handlers
- fnb-engine + inventory-service: Kitchen→Inventory auto-deduction via domain events, HTTP with Polly retry + circuit breaker, idempotency check, graceful degradation on insufficient stock
- order-service: Enhanced PayOrderCommand with 3 flows (cash/card/online), PaymentPending status, WalletServiceClient, CompleteOrderPaymentCommand for gateway callbacks
- POS frontend: Cash/Card/QR payment components wired to real backend, BFF proxy updated
- infra: Traefik routes for fnb-engine, inventory-service, and SignalR WebSocket hub
- ROADMAP.md: Updated with Phase 1 progress tracking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-06 13:28:46 +07:00
Ho Ngoc Hai
fd75da34dc
feat: enhance inventory management with new item types, stocktake, wastage, and recipe-based deductions
2026-03-05 22:28:45 +07:00
Ho Ngoc Hai
df7eec1ec2
feat(web-client-tpos, inventory-service): implement percentage-based campaigns and enrich inventory with product names
2026-03-04 20:22:54 +07:00
Ho Ngoc Hai
64e7b4e00d
refactor: update EF Core backing field mapping and ignore DDD enumeration types
2026-03-04 12:36:19 +07:00
Ho Ngoc Hai
37042b48b7
feat(inventory-service): add shopId filter to transactions endpoint
...
BFF needs to query inventory transactions by shopId. The existing
endpoint only supported inventoryItemId. Now accepts either shopId
or inventoryItemId as query parameters.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com >
2026-03-04 10:35:54 +07:00
Ho Ngoc Hai
751f90c365
feat: Log EF Core migration errors instead of crashing the application at startup across all services.
2026-02-28 01:03:43 +07:00
Ho Ngoc Hai
be86e48de6
feat: automatically apply EF Core database migrations on service startup across all services
2026-02-28 00:51:35 +07:00
Ho Ngoc Hai
f521cc0a91
chore: Remove the web-client application, add a local database initialization script, and update service Dockerfiles.
2026-02-28 00:41:17 +07:00
Cursor Agent
4751929a3e
fix: switch JWT Bearer auth from symmetric key to OIDC discovery in 5 microservices
...
Replace manual SymmetricSecurityKey validation with Authority-based OIDC
discovery so tokens are validated against RSA keys published by the IAM
IdentityServer's discovery endpoint.
Services updated:
- CatalogService.API
- OrderService.API
- InventoryService.API
- FnbEngine.API
- BookingService.API
Co-authored-by: Velik <hongochai10@users.noreply.github.com >
2026-02-26 22:51:57 +00:00
Cursor Agent
c789f964a8
Add JWT Bearer authentication registration to 5 microservice Program.cs files
...
Add AddAuthentication(JwtBearerDefaults.AuthenticationScheme) and
AddJwtBearer() service registration before CORS configuration in:
- CatalogService.API
- OrderService.API
- InventoryService.API
- FnbEngine.API
- BookingService.API
Also add Microsoft.AspNetCore.Authentication.JwtBearer v10.0.1 NuGet
package reference to each service's .csproj file.
This fixes the runtime error caused by UseAuthentication() being called
without a registered authentication scheme.
Co-authored-by: Velik <hongochai10@users.noreply.github.com >
2026-02-26 22:51:57 +00:00
Cursor Agent
2fcf73b33f
Add UseAuthentication and UseAuthorization middleware after UseRouting in 5 microservices
...
Added app.UseAuthentication() and app.UseAuthorization() after
app.UseRouting() in the middleware pipeline for:
- CatalogService.API
- OrderService.API
- InventoryService.API
- FnbEngine.API
- BookingService.API
Co-authored-by: Velik <hongochai10@users.noreply.github.com >
2026-02-26 22:51:57 +00:00
Cursor Agent
d1cfef93cf
test: replace mission and commerce sample functional suites
...
Co-authored-by: Velik <hongochai10@users.noreply.github.com >
2026-02-23 12:56:57 +00:00
Ho Ngoc Hai
83a8db2942
feat: Implement new API endpoints, application logic, and domain repositories across FnbEngine, BookingService, and OrderService, alongside minor infrastructure updates.
2026-01-18 02:51:10 +07:00
Ho Ngoc Hai
4c9e12e99c
feat: Implement a new Inventory Service API, add admin budget and frequency controllers to Ads Serving, and introduce product and category controllers to Catalog Service.
2026-01-18 01:21:09 +07:00
Ho Ngoc Hai
b1931be440
feat: Implement initial entity configurations for ads billing, analytics, and serving, add catalog product and category commands/queries, and refine booking service infrastructure.
2026-01-18 01:15:51 +07:00
Ho Ngoc Hai
4abd842c0d
feat: replace Sample aggregate with Appointment aggregate in BookingService.
2026-01-18 01:05:51 +07:00
Ho Ngoc Hai
2285013e2d
chore: Remove sample aggregate domain entities, events, exceptions, and repository interface.
2026-01-18 01:04:03 +07:00
Ho Ngoc Hai
5b0b72cbac
refactor: remove the Sample entity, its API controller, commands, queries, validations, and associated handlers and tests.
2026-01-18 01:03:49 +07:00
Ho Ngoc Hai
dc55dda87a
feat: Remove Sample aggregate, refactor database context to FnbContext, and introduce Table aggregate with its configurations, alongside adding an inventory repository interface.
2026-01-18 01:03:36 +07:00
Ho Ngoc Hai
04933be6dd
feat: Implement inventory domain by replacing generic service context with dedicated inventory context, entities, and repository.
2026-01-18 01:01:07 +07:00
Ho Ngoc Hai
5626c3495b
refactor: Update Dockerfiles to use service-specific project names instead of generic 'MyService'.
2026-01-18 00:23:39 +07:00
Ho Ngoc Hai
811ddd1e19
feat: Add functional tests for OrderService and update InventoryService command and idempotency logic.
2026-01-18 00:19:46 +07:00
Ho Ngoc Hai
844e40f818
config: Update local application ports and switch database connection strings to Neon.tech for multiple services.
2026-01-17 23:28:35 +07:00
Ho Ngoc Hai
19c0acfe0f
feat: Add new unit tests, domain exceptions, documentation, and various build artifacts across multiple services.
2026-01-17 23:04:15 +07:00