fix(backend): resolve shift signup by looking up Member via ExternalUserId
The signup/cancel endpoints were passing the Keycloak sub claim (external UUID) directly as MemberId, but ShiftSignup.MemberId references the internal Member.Id. Now ShiftService resolves ExternalUserId to the internal Member.Id before creating the signup record. Integration tests updated to seed proper Member entities.
This commit is contained in:
@@ -118,17 +118,17 @@ public static class ShiftEndpoints
|
||||
ShiftService shiftService,
|
||||
HttpContext httpContext)
|
||||
{
|
||||
var userIdClaim = httpContext.User.FindFirst("sub")?.Value;
|
||||
if (string.IsNullOrEmpty(userIdClaim) || !Guid.TryParse(userIdClaim, out var memberId))
|
||||
var externalUserId = httpContext.User.FindFirst("sub")?.Value;
|
||||
if (string.IsNullOrEmpty(externalUserId))
|
||||
{
|
||||
return TypedResults.UnprocessableEntity("Invalid user ID");
|
||||
}
|
||||
|
||||
var (success, error, isConflict) = await shiftService.SignUpForShiftAsync(id, memberId);
|
||||
var (success, error, isConflict) = await shiftService.SignUpForShiftAsync(id, externalUserId);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
if (error == "Shift not found")
|
||||
if (error == "Shift not found" || error == "Member not found")
|
||||
return TypedResults.NotFound();
|
||||
|
||||
if (error == "Cannot sign up for past shifts")
|
||||
@@ -146,17 +146,17 @@ public static class ShiftEndpoints
|
||||
ShiftService shiftService,
|
||||
HttpContext httpContext)
|
||||
{
|
||||
var userIdClaim = httpContext.User.FindFirst("sub")?.Value;
|
||||
if (string.IsNullOrEmpty(userIdClaim) || !Guid.TryParse(userIdClaim, out var memberId))
|
||||
var externalUserId = httpContext.User.FindFirst("sub")?.Value;
|
||||
if (string.IsNullOrEmpty(externalUserId))
|
||||
{
|
||||
return TypedResults.UnprocessableEntity("Invalid user ID");
|
||||
}
|
||||
|
||||
var (success, error) = await shiftService.CancelSignupAsync(id, memberId);
|
||||
var (success, error) = await shiftService.CancelSignupAsync(id, externalUserId);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
if (error == "Sign-up not found")
|
||||
if (error == "Sign-up not found" || error == "Member not found")
|
||||
return TypedResults.NotFound();
|
||||
|
||||
return TypedResults.UnprocessableEntity(error!);
|
||||
|
||||
Reference in New Issue
Block a user