From c962ed9425aa4a5c16708d4f155423fa619bee31 Mon Sep 17 00:00:00 2001 From: DeepnaPooja Date: Thu, 3 Sep 2026 17:20:12 +0530 Subject: [PATCH] Add CollectedByUserId to payment DTOs as auth workaround --- .../Features/Payment/FlatPaymentController.cs | 2 +- Distribution/Features/Payment/PaymentDTOs.cs | 12 ++++++++++-- Distribution/Features/Payment/PaymentService.cs | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Distribution/Features/Payment/FlatPaymentController.cs b/Distribution/Features/Payment/FlatPaymentController.cs index 0d5927b..a927c47 100644 --- a/Distribution/Features/Payment/FlatPaymentController.cs +++ b/Distribution/Features/Payment/FlatPaymentController.cs @@ -29,7 +29,7 @@ public class FlatPaymentController(PaymentService service) : ControllerBase { try { - var inner = new CreatePaymentRequest(request.Amount, request.Method); + var inner = new CreatePaymentRequest(request.Amount, request.Method, request.CollectedByUserId); var result = await service.CreateAsync(request.SaleId, inner, ct); return result is null ? NotFound(new { error = "Sale not found or access denied" }) : Ok(result); } diff --git a/Distribution/Features/Payment/PaymentDTOs.cs b/Distribution/Features/Payment/PaymentDTOs.cs index bc125c6..83e978a 100644 --- a/Distribution/Features/Payment/PaymentDTOs.cs +++ b/Distribution/Features/Payment/PaymentDTOs.cs @@ -2,9 +2,17 @@ using Distribution.Models; namespace Distribution.Features.Payment; -public record CreatePaymentRequest(decimal Amount, PaymentMethod Method); +public record CreatePaymentRequest( + decimal Amount, + PaymentMethod Method, + // TEMPORARY: auth middleware doesn't resolve a logged-in user yet — see testbug.md #28. + Guid? CollectedByUserId = null); -public record CreateFlatPaymentRequest(Guid SaleId, decimal Amount, PaymentMethod Method); +public record CreateFlatPaymentRequest( + Guid SaleId, + decimal Amount, + PaymentMethod Method, + Guid? CollectedByUserId = null); public record PaymentResponse( Guid Id, diff --git a/Distribution/Features/Payment/PaymentService.cs b/Distribution/Features/Payment/PaymentService.cs index 9d7b905..e98cdc1 100644 --- a/Distribution/Features/Payment/PaymentService.cs +++ b/Distribution/Features/Payment/PaymentService.cs @@ -44,7 +44,10 @@ public class PaymentService( if (sale.Status == SaleStatus.Cancelled) throw new InvalidOperationException("Cannot record a payment against a cancelled sale"); - var userId = currentUser.UserId ?? throw new UnauthorizedAccessException(); + // TEMPORARY: currentUser.UserId is always unset due to the broken auth middleware + // (testbug.md #28) — fall back to the explicitly supplied user until that's fixed. + var userId = currentUser.UserId ?? request.CollectedByUserId + ?? throw new InvalidOperationException("CollectedByUserId is required while auth is unavailable"); var payment = new Models.Payment {