-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic child scheduling feature.
- Loading branch information
Showing
22 changed files
with
584 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Services/Scheduling/Api/Controllers/SchedulesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using KDVManager.Services.Scheduling.Application.Features.Groups.Queries.ListGroups; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Pagination; | ||
using KDVManager.Services.Scheduling.Application.Features.Schedules.Queries.GetChildSchedules; | ||
using System.Net; | ||
using KDVManager.Services.Scheduling.Application.Features.Schedules.Commands.AddSchedule; | ||
|
||
namespace KDVManager.Services.Scheduling.Api.Controllers; | ||
|
||
[ApiController] | ||
[Route("v1/[controller]")] | ||
public class SchedulesController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ILogger<SchedulesController> _logger; | ||
|
||
public SchedulesController(IMediator mediator, ILogger<SchedulesController> logger) | ||
{ | ||
_logger = logger; | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpGet("", Name = "GetChildSchedules")] | ||
public async Task<ActionResult<PagedList<ChildScheduleListVM>>> ListScheduleItems([FromQuery] GetChildSchedulesQuery getChildSchedulesQuery) | ||
{ | ||
var dtos = await _mediator.Send(getChildSchedulesQuery); | ||
return Ok(dtos); | ||
} | ||
|
||
[HttpPost(Name = "AddSchedule")] | ||
[ProducesResponseType(typeof(Guid), (int)HttpStatusCode.OK)] | ||
[ProducesResponseType(typeof(UnprocessableEntityResponse), (int)HttpStatusCode.UnprocessableEntity)] | ||
public async Task<ActionResult<Guid>> AddScheduleItem([FromBody] AddScheduleCommand addScheduleCommand) | ||
{ | ||
var id = await _mediator.Send(addScheduleCommand); | ||
return Ok(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Contracts\" /> | ||
<Folder Include="Exceptions\" /> | ||
<Folder Include="Profiles\" /> | ||
<Folder Include="Features\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Domain\Domain.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||
<PackageReference Include="AutoMapper" Version="12.0.1" /> | ||
<PackageReference Include="FluentValidation" Version="11.9.2" /> | ||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" /> | ||
</ItemGroup> | ||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Folder Include="Contracts\" /> | ||
<Folder Include="Exceptions\" /> | ||
<Folder Include="Profiles\" /> | ||
<Folder Include="Features\" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Domain\Domain.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> | ||
<PackageReference Include="AutoMapper" Version="12.0.1" /> | ||
<PackageReference Include="FluentValidation" Version="11.9.2" /> | ||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> | ||
</ItemGroup> | ||
</Project> |
13 changes: 13 additions & 0 deletions
13
src/Services/Scheduling/Application/Contracts/Persistence/IScheduleRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
using KDVManager.Services.Scheduling.Domain.Entities; | ||
using KDVManager.Services.Scheduling.Domain.Interfaces; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
|
||
public interface IScheduleRepository : IAsyncRepository<Schedule> | ||
{ | ||
Task<IReadOnlyList<Schedule>> GetSchedulesByChildIdAsync(Guid childId); | ||
} |
26 changes: 26 additions & 0 deletions
26
...ices/Scheduling/Application/Features/Schedules/Commands/AddSchedule/AddScheduleCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using MediatR; | ||
using System.Collections.Generic; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.Schedules.Commands.AddSchedule; | ||
|
||
public class AddScheduleCommand : IRequest<Guid> | ||
{ | ||
public Guid ChildId { get; set; } | ||
|
||
public Guid GroupId { get; set; } | ||
|
||
public DateTime StartDate { get; set; } | ||
|
||
public DateTime? EndDate { get; set; } | ||
|
||
// Collection of nested schedules | ||
public ICollection<ScheduleRule> ScheduleRules { get; set; } = new List<ScheduleRule>(); | ||
|
||
public class ScheduleRule | ||
{ | ||
public DayOfWeek Day { get; set; } | ||
|
||
public Guid TimeSlotId { get; set; } | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...heduling/Application/Features/Schedules/Commands/AddSchedule/AddScheduleCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
using KDVManager.Services.Scheduling.Domain.Entities; | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.Schedules.Commands.AddSchedule; | ||
|
||
public class AddScheduleCommandHandler : IRequestHandler<AddScheduleCommand, Guid> | ||
{ | ||
private readonly IScheduleRepository _scheduleRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public AddScheduleCommandHandler(IScheduleRepository scheduleRepository, IMapper mapper) | ||
{ | ||
_scheduleRepository = scheduleRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<Guid> Handle(AddScheduleCommand request, CancellationToken cancellationToken) | ||
{ | ||
var validator = new AddScheduleCommandValidator(); | ||
var validationResult = await validator.ValidateAsync(request); | ||
|
||
if (!validationResult.IsValid) | ||
throw new Exceptions.ValidationException(validationResult); | ||
|
||
var schedule = _mapper.Map<Schedule>(request); | ||
|
||
schedule = await _scheduleRepository.AddAsync(schedule); | ||
|
||
return schedule.Id; | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
...duling/Application/Features/Schedules/Commands/AddSchedule/AddScheduleCommandValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentValidation; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.Schedules.Commands.AddSchedule; | ||
|
||
public class AddScheduleCommandValidator : AbstractValidator<AddScheduleCommand> | ||
{ | ||
public AddScheduleCommandValidator() | ||
{ | ||
|
||
RuleFor(AddScheduleCommand => AddScheduleCommand.ChildId) | ||
.NotEmpty() | ||
.NotNull(); | ||
|
||
RuleFor(AddScheduleCommand => AddScheduleCommand.StartDate) | ||
.NotEmpty() | ||
.NotNull(); | ||
|
||
RuleFor(AddScheduleCommand => AddScheduleCommand.EndDate) | ||
.GreaterThan(AddScheduleCommand => AddScheduleCommand.StartDate) | ||
.When(AddScheduleCommand => AddScheduleCommand.EndDate.HasValue); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...cheduling/Application/Features/Schedules/Queries/GetChildSchedules/ChildScheduleListVM.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.Schedules.Queries.GetChildSchedules; | ||
|
||
public class ChildScheduleListVM | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid ChildId { get; set; } | ||
public DateTime StartDate { get; set; } | ||
public DateTime? EndDate { get; set; } | ||
|
||
// Collection of nested schedules | ||
public ICollection<ScheduleRule> ScheduleRules { get; set; } = new List<ScheduleRule>(); | ||
|
||
public class ScheduleRule | ||
{ | ||
public DayOfWeek Day { get; set; } | ||
|
||
public Guid TimeSlotId { get; set; } | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...duling/Application/Features/Schedules/Queries/GetChildSchedules/GetChildSchedulesQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using KDVManager.Services.Scheduling.Domain; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Pagination; | ||
using MediatR; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.Schedules.Queries.GetChildSchedules; | ||
|
||
public class GetChildSchedulesQuery : IRequest<List<ChildScheduleListVM>> | ||
{ | ||
public Guid ChildId { get; set; } | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
...Application/Features/Schedules/Queries/GetChildSchedules/GetChildSchedulesQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Pagination; | ||
using KDVManager.Services.Scheduling.Domain.Entities; | ||
using MediatR; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.Schedules.Queries.GetChildSchedules; | ||
|
||
public class GetChildSchedulesQueryHandler : IRequestHandler<GetChildSchedulesQuery, List<ChildScheduleListVM>> | ||
{ | ||
private readonly IScheduleRepository _scheduleRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public GetChildSchedulesQueryHandler(IMapper mapper, IScheduleRepository scheduleRepository) | ||
{ | ||
_scheduleRepository = scheduleRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<List<ChildScheduleListVM>> Handle(GetChildSchedulesQuery request, CancellationToken cancellationToken) | ||
{ | ||
var scheduleItems = await _scheduleRepository.GetSchedulesByChildIdAsync(request.ChildId); | ||
|
||
List<ChildScheduleListVM> childScheduleListVMs = _mapper.Map<List<ChildScheduleListVM>>(scheduleItems); | ||
|
||
return new List<ChildScheduleListVM>(childScheduleListVMs); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using KDVManager.Services.Scheduling.Domain.Interfaces; | ||
|
||
namespace KDVManager.Services.Scheduling.Domain.Entities; | ||
|
||
public class Schedule : IMustHaveTenant | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid TenantId { get; set; } | ||
public Guid ChildId { get; set; } | ||
public Guid GroupId { get; set; } | ||
public DateTime StartDate { get; set; } | ||
public DateTime? EndDate { get; set; } | ||
public ICollection<ScheduleRule> ScheduleRules { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using KDVManager.Services.Scheduling.Domain.Interfaces; | ||
|
||
namespace KDVManager.Services.Scheduling.Domain.Entities; | ||
|
||
public class ScheduleRule : IMustHaveTenant | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid TenantId { get; set; } | ||
public DayOfWeek Day { get; set; } | ||
public Guid ScheduleId { get; set; } | ||
[Required] | ||
public Guid TimeSlotId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.