Dev #23
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user