diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs index f4a2bec3..2060e74b 100644 --- a/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs @@ -22,6 +22,19 @@ public AddTimeSlotCommandValidator(ITimeSlotRepository timeSlotRepository) .MustAsync(TimeSlotNameUnique) .WithErrorCode("TSNU001") .WithMessage("An group with the same name already exists."); + + RuleFor(addTimeSlotCommand => addTimeSlotCommand.StartTime) + .NotEmpty() + .NotNull(); + + RuleFor(addTimeSlotCommand => addTimeSlotCommand.EndTime) + .NotEmpty() + .NotNull(); + + RuleFor(addTimeSlotCommand => addTimeSlotCommand.EndTime) + .GreaterThan(addTimeSlotCommand => addTimeSlotCommand.StartTime) + .WithErrorCode("TSEV001") + .WithMessage("EndTime must be after StartTime."); } private async Task TimeSlotNameUnique(string name, CancellationToken token) diff --git a/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs b/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs index 77466644..8a0dee66 100644 --- a/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs +++ b/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs @@ -19,7 +19,7 @@ public async Task> PagedAsync(IPaginationFilter paginati int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize; return await _dbContext.Set() - .OrderBy(timeSlot => timeSlot.Name) + .OrderBy(timeSlot => timeSlot.EndTime).ThenBy(timeSlot => timeSlot.StartTime) .Skip((paginationFilter.PageNumber - 1) * paginationFilter.PageSize).Take(paginationFilter.PageSize) .ToListAsync(); }