From 5ac64c7d154f08c6f65a04b1b15bea264266bcc4 Mon Sep 17 00:00:00 2001 From: LuukvH Date: Sat, 20 Jul 2024 23:35:49 +0200 Subject: [PATCH] feat: Add timeslot api Add api for adding and listing time slots --- .../Middleware/ExceptionHandlerMiddleware.cs | 6 +- .../ExceptionHandlerMiddlewareExtension.cs | 5 +- .../Responses/UnprocessableEntityResponse.cs | 1 - .../Services/TenantService/TenantService.cs | 3 - .../CRM/Application/ConfigureServices.cs | 4 +- .../Contracts/Pagination/PageParameters.cs | 1 - .../Contracts/Persistence/IChildRepository.cs | 3 +- .../Persistence/IPersonRepository.cs | 3 +- .../Contracts/Validation/ValidationError.cs | 3 +- .../CreateChildCommandValidator.cs | 6 +- .../DeleteChild/DeleteChildCommandHandler.cs | 3 +- .../UpdateChild/UpdateChildCommandHandler.cs | 4 +- .../UpdateChildCommandValidator.cs | 6 +- .../GetChildDetailQueryHandler.cs | 3 +- .../Queries/GetChildList/GetChildListQuery.cs | 5 +- .../GetChildList/GetChildListQueryHandler.cs | 4 +- .../AddPerson/AddPersonCommandValidator.cs | 3 +- .../GetPersonList/GetPersonListQuery.cs | 5 +- .../GetPersonListQueryHandler.cs | 4 +- .../Application/Profiles/MappingProfile.cs | 3 +- .../ChildManagementDbContext.cs | 3 +- .../Configurations/ChildConfiguration.cs | 3 +- .../CRM/Infrastructure/ConfigureServices.cs | 4 +- .../CRM/Infrastructure/MigrationDbContext.cs | 3 +- .../Repositories/PersonRepository.cs | 3 +- .../Api/Controllers/GroupsController.cs | 10 +-- .../Api/Controllers/TimeSlotsController.cs | 39 ++++++++++ .../Middleware/ExceptionHandlerMiddleware.cs | 6 +- .../ExceptionHandlerMiddlewareExtension.cs | 5 +- src/Services/Scheduling/Api/Program.cs | 2 - .../Responses/UnprocessableEntityResponse.cs | 1 - .../Services/TenantService/TenantService.cs | 3 - .../Application/ConfigureServices.cs | 4 +- .../Contracts/Pagination/PageParameters.cs | 1 - .../Contracts/Persistence/IGroupRepository.cs | 4 +- .../Persistence/ITimeSlotRepository.cs | 16 +++++ .../Contracts/Validation/ValidationError.cs | 3 +- .../AddGroup/AddGroupCommandValidator.cs | 3 +- .../DeleteGroup/DeleteGroupCommandHandler.cs | 3 +- .../Queries/ListGroups/ListGroupsQuery.cs | 5 +- .../ListGroups/ListGroupsQueryHandler.cs | 4 +- .../AddTimeSlot/AddTimeSlotCommand.cs | 13 ++++ .../AddTimeSlot/AddTimeSlotCommandHandler.cs | 37 ++++++++++ .../AddTimeSlotCommandValidator.cs | 31 ++++++++ .../ListTimeSlots/ListTimeSlotsQuery.cs | 9 +++ .../ListTimeSlotsQueryHandler.cs | 32 +++++++++ .../Queries/ListTimeSlots/TimeSlotListVM.cs | 11 +++ .../Application/Profiles/MappingProfile.cs | 9 ++- .../Scheduling/Domain/Entities/TimeSlot.cs | 17 +++++ .../Configurations/GroupConfiguration.cs | 3 +- .../Infrastructure/ConfigureServices.cs | 4 +- .../Infrastructure/MigrationDbContext.cs | 5 +- .../20240720210110_TimeSlots.Designer.cs | 71 +++++++++++++++++++ .../Migrations/20240720210110_TimeSlots.cs | 37 ++++++++++ .../MigrationDbContextModelSnapshot.cs | 23 ++++++ .../Repositories/GroupRepository.cs | 3 +- .../Repositories/TimeSlotRepository.cs | 37 ++++++++++ .../Infrastructure/SchedulingDbContext.cs | 5 +- 58 files changed, 421 insertions(+), 126 deletions(-) create mode 100644 src/Services/Scheduling/Api/Controllers/TimeSlotsController.cs create mode 100644 src/Services/Scheduling/Application/Contracts/Persistence/ITimeSlotRepository.cs create mode 100644 src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommand.cs create mode 100644 src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandHandler.cs create mode 100644 src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs create mode 100644 src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQuery.cs create mode 100644 src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQueryHandler.cs create mode 100644 src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/TimeSlotListVM.cs create mode 100644 src/Services/Scheduling/Domain/Entities/TimeSlot.cs create mode 100644 src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.Designer.cs create mode 100644 src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.cs create mode 100644 src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs diff --git a/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddleware.cs b/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddleware.cs index 92ace6c0..758c2719 100644 --- a/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddleware.cs +++ b/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddleware.cs @@ -1,10 +1,6 @@ -using System; -using System.Net; -using System.Threading.Tasks; +using System.Net; using KDVManager.Services.CRM.Application.Exceptions; using System.Text.Json; -using System.Text.Json.Serialization; -using Microsoft.AspNetCore.Http; namespace KDVManager.Services.CRM.Api.Middleware; diff --git a/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs b/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs index 268fe013..6cf78a62 100644 --- a/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs +++ b/src/Services/CRM/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs @@ -1,7 +1,4 @@ -using System; -using Microsoft.AspNetCore.Builder; - -namespace KDVManager.Services.CRM.Api.Middleware +namespace KDVManager.Services.CRM.Api.Middleware { public static class ExceptionHandlerMiddlewareExtension { diff --git a/src/Services/CRM/Api/Responses/UnprocessableEntityResponse.cs b/src/Services/CRM/Api/Responses/UnprocessableEntityResponse.cs index 6010153e..1a542e6b 100644 --- a/src/Services/CRM/Api/Responses/UnprocessableEntityResponse.cs +++ b/src/Services/CRM/Api/Responses/UnprocessableEntityResponse.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using KDVManager.Services.CRM.Application.Exceptions; using ValidationException = KDVManager.Services.CRM.Application.Exceptions.ValidationException; public class ValidationError diff --git a/src/Services/CRM/Api/Services/TenantService/TenantService.cs b/src/Services/CRM/Api/Services/TenantService/TenantService.cs index b59a34d8..3dff8998 100644 --- a/src/Services/CRM/Api/Services/TenantService/TenantService.cs +++ b/src/Services/CRM/Api/Services/TenantService/TenantService.cs @@ -1,7 +1,4 @@ -using System; using KDVManager.Services.CRM.Application.Contracts.Services; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Primitives; using KDVManager.Services.CRM.Application.Exceptions; namespace KDVManager.Services.CRM.Api.Services; diff --git a/src/Services/CRM/Application/ConfigureServices.cs b/src/Services/CRM/Application/ConfigureServices.cs index c53755ef..d8c82be1 100644 --- a/src/Services/CRM/Application/ConfigureServices.cs +++ b/src/Services/CRM/Application/ConfigureServices.cs @@ -1,7 +1,5 @@ -using System; -using System.Reflection; +using System.Reflection; using MediatR; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/Services/CRM/Application/Contracts/Pagination/PageParameters.cs b/src/Services/CRM/Application/Contracts/Pagination/PageParameters.cs index f6bbf90d..7fa8eda8 100644 --- a/src/Services/CRM/Application/Contracts/Pagination/PageParameters.cs +++ b/src/Services/CRM/Application/Contracts/Pagination/PageParameters.cs @@ -1,5 +1,4 @@ using KDVManager.Services.CRM.Domain.Interfaces; -using MediatR; namespace KDVManager.Services.CRM.Application.Contracts.Pagination { diff --git a/src/Services/CRM/Application/Contracts/Persistence/IChildRepository.cs b/src/Services/CRM/Application/Contracts/Persistence/IChildRepository.cs index be0240b2..397b35a9 100644 --- a/src/Services/CRM/Application/Contracts/Persistence/IChildRepository.cs +++ b/src/Services/CRM/Application/Contracts/Persistence/IChildRepository.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using KDVManager.Services.CRM.Domain.Entities; using KDVManager.Services.CRM.Domain.Interfaces; diff --git a/src/Services/CRM/Application/Contracts/Persistence/IPersonRepository.cs b/src/Services/CRM/Application/Contracts/Persistence/IPersonRepository.cs index a137b6d6..db8be338 100644 --- a/src/Services/CRM/Application/Contracts/Persistence/IPersonRepository.cs +++ b/src/Services/CRM/Application/Contracts/Persistence/IPersonRepository.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using KDVManager.Services.CRM.Domain.Entities; using KDVManager.Services.CRM.Domain.Interfaces; diff --git a/src/Services/CRM/Application/Contracts/Validation/ValidationError.cs b/src/Services/CRM/Application/Contracts/Validation/ValidationError.cs index 1ec1e97f..1742f3bf 100644 --- a/src/Services/CRM/Application/Contracts/Validation/ValidationError.cs +++ b/src/Services/CRM/Application/Contracts/Validation/ValidationError.cs @@ -1,5 +1,4 @@ -using System; -namespace KDVManager.Services.CRM.Application.Contracts.Validation +namespace KDVManager.Services.CRM.Application.Contracts.Validation { public class ValidationError { diff --git a/src/Services/CRM/Application/Features/Children/Commands/CreateChild/CreateChildCommandValidator.cs b/src/Services/CRM/Application/Features/Children/Commands/CreateChild/CreateChildCommandValidator.cs index 4ab6ec7e..432079bf 100644 --- a/src/Services/CRM/Application/Features/Children/Commands/CreateChild/CreateChildCommandValidator.cs +++ b/src/Services/CRM/Application/Features/Children/Commands/CreateChild/CreateChildCommandValidator.cs @@ -1,8 +1,4 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using FluentValidation; -using KDVManager.Services.CRM.Application.Contracts.Persistence; +using FluentValidation; namespace KDVManager.Services.CRM.Application.Features.Children.Commands.CreateChild; diff --git a/src/Services/CRM/Application/Features/Children/Commands/DeleteChild/DeleteChildCommandHandler.cs b/src/Services/CRM/Application/Features/Children/Commands/DeleteChild/DeleteChildCommandHandler.cs index b22fd1d1..6a7c857c 100644 --- a/src/Services/CRM/Application/Features/Children/Commands/DeleteChild/DeleteChildCommandHandler.cs +++ b/src/Services/CRM/Application/Features/Children/Commands/DeleteChild/DeleteChildCommandHandler.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using AutoMapper; using KDVManager.Services.CRM.Application.Contracts.Persistence; diff --git a/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandHandler.cs b/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandHandler.cs index 189cc57a..9e58109f 100644 --- a/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandHandler.cs +++ b/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandHandler.cs @@ -1,9 +1,7 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using AutoMapper; using KDVManager.Services.CRM.Application.Contracts.Persistence; -using KDVManager.Services.CRM.Application.Features.Children.Commands.CreateChild; using KDVManager.Services.CRM.Domain.Entities; using MediatR; diff --git a/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandValidator.cs b/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandValidator.cs index fe0df7d0..9650f1c0 100644 --- a/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandValidator.cs +++ b/src/Services/CRM/Application/Features/Children/Commands/UpdateChild/UpdateChildCommandValidator.cs @@ -1,8 +1,4 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using FluentValidation; -using KDVManager.Services.CRM.Application.Contracts.Persistence; +using FluentValidation; namespace KDVManager.Services.CRM.Application.Features.Children.Commands.UpdateChild; diff --git a/src/Services/CRM/Application/Features/Children/Queries/GetChildDetail/GetChildDetailQueryHandler.cs b/src/Services/CRM/Application/Features/Children/Queries/GetChildDetail/GetChildDetailQueryHandler.cs index 074fc780..bfe306a8 100644 --- a/src/Services/CRM/Application/Features/Children/Queries/GetChildDetail/GetChildDetailQueryHandler.cs +++ b/src/Services/CRM/Application/Features/Children/Queries/GetChildDetail/GetChildDetailQueryHandler.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using AutoMapper; using KDVManager.Services.CRM.Application.Contracts.Persistence; diff --git a/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQuery.cs b/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQuery.cs index 0403183e..5e163af9 100644 --- a/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQuery.cs +++ b/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQuery.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using KDVManager.Services.CRM.Domain; -using KDVManager.Services.CRM.Application.Contracts.Pagination; +using KDVManager.Services.CRM.Application.Contracts.Pagination; using MediatR; namespace KDVManager.Services.CRM.Application.Features.Children.Queries.GetChildList diff --git a/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQueryHandler.cs b/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQueryHandler.cs index 233f6214..18bac5ff 100644 --- a/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQueryHandler.cs +++ b/src/Services/CRM/Application/Features/Children/Queries/GetChildList/GetChildListQueryHandler.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AutoMapper; using KDVManager.Services.CRM.Application.Contracts.Persistence; using KDVManager.Services.CRM.Application.Contracts.Pagination; -using KDVManager.Services.CRM.Domain.Entities; using MediatR; namespace KDVManager.Services.CRM.Application.Features.Children.Queries.GetChildList; diff --git a/src/Services/CRM/Application/Features/People/Commands/AddPerson/AddPersonCommandValidator.cs b/src/Services/CRM/Application/Features/People/Commands/AddPerson/AddPersonCommandValidator.cs index 3a4172f0..a46a16cd 100644 --- a/src/Services/CRM/Application/Features/People/Commands/AddPerson/AddPersonCommandValidator.cs +++ b/src/Services/CRM/Application/Features/People/Commands/AddPerson/AddPersonCommandValidator.cs @@ -1,5 +1,4 @@ -using System; -using FluentValidation; +using FluentValidation; namespace KDVManager.Services.CRM.Application.Features.People.Commands.AddPerson; diff --git a/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQuery.cs b/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQuery.cs index 79393356..54ae3eb0 100644 --- a/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQuery.cs +++ b/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQuery.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using KDVManager.Services.CRM.Domain; -using KDVManager.Services.CRM.Application.Contracts.Pagination; +using KDVManager.Services.CRM.Application.Contracts.Pagination; using MediatR; namespace KDVManager.Services.CRM.Application.Features.People.Queries.GetPersonList; diff --git a/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQueryHandler.cs b/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQueryHandler.cs index 3367091b..fc877394 100644 --- a/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQueryHandler.cs +++ b/src/Services/CRM/Application/Features/People/Queries/GetPersonList/GetPersonListQueryHandler.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using AutoMapper; using KDVManager.Services.CRM.Application.Contracts.Persistence; using KDVManager.Services.CRM.Application.Contracts.Pagination; -using KDVManager.Services.CRM.Domain.Entities; using MediatR; namespace KDVManager.Services.CRM.Application.Features.People.Queries.GetPersonList; diff --git a/src/Services/CRM/Application/Profiles/MappingProfile.cs b/src/Services/CRM/Application/Profiles/MappingProfile.cs index d0ac01ca..c2086896 100644 --- a/src/Services/CRM/Application/Profiles/MappingProfile.cs +++ b/src/Services/CRM/Application/Profiles/MappingProfile.cs @@ -1,5 +1,4 @@ -using System; -using AutoMapper; +using AutoMapper; using KDVManager.Services.CRM.Application.Contracts.Pagination; using KDVManager.Services.CRM.Application.Features.Children.Commands.CreateChild; using KDVManager.Services.CRM.Application.Features.Children.Commands.UpdateChild; diff --git a/src/Services/CRM/Infrastructure/ChildManagementDbContext.cs b/src/Services/CRM/Infrastructure/ChildManagementDbContext.cs index 42498bb2..51a6f6ef 100644 --- a/src/Services/CRM/Infrastructure/ChildManagementDbContext.cs +++ b/src/Services/CRM/Infrastructure/ChildManagementDbContext.cs @@ -1,5 +1,4 @@ -using System; -using KDVManager.Services.CRM.Domain.Entities; +using KDVManager.Services.CRM.Domain.Entities; using KDVManager.Services.CRM.Application.Contracts.Services; using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; diff --git a/src/Services/CRM/Infrastructure/Configurations/ChildConfiguration.cs b/src/Services/CRM/Infrastructure/Configurations/ChildConfiguration.cs index eace52d7..2d9b12c4 100644 --- a/src/Services/CRM/Infrastructure/Configurations/ChildConfiguration.cs +++ b/src/Services/CRM/Infrastructure/Configurations/ChildConfiguration.cs @@ -1,5 +1,4 @@ -using System; -using KDVManager.Services.CRM.Domain.Entities; +using KDVManager.Services.CRM.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; diff --git a/src/Services/CRM/Infrastructure/ConfigureServices.cs b/src/Services/CRM/Infrastructure/ConfigureServices.cs index bb719b2e..ac8f6caa 100644 --- a/src/Services/CRM/Infrastructure/ConfigureServices.cs +++ b/src/Services/CRM/Infrastructure/ConfigureServices.cs @@ -1,10 +1,8 @@ -using System; -using KDVManager.Services.CRM.Application.Contracts.Persistence; +using KDVManager.Services.CRM.Application.Contracts.Persistence; using KDVManager.Services.CRM.Infrastructure; using KDVManager.Services.CRM.Infrastructure.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/Services/CRM/Infrastructure/MigrationDbContext.cs b/src/Services/CRM/Infrastructure/MigrationDbContext.cs index d1a1984a..a023410e 100644 --- a/src/Services/CRM/Infrastructure/MigrationDbContext.cs +++ b/src/Services/CRM/Infrastructure/MigrationDbContext.cs @@ -1,5 +1,4 @@ -using System; -using KDVManager.Services.CRM.Domain.Entities; +using KDVManager.Services.CRM.Domain.Entities; using Microsoft.EntityFrameworkCore; namespace KDVManager.Services.CRM.Infrastructure diff --git a/src/Services/CRM/Infrastructure/Repositories/PersonRepository.cs b/src/Services/CRM/Infrastructure/Repositories/PersonRepository.cs index 6a5a9ee1..aac4276d 100644 --- a/src/Services/CRM/Infrastructure/Repositories/PersonRepository.cs +++ b/src/Services/CRM/Infrastructure/Repositories/PersonRepository.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Collections.Generic; using System.Threading.Tasks; using KDVManager.Services.CRM.Application.Contracts.Persistence; diff --git a/src/Services/Scheduling/Api/Controllers/GroupsController.cs b/src/Services/Scheduling/Api/Controllers/GroupsController.cs index 440e8c66..19ca2422 100644 --- a/src/Services/Scheduling/Api/Controllers/GroupsController.cs +++ b/src/Services/Scheduling/Api/Controllers/GroupsController.cs @@ -1,17 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using KDVManager.Services.Scheduling.Application.Features.Groups.Commands.AddGroup; +using KDVManager.Services.Scheduling.Application.Features.Groups.Commands.AddGroup; using KDVManager.Services.Scheduling.Application.Features.Groups.Queries.ListGroups; using MediatR; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Microsoft.AspNetCore.Authorization; using KDVManager.Services.Scheduling.Application.Contracts.Pagination; using System.Net; -using KDVManager.Services.Scheduling.Application.Contracts.Persistence; -using System.Net.Mime; using KDVManager.Services.Scheduling.Application.Features.Groups.Commands.DeleteGroup; namespace KDVManager.Services.Scheduling.Api.Controllers; diff --git a/src/Services/Scheduling/Api/Controllers/TimeSlotsController.cs b/src/Services/Scheduling/Api/Controllers/TimeSlotsController.cs new file mode 100644 index 00000000..8f9db7e8 --- /dev/null +++ b/src/Services/Scheduling/Api/Controllers/TimeSlotsController.cs @@ -0,0 +1,39 @@ +using KDVManager.Services.Scheduling.Application.Features.TimeSlots.Commands.AddTimeSlot; +using KDVManager.Services.Scheduling.Application.Features.TimeSlots.Queries.ListTimeSlots; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using KDVManager.Services.Scheduling.Application.Contracts.Pagination; +using System.Net; + +namespace KDVManager.Services.Scheduling.Api.Controllers; + +[ApiController] +[Route("v1/[controller]")] +public class TimeSlotsController : ControllerBase +{ + private readonly IMediator _mediator; + private readonly ILogger _logger; + + public TimeSlotsController(IMediator mediator, ILogger logger) + { + _logger = logger; + _mediator = mediator; + } + + [HttpGet("", Name = "ListTimeSlots")] + public async Task>> ListTimeSlots([FromQuery] ListTimeSlotsQuery listTimeSlotsQuery) + { + var dtos = await _mediator.Send(listTimeSlotsQuery); + Response.Headers.Add("x-Total", dtos.TotalCount.ToString()); + return Ok(dtos); + } + + [HttpPost(Name = "AddTimeSlot")] + [ProducesResponseType(typeof(Guid), (int)HttpStatusCode.OK)] + [ProducesResponseType(typeof(UnprocessableEntityResponse), (int)HttpStatusCode.UnprocessableEntity)] + public async Task> AddTimeSlot([FromBody] AddTimeSlotCommand addTimeSlotCommand) + { + var id = await _mediator.Send(addTimeSlotCommand); + return Ok(id); + } +} diff --git a/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddleware.cs b/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddleware.cs index d4a12218..fc96bcb1 100644 --- a/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddleware.cs +++ b/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddleware.cs @@ -1,10 +1,6 @@ -using System; -using System.Net; -using System.Threading.Tasks; +using System.Net; using KDVManager.Services.Scheduling.Application.Exceptions; using System.Text.Json; -using System.Text.Json.Serialization; -using Microsoft.AspNetCore.Http; namespace KDVManager.Services.Scheduling.Api.Middleware; diff --git a/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs b/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs index c0a3ec32..5f372dd1 100644 --- a/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs +++ b/src/Services/Scheduling/Api/Middleware/ExceptionHandlerMiddlewareExtension.cs @@ -1,7 +1,4 @@ -using System; -using Microsoft.AspNetCore.Builder; - -namespace KDVManager.Services.Scheduling.Api.Middleware; +namespace KDVManager.Services.Scheduling.Api.Middleware; public static class ExceptionHandlerMiddlewareExtension { diff --git a/src/Services/Scheduling/Api/Program.cs b/src/Services/Scheduling/Api/Program.cs index 15d969f8..f8ec5240 100644 --- a/src/Services/Scheduling/Api/Program.cs +++ b/src/Services/Scheduling/Api/Program.cs @@ -1,6 +1,4 @@ using KDVManager.Services.Scheduling.Api.Middleware; -using KDVManager.Services.Scheduling.Application; -using KDVManager.Services.Scheduling.Infrastructure; var builder = WebApplication.CreateBuilder(args); diff --git a/src/Services/Scheduling/Api/Responses/UnprocessableEntityResponse.cs b/src/Services/Scheduling/Api/Responses/UnprocessableEntityResponse.cs index fdd90ce4..3c3edf82 100644 --- a/src/Services/Scheduling/Api/Responses/UnprocessableEntityResponse.cs +++ b/src/Services/Scheduling/Api/Responses/UnprocessableEntityResponse.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using KDVManager.Services.Scheduling.Application.Exceptions; using ValidationException = KDVManager.Services.Scheduling.Application.Exceptions.ValidationException; public class ValidationError diff --git a/src/Services/Scheduling/Api/Services/TenantService/TenantService.cs b/src/Services/Scheduling/Api/Services/TenantService/TenantService.cs index 699d94fc..8c2d25fc 100644 --- a/src/Services/Scheduling/Api/Services/TenantService/TenantService.cs +++ b/src/Services/Scheduling/Api/Services/TenantService/TenantService.cs @@ -1,7 +1,4 @@ -using System; using KDVManager.Services.Scheduling.Application.Contracts.Services; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Primitives; using KDVManager.Services.Scheduling.Application.Exceptions; namespace KDVManager.Services.Scheduling.Api.Services; diff --git a/src/Services/Scheduling/Application/ConfigureServices.cs b/src/Services/Scheduling/Application/ConfigureServices.cs index c53755ef..d8c82be1 100644 --- a/src/Services/Scheduling/Application/ConfigureServices.cs +++ b/src/Services/Scheduling/Application/ConfigureServices.cs @@ -1,7 +1,5 @@ -using System; -using System.Reflection; +using System.Reflection; using MediatR; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/Services/Scheduling/Application/Contracts/Pagination/PageParameters.cs b/src/Services/Scheduling/Application/Contracts/Pagination/PageParameters.cs index 8e280a2b..cb248600 100644 --- a/src/Services/Scheduling/Application/Contracts/Pagination/PageParameters.cs +++ b/src/Services/Scheduling/Application/Contracts/Pagination/PageParameters.cs @@ -1,5 +1,4 @@ using KDVManager.Services.Scheduling.Domain.Interfaces; -using MediatR; namespace KDVManager.Services.Scheduling.Application.Contracts.Pagination; diff --git a/src/Services/Scheduling/Application/Contracts/Persistence/IGroupRepository.cs b/src/Services/Scheduling/Application/Contracts/Persistence/IGroupRepository.cs index c773fab4..d1e26194 100644 --- a/src/Services/Scheduling/Application/Contracts/Persistence/IGroupRepository.cs +++ b/src/Services/Scheduling/Application/Contracts/Persistence/IGroupRepository.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +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; diff --git a/src/Services/Scheduling/Application/Contracts/Persistence/ITimeSlotRepository.cs b/src/Services/Scheduling/Application/Contracts/Persistence/ITimeSlotRepository.cs new file mode 100644 index 00000000..c6f7283a --- /dev/null +++ b/src/Services/Scheduling/Application/Contracts/Persistence/ITimeSlotRepository.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using KDVManager.Services.Scheduling.Domain.Entities; +using KDVManager.Services.Scheduling.Domain.Interfaces; + +namespace KDVManager.Services.Scheduling.Application.Contracts.Persistence; + +public interface ITimeSlotRepository : IAsyncRepository +{ + Task> PagedAsync(IPaginationFilter paginationFilter); + + Task CountAsync(); + + Task IsTimeSlotNameUnique(string name); +} + diff --git a/src/Services/Scheduling/Application/Contracts/Validation/ValidationError.cs b/src/Services/Scheduling/Application/Contracts/Validation/ValidationError.cs index 1470d2bf..d8f676ea 100644 --- a/src/Services/Scheduling/Application/Contracts/Validation/ValidationError.cs +++ b/src/Services/Scheduling/Application/Contracts/Validation/ValidationError.cs @@ -1,5 +1,4 @@ -using System; -namespace KDVManager.Services.Scheduling.Application.Contracts.Validation; +namespace KDVManager.Services.Scheduling.Application.Contracts.Validation; public class ValidationError { diff --git a/src/Services/Scheduling/Application/Features/Groups/Commands/AddGroup/AddGroupCommandValidator.cs b/src/Services/Scheduling/Application/Features/Groups/Commands/AddGroup/AddGroupCommandValidator.cs index 0c152bd2..0e8bfd0f 100644 --- a/src/Services/Scheduling/Application/Features/Groups/Commands/AddGroup/AddGroupCommandValidator.cs +++ b/src/Services/Scheduling/Application/Features/Groups/Commands/AddGroup/AddGroupCommandValidator.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using FluentValidation; using KDVManager.Services.Scheduling.Application.Contracts.Persistence; diff --git a/src/Services/Scheduling/Application/Features/Groups/Commands/DeleteGroup/DeleteGroupCommandHandler.cs b/src/Services/Scheduling/Application/Features/Groups/Commands/DeleteGroup/DeleteGroupCommandHandler.cs index 0b62e3f8..d6ff0a18 100644 --- a/src/Services/Scheduling/Application/Features/Groups/Commands/DeleteGroup/DeleteGroupCommandHandler.cs +++ b/src/Services/Scheduling/Application/Features/Groups/Commands/DeleteGroup/DeleteGroupCommandHandler.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using AutoMapper; using KDVManager.Services.Scheduling.Application.Contracts.Persistence; diff --git a/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQuery.cs b/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQuery.cs index 8e332f60..442f662d 100644 --- a/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQuery.cs +++ b/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQuery.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using KDVManager.Services.Scheduling.Domain; -using KDVManager.Services.Scheduling.Application.Contracts.Pagination; +using KDVManager.Services.Scheduling.Application.Contracts.Pagination; using MediatR; namespace KDVManager.Services.Scheduling.Application.Features.Groups.Queries.ListGroups; diff --git a/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQueryHandler.cs b/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQueryHandler.cs index db61d729..51756a4d 100644 --- a/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQueryHandler.cs +++ b/src/Services/Scheduling/Application/Features/Groups/Queries/ListGroups/ListGroupsQueryHandler.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; +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.Groups.Queries.ListGroups; diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommand.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommand.cs new file mode 100644 index 00000000..7db2e152 --- /dev/null +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommand.cs @@ -0,0 +1,13 @@ +using System; +using MediatR; + +namespace KDVManager.Services.Scheduling.Application.Features.TimeSlots.Commands.AddTimeSlot; + +public class AddTimeSlotCommand : IRequest +{ + public string Name { get; set; } + + public TimeSpan StartTime { get; set; } + + public TimeSpan EndTime { get; set; } +} diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandHandler.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandHandler.cs new file mode 100644 index 00000000..fcd92cdc --- /dev/null +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandHandler.cs @@ -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.TimeSlots.Commands.AddTimeSlot; + +public class AddTimeSlotCommandHandler : IRequestHandler +{ + private readonly ITimeSlotRepository _timeSlotRepository; + private readonly IMapper _mapper; + + public AddTimeSlotCommandHandler(ITimeSlotRepository timeSlotRepository, IMapper mapper) + { + _timeSlotRepository = timeSlotRepository; + _mapper = mapper; + } + + public async Task Handle(AddTimeSlotCommand request, CancellationToken cancellationToken) + { + var validator = new AddTimeSlotCommandValidator(_timeSlotRepository); + var validationResult = await validator.ValidateAsync(request); + + if (!validationResult.IsValid) + throw new Exceptions.ValidationException(validationResult); + + var timeSlot = _mapper.Map(request); + + timeSlot = await _timeSlotRepository.AddAsync(timeSlot); + + return timeSlot.Id; + } +} + diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs new file mode 100644 index 00000000..f4a2bec3 --- /dev/null +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Commands/AddTimeSlot/AddTimeSlotCommandValidator.cs @@ -0,0 +1,31 @@ +using System.Threading; +using System.Threading.Tasks; +using FluentValidation; +using KDVManager.Services.Scheduling.Application.Contracts.Persistence; + +namespace KDVManager.Services.Scheduling.Application.Features.TimeSlots.Commands.AddTimeSlot; + +public class AddTimeSlotCommandValidator : AbstractValidator +{ + private readonly ITimeSlotRepository _timeSlotRepository; + + public AddTimeSlotCommandValidator(ITimeSlotRepository timeSlotRepository) + { + _timeSlotRepository = timeSlotRepository; + + RuleFor(addTimeSlotCommand => addTimeSlotCommand.Name) + .NotEmpty() + .NotNull() + .MaximumLength(25); + + RuleFor(addTimeSlotCommand => addTimeSlotCommand.Name) + .MustAsync(TimeSlotNameUnique) + .WithErrorCode("TSNU001") + .WithMessage("An group with the same name already exists."); + } + + private async Task TimeSlotNameUnique(string name, CancellationToken token) + { + return !(await _timeSlotRepository.IsTimeSlotNameUnique(name)); + } +} diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQuery.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQuery.cs new file mode 100644 index 00000000..edb1518a --- /dev/null +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQuery.cs @@ -0,0 +1,9 @@ +using KDVManager.Services.Scheduling.Application.Contracts.Pagination; +using MediatR; + +namespace KDVManager.Services.Scheduling.Application.Features.TimeSlots.Queries.ListTimeSlots; + +public class ListTimeSlotsQuery : PageParameters, IRequest> +{ +} + diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQueryHandler.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQueryHandler.cs new file mode 100644 index 00000000..d439e900 --- /dev/null +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/ListTimeSlotsQueryHandler.cs @@ -0,0 +1,32 @@ +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 MediatR; + +namespace KDVManager.Services.Scheduling.Application.Features.TimeSlots.Queries.ListTimeSlots; + +public class ListTimeSlotsQueryHandler : IRequestHandler> +{ + private readonly ITimeSlotRepository _timeSlotRepository; + private readonly IMapper _mapper; + + public ListTimeSlotsQueryHandler(IMapper mapper, ITimeSlotRepository timeSlotRepository) + { + _timeSlotRepository = timeSlotRepository; + _mapper = mapper; + } + + public async Task> Handle(ListTimeSlotsQuery request, CancellationToken cancellationToken) + { + var groups = await _timeSlotRepository.PagedAsync(request); + var count = await _timeSlotRepository.CountAsync(); + + List timeSlotListVMs = _mapper.Map>(groups); + + return new PagedList(timeSlotListVMs, count); + } +} + diff --git a/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/TimeSlotListVM.cs b/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/TimeSlotListVM.cs new file mode 100644 index 00000000..434a03fb --- /dev/null +++ b/src/Services/Scheduling/Application/Features/TimeSlots/Queries/ListTimeSlots/TimeSlotListVM.cs @@ -0,0 +1,11 @@ +using System; + +namespace KDVManager.Services.Scheduling.Application.Features.TimeSlots.Queries.ListTimeSlots; + +public class TimeSlotListVM +{ + public Guid Id { get; set; } + public string Name { get; set; } + public TimeSpan StartTime { get; set; } + public TimeSpan EndTime { get; set; } +} diff --git a/src/Services/Scheduling/Application/Profiles/MappingProfile.cs b/src/Services/Scheduling/Application/Profiles/MappingProfile.cs index a09ecef8..4c70a424 100644 --- a/src/Services/Scheduling/Application/Profiles/MappingProfile.cs +++ b/src/Services/Scheduling/Application/Profiles/MappingProfile.cs @@ -1,8 +1,9 @@ -using System; -using AutoMapper; +using AutoMapper; using KDVManager.Services.Scheduling.Application.Contracts.Pagination; using KDVManager.Services.Scheduling.Application.Features.Groups.Commands.AddGroup; using KDVManager.Services.Scheduling.Application.Features.Groups.Queries.ListGroups; +using KDVManager.Services.Scheduling.Application.Features.TimeSlots.Commands.AddTimeSlot; +using KDVManager.Services.Scheduling.Application.Features.TimeSlots.Queries.ListTimeSlots; using KDVManager.Services.Scheduling.Domain.Entities; namespace KDVManager.Services.Scheduling.Application.Profiles; @@ -14,6 +15,10 @@ public MappingProfile() CreateMap(); CreateMap().ReverseMap(); CreateMap(); + + CreateMap(); + CreateMap().ReverseMap(); + CreateMap(); } } diff --git a/src/Services/Scheduling/Domain/Entities/TimeSlot.cs b/src/Services/Scheduling/Domain/Entities/TimeSlot.cs new file mode 100644 index 00000000..4a428361 --- /dev/null +++ b/src/Services/Scheduling/Domain/Entities/TimeSlot.cs @@ -0,0 +1,17 @@ +using System; +using KDVManager.Services.Scheduling.Domain.Interfaces; + +namespace KDVManager.Services.Scheduling.Domain.Entities; + +public class TimeSlot : IMustHaveTenant +{ + public Guid Id { get; set; } + + public Guid TenantId { get; set; } + + public string Name { get; set; } + + public TimeSpan StartTime { get; set; } + + public TimeSpan EndTime { get; set; } +} diff --git a/src/Services/Scheduling/Infrastructure/Configurations/GroupConfiguration.cs b/src/Services/Scheduling/Infrastructure/Configurations/GroupConfiguration.cs index af9fd201..cdf9bd9d 100644 --- a/src/Services/Scheduling/Infrastructure/Configurations/GroupConfiguration.cs +++ b/src/Services/Scheduling/Infrastructure/Configurations/GroupConfiguration.cs @@ -1,5 +1,4 @@ -using System; -using KDVManager.Services.Scheduling.Domain.Entities; +using KDVManager.Services.Scheduling.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; diff --git a/src/Services/Scheduling/Infrastructure/ConfigureServices.cs b/src/Services/Scheduling/Infrastructure/ConfigureServices.cs index 9be337af..a39767e7 100644 --- a/src/Services/Scheduling/Infrastructure/ConfigureServices.cs +++ b/src/Services/Scheduling/Infrastructure/ConfigureServices.cs @@ -1,10 +1,8 @@ -using System; -using KDVManager.Services.Scheduling.Application.Contracts.Persistence; +using KDVManager.Services.Scheduling.Application.Contracts.Persistence; using KDVManager.Services.Scheduling.Infrastructure; using KDVManager.Services.Scheduling.Infrastructure.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/Services/Scheduling/Infrastructure/MigrationDbContext.cs b/src/Services/Scheduling/Infrastructure/MigrationDbContext.cs index ec703281..36e816dd 100644 --- a/src/Services/Scheduling/Infrastructure/MigrationDbContext.cs +++ b/src/Services/Scheduling/Infrastructure/MigrationDbContext.cs @@ -1,5 +1,4 @@ -using System; -using KDVManager.Services.Scheduling.Domain.Entities; +using KDVManager.Services.Scheduling.Domain.Entities; using Microsoft.EntityFrameworkCore; using System.Reflection; @@ -13,6 +12,8 @@ public MigrationDbContext(DbContextOptions options) : base(o public DbSet Groups { get; set; } + public DbSet TimeSlots { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); diff --git a/src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.Designer.cs b/src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.Designer.cs new file mode 100644 index 00000000..7efcf0db --- /dev/null +++ b/src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.Designer.cs @@ -0,0 +1,71 @@ +// +using System; +using KDVManager.Services.Scheduling.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Infrastructure.Migrations +{ + [DbContext(typeof(MigrationDbContext))] + [Migration("20240720210110_TimeSlots")] + partial class TimeSlots + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("KDVManager.Services.Scheduling.Domain.Entities.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TenantId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("KDVManager.Services.Scheduling.Domain.Entities.TimeSlot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("EndTime") + .HasColumnType("interval"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("StartTime") + .HasColumnType("interval"); + + b.Property("TenantId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("TimeSlots"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.cs b/src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.cs new file mode 100644 index 00000000..fda7ba76 --- /dev/null +++ b/src/Services/Scheduling/Infrastructure/Migrations/20240720210110_TimeSlots.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Infrastructure.Migrations +{ + /// + public partial class TimeSlots : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "TimeSlots", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + TenantId = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: true), + StartTime = table.Column(type: "interval", nullable: false), + EndTime = table.Column(type: "interval", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TimeSlots", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "TimeSlots"); + } + } +} diff --git a/src/Services/Scheduling/Infrastructure/Migrations/MigrationDbContextModelSnapshot.cs b/src/Services/Scheduling/Infrastructure/Migrations/MigrationDbContextModelSnapshot.cs index ffae097c..5d2b7815 100644 --- a/src/Services/Scheduling/Infrastructure/Migrations/MigrationDbContextModelSnapshot.cs +++ b/src/Services/Scheduling/Infrastructure/Migrations/MigrationDbContextModelSnapshot.cs @@ -39,6 +39,29 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Groups"); }); + + modelBuilder.Entity("KDVManager.Services.Scheduling.Domain.Entities.TimeSlot", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("EndTime") + .HasColumnType("interval"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("StartTime") + .HasColumnType("interval"); + + b.Property("TenantId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("TimeSlots"); + }); #pragma warning restore 612, 618 } } diff --git a/src/Services/Scheduling/Infrastructure/Repositories/GroupRepository.cs b/src/Services/Scheduling/Infrastructure/Repositories/GroupRepository.cs index 766c7def..aec52ba8 100644 --- a/src/Services/Scheduling/Infrastructure/Repositories/GroupRepository.cs +++ b/src/Services/Scheduling/Infrastructure/Repositories/GroupRepository.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Collections.Generic; using System.Threading.Tasks; using KDVManager.Services.Scheduling.Application.Contracts.Persistence; diff --git a/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs b/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs new file mode 100644 index 00000000..77466644 --- /dev/null +++ b/src/Services/Scheduling/Infrastructure/Repositories/TimeSlotRepository.cs @@ -0,0 +1,37 @@ +using System.Linq; +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; +using Microsoft.EntityFrameworkCore; + +namespace KDVManager.Services.Scheduling.Infrastructure.Repositories; + +public class TimeSlotRepository : BaseRepository, ITimeSlotRepository +{ + public TimeSlotRepository(SchedulingDbContext dbContext) : base(dbContext) + { + } + + public async Task> PagedAsync(IPaginationFilter paginationFilter) + { + int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize; + + return await _dbContext.Set() + .OrderBy(timeSlot => timeSlot.Name) + .Skip((paginationFilter.PageNumber - 1) * paginationFilter.PageSize).Take(paginationFilter.PageSize) + .ToListAsync(); + } + + public async Task CountAsync() + { + return await _dbContext.Set().CountAsync(); + } + + public async Task IsTimeSlotNameUnique(string name) + { + var matches = _dbContext.TimeSlots.Any(e => e.Name.Equals(name)); + return await Task.FromResult(matches); + } +} diff --git a/src/Services/Scheduling/Infrastructure/SchedulingDbContext.cs b/src/Services/Scheduling/Infrastructure/SchedulingDbContext.cs index 32320c96..5216e2c6 100644 --- a/src/Services/Scheduling/Infrastructure/SchedulingDbContext.cs +++ b/src/Services/Scheduling/Infrastructure/SchedulingDbContext.cs @@ -1,5 +1,4 @@ -using System; -using KDVManager.Services.Scheduling.Domain.Entities; +using KDVManager.Services.Scheduling.Domain.Entities; using KDVManager.Services.Scheduling.Application.Contracts.Services; using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; @@ -18,11 +17,13 @@ public SchedulingDbContext(DbContextOptions options, ITenan } public DbSet Groups { get; set; } + public DbSet TimeSlots { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasQueryFilter(a => a.TenantId == _tenantService.Tenant); + modelBuilder.Entity().HasQueryFilter(a => a.TenantId == _tenantService.Tenant); modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); }