Fix task and shift self-assignment features
This commit is contained in:
@@ -17,7 +17,7 @@ public class ShiftService
|
||||
_tenantProvider = tenantProvider;
|
||||
}
|
||||
|
||||
public async Task<ShiftListDto> GetShiftsAsync(DateTimeOffset? from, DateTimeOffset? to, int page, int pageSize)
|
||||
public async Task<ShiftListDto> GetShiftsAsync(DateTimeOffset? from, DateTimeOffset? to, int page, int pageSize, string? currentExternalUserId = null)
|
||||
{
|
||||
var query = _context.Shifts.AsQueryable();
|
||||
|
||||
@@ -42,19 +42,37 @@ public class ShiftService
|
||||
.Select(g => new { ShiftId = g.Key, Count = g.Count() })
|
||||
.ToDictionaryAsync(x => x.ShiftId, x => x.Count);
|
||||
|
||||
var tenantId = _tenantProvider.GetTenantId();
|
||||
var memberId = currentExternalUserId != null
|
||||
? await _context.Members
|
||||
.Where(m => m.ExternalUserId == currentExternalUserId && m.TenantId == tenantId)
|
||||
.Select(m => (Guid?)m.Id)
|
||||
.FirstOrDefaultAsync()
|
||||
: null;
|
||||
|
||||
var userSignups = memberId.HasValue
|
||||
? await _context.ShiftSignups
|
||||
.Where(ss => shiftIds.Contains(ss.ShiftId) && ss.MemberId == memberId.Value)
|
||||
.Select(ss => ss.ShiftId)
|
||||
.ToListAsync()
|
||||
: new List<Guid>();
|
||||
|
||||
var userSignedUpShiftIds = userSignups.ToHashSet();
|
||||
|
||||
var items = shifts.Select(s => new ShiftListItemDto(
|
||||
s.Id,
|
||||
s.Title,
|
||||
s.StartTime,
|
||||
s.EndTime,
|
||||
s.Capacity,
|
||||
signupCounts.GetValueOrDefault(s.Id, 0)
|
||||
signupCounts.GetValueOrDefault(s.Id, 0),
|
||||
userSignedUpShiftIds.Contains(s.Id)
|
||||
)).ToList();
|
||||
|
||||
return new ShiftListDto(items, total, page, pageSize);
|
||||
}
|
||||
|
||||
public async Task<ShiftDetailDto?> GetShiftByIdAsync(Guid id)
|
||||
public async Task<ShiftDetailDto?> GetShiftByIdAsync(Guid id, string? currentExternalUserId = null)
|
||||
{
|
||||
var shift = await _context.Shifts.FindAsync(id);
|
||||
|
||||
@@ -75,6 +93,8 @@ public class ShiftService
|
||||
ss.SignedUpAt
|
||||
)).ToList();
|
||||
|
||||
var isSignedUp = currentExternalUserId != null && signupDtos.Any(s => s.ExternalUserId == currentExternalUserId);
|
||||
|
||||
return new ShiftDetailDto(
|
||||
shift.Id,
|
||||
shift.Title,
|
||||
@@ -87,7 +107,8 @@ public class ShiftService
|
||||
shift.ClubId,
|
||||
shift.CreatedById,
|
||||
shift.CreatedAt,
|
||||
shift.UpdatedAt
|
||||
shift.UpdatedAt,
|
||||
isSignedUp
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,13 +147,14 @@ public class ShiftService
|
||||
shift.ClubId,
|
||||
shift.CreatedById,
|
||||
shift.CreatedAt,
|
||||
shift.UpdatedAt
|
||||
shift.UpdatedAt,
|
||||
false
|
||||
);
|
||||
|
||||
return (dto, null);
|
||||
}
|
||||
|
||||
public async Task<(ShiftDetailDto? shift, string? error, bool isConflict)> UpdateShiftAsync(Guid id, UpdateShiftRequest request)
|
||||
public async Task<(ShiftDetailDto? shift, string? error, bool isConflict)> UpdateShiftAsync(Guid id, UpdateShiftRequest request, string? currentExternalUserId = null)
|
||||
{
|
||||
var shift = await _context.Shifts.FindAsync(id);
|
||||
|
||||
@@ -182,6 +204,8 @@ public class ShiftService
|
||||
ss.SignedUpAt
|
||||
)).ToList();
|
||||
|
||||
var isSignedUp = currentExternalUserId != null && signupDtos.Any(s => s.ExternalUserId == currentExternalUserId);
|
||||
|
||||
var dto = new ShiftDetailDto(
|
||||
shift.Id,
|
||||
shift.Title,
|
||||
@@ -194,7 +218,8 @@ public class ShiftService
|
||||
shift.ClubId,
|
||||
shift.CreatedById,
|
||||
shift.CreatedAt,
|
||||
shift.UpdatedAt
|
||||
shift.UpdatedAt,
|
||||
isSignedUp
|
||||
);
|
||||
|
||||
return (dto, null, false);
|
||||
|
||||
Reference in New Issue
Block a user