-
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 possibility to add scheduling items to children.
- Loading branch information
Showing
29 changed files
with
886 additions
and
24 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
40 changes: 40 additions & 0 deletions
40
src/Services/Scheduling/Api/Controllers/ScheduleItemsController.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,40 @@ | ||
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.ScheduleItems.Queries.ListScheduleItems; | ||
using System.Net; | ||
using KDVManager.Services.Scheduling.Application.Features.ScheduleItems.Commands.AddScheduleItem; | ||
|
||
namespace KDVManager.Services.Scheduling.Api.Controllers; | ||
|
||
[ApiController] | ||
[Route("v1/[controller]")] | ||
public class ScheduleItemsController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly ILogger<ScheduleItemsController> _logger; | ||
|
||
public ScheduleItemsController(IMediator mediator, ILogger<ScheduleItemsController> logger) | ||
{ | ||
_logger = logger; | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpGet("", Name = "ListScheduleItems")] | ||
public async Task<ActionResult<PagedList<ScheduleItemListVM>>> ListScheduleItems([FromQuery] ListScheduleItemsQuery listScheduleItemsQuery) | ||
{ | ||
var dtos = await _mediator.Send(listScheduleItemsQuery); | ||
Response.Headers.Add("x-Total", dtos.TotalCount.ToString()); | ||
return Ok(dtos); | ||
} | ||
|
||
[HttpPost(Name = "AddScheduleItem")] | ||
[ProducesResponseType(typeof(Guid), (int)HttpStatusCode.OK)] | ||
[ProducesResponseType(typeof(UnprocessableEntityResponse), (int)HttpStatusCode.UnprocessableEntity)] | ||
public async Task<ActionResult<Guid>> AddScheduleItem([FromBody] AddScheduleItemCommand addScheduleItemCommand) | ||
{ | ||
var id = await _mediator.Send(addScheduleItemCommand); | ||
return Ok(id); | ||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddleware.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
5 changes: 1 addition & 4 deletions
5
src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddlewareExtension.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
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
1 change: 0 additions & 1 deletion
1
src/Services/Scheduling/Api/Responses/UnprocessableEntityResponse.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
3 changes: 0 additions & 3 deletions
3
src/Services/Scheduling/Api/Services/TenantService/TenantService.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
13 changes: 13 additions & 0 deletions
13
src/Services/Scheduling/Application/Contracts/Persistence/IScheduleItemRepository.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 IScheduleItemRepository : IAsyncRepository<ScheduleItem> | ||
{ | ||
Task<IReadOnlyList<ScheduleItem>> GetScheduleItemsByChildIdAsync(Guid childId); | ||
} |
10 changes: 10 additions & 0 deletions
10
...ing/Application/Features/ScheduleItems/Commands/AddScheduleItem/AddScheduleItemCommand.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,10 @@ | ||
using System; | ||
using MediatR; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.ScheduleItems.Commands.AddScheduleItem; | ||
|
||
public class AddScheduleItemCommand : IRequest<Guid> | ||
{ | ||
public string Name { get; set; } | ||
public Guid ChildId { get; set; } | ||
} |
37 changes: 37 additions & 0 deletions
37
...lication/Features/ScheduleItems/Commands/AddScheduleItem/AddScheduleItemCommandHandler.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,37 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
using KDVManager.Services.Scheduling.Domain.Entities; | ||
using MediatR; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.ScheduleItems.Commands.AddScheduleItem; | ||
|
||
public class AddScheduleItemCommandHandler : IRequestHandler<AddScheduleItemCommand, Guid> | ||
{ | ||
private readonly IScheduleItemRepository _scheduleItemRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public AddScheduleItemCommandHandler(IScheduleItemRepository scheduleItemRepository, IMapper mapper) | ||
{ | ||
_scheduleItemRepository = scheduleItemRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<Guid> Handle(AddScheduleItemCommand request, CancellationToken cancellationToken) | ||
{ | ||
var validator = new AddScheduleItemCommandValidator(_scheduleItemRepository); | ||
var validationResult = await validator.ValidateAsync(request); | ||
|
||
if (!validationResult.IsValid) | ||
throw new Exceptions.ValidationException(validationResult); | ||
|
||
var scheduleItem = _mapper.Map<ScheduleItem>(request); | ||
|
||
scheduleItem = await _scheduleItemRepository.AddAsync(scheduleItem); | ||
|
||
return scheduleItem.Id; | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
...cation/Features/ScheduleItems/Commands/AddScheduleItem/AddScheduleItemCommandValidator.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,22 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentValidation; | ||
using KDVManager.Services.Scheduling.Application.Contracts.Persistence; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.ScheduleItems.Commands.AddScheduleItem; | ||
|
||
public class AddScheduleItemCommandValidator : AbstractValidator<AddScheduleItemCommand> | ||
{ | ||
private readonly IScheduleItemRepository _scheduleItemRepository; | ||
|
||
public AddScheduleItemCommandValidator(IScheduleItemRepository scheduleItemRepository) | ||
{ | ||
_scheduleItemRepository = scheduleItemRepository; | ||
|
||
RuleFor(AddScheduleItemCommand => AddScheduleItemCommand.Name) | ||
.NotEmpty() | ||
.NotNull() | ||
.MaximumLength(25); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ng/Application/Features/ScheduleItems/Queries/ListScheduleItems/ListScheduleItemsQuery.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.ScheduleItems.Queries.ListScheduleItems; | ||
|
||
public class ListScheduleItemsQuery : PageParameters, IRequest<PagedList<ScheduleItemListVM>> | ||
{ | ||
public Guid ChildId { get; set; } | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
...ication/Features/ScheduleItems/Queries/ListScheduleItems/ListScheduleItemsQueryHandler.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,34 @@ | ||
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.ScheduleItems.Queries.ListScheduleItems; | ||
|
||
public class ListScheduleItemsQueryHandler : IRequestHandler<ListScheduleItemsQuery, List<ScheduleItemListVM>> | ||
{ | ||
private readonly IScheduleItemRepository _scheduleItemRepository; | ||
private readonly IMapper _mapper; | ||
|
||
public ListScheduleItemsQueryHandler(IMapper mapper, IScheduleItemRepository scheduleItemRepository) | ||
{ | ||
_scheduleItemRepository = scheduleItemRepository; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<List<ScheduleItemListVM>> Handle(ListScheduleItemsQuery request, CancellationToken cancellationToken) | ||
{ | ||
var scheduleItems = await _scheduleItemRepository.GetScheduleItemsByChildIdAsync(request.ChildId); | ||
|
||
|
||
List<ScheduleItemListVM> scheduleItemListVMs = _mapper.Map<List<ScheduleItemListVM>>(scheduleItems); | ||
|
||
return new List<ScheduleItemListVM>(scheduleItemListVMs); | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
...duling/Application/Features/ScheduleItems/Queries/ListScheduleItems/ScheduleItemListVM.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; | ||
|
||
namespace KDVManager.Services.Scheduling.Application.Features.ScheduleItems.Queries.ListScheduleItems; | ||
|
||
public class ScheduleItemListVM | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid ChildId { get; set; } | ||
public string Title { get; set; } | ||
public DateTime StartDate { get; set; } | ||
public DateTime? EndDate { 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
11 changes: 11 additions & 0 deletions
11
src/Services/Scheduling/Domain/Entities/RecurringSchedulePattern.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,11 @@ | ||
using System; | ||
public class RecurringSchedulePattern | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid TenantId { get; set; } | ||
public Guid ScheduleItemId { get; set; } | ||
public DayOfWeek StartDay { get; set; } | ||
public TimeSpan StartTime { get; set; } | ||
public DayOfWeek EndDay { get; set; } | ||
public TimeSpan EndTime { 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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
public class ScheduleItem | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid TenantId { get; set; } | ||
public Guid ChildId { get; set; } | ||
public string Title { get; set; } | ||
public DateTime StartDate { get; set; } | ||
public DateTime? EndDate { get; set; } | ||
public ICollection<RecurringSchedulePattern> recurringSchedulePatterns { 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.