Skip to content

Commit

Permalink
chore: Sort add validations to timeslot
Browse files Browse the repository at this point in the history
Validate that the StartTime and EndTime are present. And that the Endtime is after the StartTime.
  • Loading branch information
LuukvH committed Jul 27, 2024
1 parent 761d4bc commit 8203266
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> TimeSlotNameUnique(string name, CancellationToken token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<IReadOnlyList<TimeSlot>> PagedAsync(IPaginationFilter paginati
int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;

return await _dbContext.Set<TimeSlot>()
.OrderBy(timeSlot => timeSlot.Name)
.OrderBy(timeSlot => timeSlot.EndTime).ThenBy(timeSlot => timeSlot.StartTime)
.Skip((paginationFilter.PageNumber - 1) * paginationFilter.PageSize).Take(paginationFilter.PageSize)
.ToListAsync();
}
Expand Down

0 comments on commit 8203266

Please sign in to comment.