diff --git a/StudioManager.API/Controllers/V1/EquipmentTypesController.cs b/StudioManager.API/Controllers/V1/EquipmentTypesController.cs index 4a19cbb..21df73c 100644 --- a/StudioManager.API/Controllers/V1/EquipmentTypesController.cs +++ b/StudioManager.API/Controllers/V1/EquipmentTypesController.cs @@ -7,6 +7,7 @@ using StudioManager.Application.EquipmentTypes.Create; using StudioManager.Application.EquipmentTypes.Delete; using StudioManager.Application.EquipmentTypes.GetAll; +using StudioManager.Application.EquipmentTypes.GetById; using StudioManager.Application.EquipmentTypes.Update; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Filters; @@ -53,6 +54,14 @@ public async Task DeleteEquipmentTypeAsync(Guid id) var command = new DeleteEquipmentTypeCommand(id); return await SendAsync(command); } + + [HttpGet("{id:guid}")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + public async Task GetEquipmentTypeByIdAsync(Guid id) + { + var command = new GetEquipmentTypeByIdQuery(id); + return await SendAsync(command); + } private static EquipmentTypeFilter CreateFilter(string? ft) { diff --git a/StudioManager.API/Controllers/V1/EquipmentsController.cs b/StudioManager.API/Controllers/V1/EquipmentsController.cs index 6e8b2a1..9f34676 100644 --- a/StudioManager.API/Controllers/V1/EquipmentsController.cs +++ b/StudioManager.API/Controllers/V1/EquipmentsController.cs @@ -8,6 +8,7 @@ using StudioManager.Application.Equipments.Create; using StudioManager.Application.Equipments.Delete; using StudioManager.Application.Equipments.GetAll; +using StudioManager.Application.Equipments.GetById; using StudioManager.Application.Equipments.Update; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Filters; @@ -54,6 +55,13 @@ public async Task GetEquipments( var command = new GetAllEquipmentsQuery(filter, pagination); return await SendAsync(command); } + + [HttpGet("{id:guid}")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + public async Task GetEquipmentById(Guid id) + { + return await SendAsync(new GetEquipmentByIdQuery(id)); + } private static EquipmentFilter CreateFilter( string? search, diff --git a/StudioManager.API/Controllers/V1/ReservationsController.cs b/StudioManager.API/Controllers/V1/ReservationsController.cs index 5f5b9b8..b8ace57 100644 --- a/StudioManager.API/Controllers/V1/ReservationsController.cs +++ b/StudioManager.API/Controllers/V1/ReservationsController.cs @@ -8,6 +8,7 @@ using StudioManager.Application.Reservations.Create; using StudioManager.Application.Reservations.Delete; using StudioManager.Application.Reservations.GetAll; +using StudioManager.Application.Reservations.GetById; using StudioManager.Application.Reservations.Update; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Filters; @@ -57,4 +58,11 @@ public async Task GetAllReservations( return await SendAsync(new GetAllReservationsQuery(filter, pagination)); } + + [HttpGet("{id:guid}")] + [ProducesResponseType(typeof(QueryResult), StatusCodes.Status200OK)] + public async Task GetReservationById(Guid id) + { + return await SendAsync(new GetReservationByIdQuery(id)); + } } diff --git a/StudioManager.Application.Tests/EquipmentTypes/DeleteEquipmentTypeCommandHandlerTests/Handle.cs b/StudioManager.Application.Tests/EquipmentTypes/DeleteEquipmentTypeCommandHandlerTests/Handle.cs index a8b4aa3..4520fd0 100644 --- a/StudioManager.Application.Tests/EquipmentTypes/DeleteEquipmentTypeCommandHandlerTests/Handle.cs +++ b/StudioManager.Application.Tests/EquipmentTypes/DeleteEquipmentTypeCommandHandlerTests/Handle.cs @@ -24,7 +24,7 @@ public async Task SetUpAsync() } [Test] - public async Task should_return_not_found_when_updating_non_existing_entity_async() + public async Task should_return_not_found_when_removing_non_existing_entity_async() { // Arrange await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) diff --git a/StudioManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Handle.cs b/StudioManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Handle.cs new file mode 100644 index 0000000..ff192c7 --- /dev/null +++ b/StudioManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Handle.cs @@ -0,0 +1,74 @@ +using FluentAssertions; +using NUnit.Framework; +using StudioManager.API.Contracts.EquipmentTypes; +using StudioManager.Application.EquipmentTypes.GetById; +using StudioManager.Domain.Common.Results; +using StudioManager.Domain.Entities; +using StudioManager.Infrastructure; +using StudioManager.Tests.Common; +using StudioManager.Tests.Common.DbContextExtensions; + +namespace StudioManager.Application.Tests.EquipmentTypes.GetEquipmentTypeByIdQueryHandlerTests; + +public sealed class Handle : IntegrationTestBase +{ + private static GetEquipmentTypeByIdQueryHandler _testCandidate = null!; + private static TestDbContextFactory _testDbContextFactory = null!; + + [SetUp] + public async Task SetUpAsync() + { + var connectionString = await DbMigrator.MigrateDbAsync(); + _testDbContextFactory = new TestDbContextFactory(connectionString); + _testCandidate = new GetEquipmentTypeByIdQueryHandler(_testDbContextFactory, Mapper); + } + + [Test] + public async Task should_return_not_found_when_requesting_non_existing_entity_async() + { + // Arrange + await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) + { + await ClearTableContentsForAsync(dbContext); + } + + var id = Guid.NewGuid(); + + var command = new GetEquipmentTypeByIdQuery(id); + + // Act + var result = await _testCandidate.Handle(command, Cts.Token); + + result.Should().NotBeNull(); + result.Should().BeOfType>(); + result.Data.Should().BeNull(); + result.Succeeded.Should().BeFalse(); + result.StatusCode.Should().Be(NotFoundStatusCode); + result.Error.Should().NotBeNullOrWhiteSpace(); + result.Error.Should().Be($"[NOT FOUND] {nameof(EquipmentType)} with id '{id}' does not exist"); + } + + [Test] + public async Task should_return_success_async() + { + // Arrange + var equipmentType = EquipmentType.Create("Test-Equipment-Type"); + await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) + { + await AddEntitiesToTable(dbContext, equipmentType); + } + + var command = new GetEquipmentTypeByIdQuery(equipmentType.Id); + + // Act + var result = await _testCandidate.Handle(command, Cts.Token); + + result.Should().NotBeNull(); + result.Should().BeOfType>(); + result.Data.Should().NotBeNull(); + result.Data.Should().BeOfType(); + result.Succeeded.Should().BeTrue(); + result.StatusCode.Should().Be(OkStatusCode); + result.Error.Should().BeNullOrWhiteSpace(); + } +} diff --git a/StudioManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Validator.cs b/StudioManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Validator.cs new file mode 100644 index 0000000..cd22cc9 --- /dev/null +++ b/StudioManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Validator.cs @@ -0,0 +1,38 @@ +using FluentAssertions; +using NUnit.Framework; +using StudioManager.Application.EquipmentTypes.GetById; + +namespace StudioManager.Application.Tests.EquipmentTypes.GetEquipmentTypeByIdQueryHandlerTests; + +public sealed class Validator +{ + [Test] + public async Task should_return_error_when_id_is_empty_async() + { + // Arrange + var query = new GetEquipmentTypeByIdQuery(Guid.Empty); + var validator = new GetEquipmentTypeByIdQueryValidator(); + + // Act + var result = await validator.ValidateAsync(query, CancellationToken.None); + + // Assert + result.IsValid.Should().BeFalse(); + result.Errors.Should().ContainSingle(e => e.PropertyName == nameof(query.Id) && e.ErrorMessage == "'Id' must not be empty."); + } + + [Test] + public async Task should_return_success_when_query_is_valid_async() + { + // Arrange + var query = new GetEquipmentTypeByIdQuery(Guid.NewGuid()); + var validator = new GetEquipmentTypeByIdQueryValidator(); + + // Act + var result = await validator.ValidateAsync(query, CancellationToken.None); + + // Assert + result.IsValid.Should().BeTrue(); + result.Errors.Should().BeEmpty(); + } +} diff --git a/StudioManager.Application.Tests/Equipments/DeleteEquipmentCommandHandlerTests/Handle.cs b/StudioManager.Application.Tests/Equipments/DeleteEquipmentCommandHandlerTests/Handle.cs index 610bb5b..f2e6a6f 100644 --- a/StudioManager.Application.Tests/Equipments/DeleteEquipmentCommandHandlerTests/Handle.cs +++ b/StudioManager.Application.Tests/Equipments/DeleteEquipmentCommandHandlerTests/Handle.cs @@ -25,7 +25,7 @@ public async Task SetUpAsync() } [Test] - public async Task should_return_not_found_when_updating_non_existing_entity_async() + public async Task should_return_not_found_when_removing_non_existing_entity_async() { // Arrange await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) diff --git a/StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Handle.cs b/StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Handle.cs new file mode 100644 index 0000000..d534698 --- /dev/null +++ b/StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Handle.cs @@ -0,0 +1,79 @@ +using FluentAssertions; +using NUnit.Framework; +using StudioManager.API.Contracts.Equipments; +using StudioManager.Application.Equipments.GetById; +using StudioManager.Domain.Common.Results; +using StudioManager.Domain.Entities; +using StudioManager.Infrastructure; +using StudioManager.Tests.Common; +using StudioManager.Tests.Common.DbContextExtensions; + +namespace StudioManager.Application.Tests.Equipments.GetEquipmentByIdQueryHandlerTests; + +public sealed class Handle : IntegrationTestBase +{ + private static GetEquipmentByIdQueryHandler _testCandidate = null!; + private static TestDbContextFactory _testDbContextFactory = null!; + + + [SetUp] + public async Task SetUpAsync() + { + var connectionString = await DbMigrator.MigrateDbAsync(); + _testDbContextFactory = new TestDbContextFactory(connectionString); + _testCandidate = new GetEquipmentByIdQueryHandler(_testDbContextFactory, Mapper); + } + + [Test] + public async Task should_return_not_found_when_getting_non_existing_entity_async() + { + // Arrange + await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) + { + await ClearTableContentsForAsync(dbContext); + } + + var id = Guid.NewGuid(); + + var command = new GetEquipmentByIdQuery(id); + + // Act + var result = await _testCandidate.Handle(command, Cts.Token); + + result.Should().NotBeNull(); + result.Should().BeOfType>(); + result.Data.Should().BeNull(); + result.Succeeded.Should().BeFalse(); + result.StatusCode.Should().Be(NotFoundStatusCode); + result.Error.Should().NotBeNullOrWhiteSpace(); + result.Error.Should().Be($"[NOT FOUND] {nameof(Equipment)} with id '{id}' does not exist"); + } + + [Test] + public async Task should_return_success_async() + { + // Arrange + var equipmentType = EquipmentType.Create("Test-Equipment-Type"); + var equipment = Equipment.Create("Test-Equipment", equipmentType.Id, 1); + await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) + { + await ClearTableContentsForAsync(dbContext); + await ClearTableContentsForAsync(dbContext); + await AddEntitiesToTable(dbContext, equipmentType); + await AddEntitiesToTable(dbContext, equipment); + } + + var command = new GetEquipmentByIdQuery(equipment.Id); + + // Act + var result = await _testCandidate.Handle(command, Cts.Token); + + result.Should().NotBeNull(); + result.Should().BeOfType>(); + result.Data.Should().NotBeNull(); + result.Data.Should().BeOfType(); + result.Succeeded.Should().BeTrue(); + result.StatusCode.Should().Be(OkStatusCode); + result.Error.Should().BeNullOrWhiteSpace(); + } +} diff --git a/StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Validator.cs b/StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Validator.cs new file mode 100644 index 0000000..e8544f8 --- /dev/null +++ b/StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Validator.cs @@ -0,0 +1,42 @@ +using FluentAssertions; +using NUnit.Framework; +using StudioManager.Application.Equipments.GetById; + +namespace StudioManager.Application.Tests.Equipments.GetEquipmentByIdQueryHandlerTests; + +public sealed class Validator +{ + [Test] + public async Task should_return_error_when_id_is_empty_async() + { + // Arrange + var command = new GetEquipmentByIdQuery(Guid.Empty); + var validator = new GetEquipmentByIdQueryValidator(); + + // Act + var result = await validator.ValidateAsync(command, CancellationToken.None); + + // Assert + result.Should().NotBeNull(); + result.IsValid.Should().BeFalse(); + result.Errors.Should().NotBeNullOrEmpty(); + result.Errors.Should().HaveCount(1); + result.Errors.First().ErrorMessage.Should().Be("'Id' must not be empty."); + } + + [Test] + public async Task should_return_success_when_query_is_valid_async() + { + // Arrange + var command = new GetEquipmentByIdQuery(Guid.NewGuid()); + var validator = new GetEquipmentByIdQueryValidator(); + + // Act + var result = await validator.ValidateAsync(command, CancellationToken.None); + + // Assert + result.Should().NotBeNull(); + result.IsValid.Should().BeTrue(); + result.Errors.Should().BeEmpty(); + } +} diff --git a/StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Handle.cs b/StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Handle.cs new file mode 100644 index 0000000..64100a7 --- /dev/null +++ b/StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Handle.cs @@ -0,0 +1,68 @@ +using FluentAssertions; +using NUnit.Framework; +using StudioManager.API.Contracts.Reservations; +using StudioManager.Application.Reservations.GetById; +using StudioManager.Application.Tests.Reservations.Common; +using StudioManager.Domain.Common.Results; +using StudioManager.Domain.Entities; +using StudioManager.Infrastructure; +using StudioManager.Tests.Common; +using StudioManager.Tests.Common.DbContextExtensions; + +namespace StudioManager.Application.Tests.Reservations.GetReservationByIdQueryHandlerTests; + +public sealed class Handle : IntegrationTestBase +{ + private static TestDbContextFactory _dbContextFactory = null!; + private static GetReservationByIdQueryHandler _testCandidate = null!; + + [SetUp] + public async Task SetUpAsync() + { + var connectionString = await DbMigrator.MigrateDbAsync(); + _dbContextFactory = new TestDbContextFactory(connectionString); + _testCandidate = new GetReservationByIdQueryHandler(_dbContextFactory, Mapper); + } + + [Test] + public async Task should_return_not_found_when_requesting_non_existing_reservation_async() + { + // Arrange + var command = new GetReservationByIdQuery(Guid.NewGuid()); + + // Act + var result = await _testCandidate.Handle(command, CancellationToken.None); + + // Assert + result.Should().NotBeNull(); + result.Succeeded.Should().BeFalse(); + result.StatusCode.Should().Be(NotFoundStatusCode); + result.Data.Should().BeNull(); + result.Should().BeOfType>(); + result.Error.Should().NotBeNullOrWhiteSpace(); + result.Error.Should().Be($"[NOT FOUND] {nameof(Reservation)} with id '{command.Id}' does not exist"); + } + + [Test] + public async Task should_return_success_async() + { + // Arrange + await using var dbContext = await _dbContextFactory.CreateDbContextAsync(); + var reservation = + await ReservationTestHelper.AddReservationAsync(dbContext); + + var command = new GetReservationByIdQuery(reservation.Id); + + // Act + var result = await _testCandidate.Handle(command, CancellationToken.None); + + // Assert + result.Should().NotBeNull(); + result.Succeeded.Should().BeTrue(); + result.StatusCode.Should().Be(OkStatusCode); + result.Data.Should().NotBeNull(); + result.Data.Should().BeOfType(); + result.Should().BeOfType>(); + result.Error.Should().BeNullOrWhiteSpace(); + } +} diff --git a/StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Validator.cs b/StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Validator.cs new file mode 100644 index 0000000..e66e5a1 --- /dev/null +++ b/StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Validator.cs @@ -0,0 +1,39 @@ +using FluentAssertions; +using NUnit.Framework; +using StudioManager.Application.Reservations.GetById; + +namespace StudioManager.Application.Tests.Reservations.GetReservationByIdQueryHandlerTests; + +public sealed class Validator +{ + [Test] + public async Task should_return_error_when_id_is_empty_async() + { + // Arrange + var query = new GetReservationByIdQuery(Guid.Empty); + var validator = new GetReservationByIdQueryValidator(); + + // Act + var result = await validator.ValidateAsync(query, CancellationToken.None); + + // Assert + result.IsValid.Should().BeFalse(); + result.Errors.Should().ContainSingle(e => e.PropertyName == nameof(query.Id) && e.ErrorMessage == "'Id' must not be empty."); + } + + [Test] + public async Task should_return_success_when_query_is_valid_async() + { + // Arrange + var query = new GetReservationByIdQuery(Guid.NewGuid()); + var validator = new GetReservationByIdQueryValidator(); + + // Act + var result = await validator.ValidateAsync(query, CancellationToken.None); + + // Assert + result.Should().NotBeNull(); + result.IsValid.Should().BeTrue(); + result.Errors.Should().BeEmpty(); + } +} diff --git a/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommand.cs b/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommand.cs index 8ae134d..e135ef5 100644 --- a/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommand.cs +++ b/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommand.cs @@ -1,7 +1,6 @@ -using MediatR; -using StudioManager.API.Contracts.EquipmentTypes; +using StudioManager.API.Contracts.EquipmentTypes; using StudioManager.Domain.Common.Results; namespace StudioManager.Application.EquipmentTypes.Create; -public sealed record CreateEquipmentTypeCommand(EquipmentTypeWriteDto EquipmentType) : IRequest; +public sealed record CreateEquipmentTypeCommand(EquipmentTypeWriteDto EquipmentType) : ICommand; diff --git a/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommandHandler.cs b/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommandHandler.cs index 782a88a..4843657 100644 --- a/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommandHandler.cs +++ b/StudioManager.Application/EquipmentTypes/Create/CreateEquipmentTypeCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -11,7 +10,7 @@ namespace StudioManager.Application.EquipmentTypes.Create; public sealed class CreateEquipmentTypeCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(CreateEquipmentTypeCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommand.cs b/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommand.cs index c103325..7e3a476 100644 --- a/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommand.cs +++ b/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommand.cs @@ -1,6 +1,5 @@ -using MediatR; -using StudioManager.Domain.Common.Results; +using StudioManager.Domain.Common.Results; namespace StudioManager.Application.EquipmentTypes.Delete; -public sealed record DeleteEquipmentTypeCommand(Guid Id) : IRequest; +public sealed record DeleteEquipmentTypeCommand(Guid Id) : ICommand; diff --git a/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommandHandler.cs b/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommandHandler.cs index 5a55dde..d043409 100644 --- a/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommandHandler.cs +++ b/StudioManager.Application/EquipmentTypes/Delete/DeleteEquipmentTypeCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -10,7 +9,7 @@ namespace StudioManager.Application.EquipmentTypes.Delete; public sealed class DeleteEquipmentTypeCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(DeleteEquipmentTypeCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQuery.cs b/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQuery.cs index 8bde8ef..3b45468 100644 --- a/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQuery.cs +++ b/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQuery.cs @@ -1,11 +1,10 @@ -using MediatR; -using StudioManager.API.Contracts.EquipmentTypes; +using StudioManager.API.Contracts.EquipmentTypes; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Filters; namespace StudioManager.Application.EquipmentTypes.GetAll; -public sealed class GetEquipmentTypesQuery : IRequest>> +public sealed class GetEquipmentTypesQuery : IQuery> { public required EquipmentTypeFilter Filter { get; init; } } diff --git a/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQueryHandler.cs b/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQueryHandler.cs index f9d54e2..c9a8ab5 100644 --- a/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQueryHandler.cs +++ b/StudioManager.Application/EquipmentTypes/GetAll/GetEquipmentTypesQueryHandler.cs @@ -1,6 +1,5 @@ using AutoMapper; using AutoMapper.QueryableExtensions; -using MediatR; using Microsoft.EntityFrameworkCore; using StudioManager.API.Contracts.EquipmentTypes; using StudioManager.Domain.Common.Results; @@ -11,7 +10,7 @@ namespace StudioManager.Application.EquipmentTypes.GetAll; public sealed class GetEquipmentTypesQueryHandler( IDbContextFactory dbContextFactory, IMapper mapper) - : IRequestHandler>> + : IQueryHandler> { public async Task>> Handle( GetEquipmentTypesQuery request, diff --git a/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQuery.cs b/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQuery.cs new file mode 100644 index 0000000..c5f275f --- /dev/null +++ b/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQuery.cs @@ -0,0 +1,9 @@ +using StudioManager.API.Contracts.EquipmentTypes; +using StudioManager.Domain.Common.Results; + +namespace StudioManager.Application.EquipmentTypes.GetById; + +public sealed record GetEquipmentTypeByIdQuery(Guid Id) : IQuery +{ + public Guid Id { get; } = Id; +} diff --git a/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQueryHandler.cs b/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQueryHandler.cs new file mode 100644 index 0000000..2e14722 --- /dev/null +++ b/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQueryHandler.cs @@ -0,0 +1,31 @@ +using AutoMapper; +using AutoMapper.QueryableExtensions; +using Microsoft.EntityFrameworkCore; +using StudioManager.API.Contracts.EquipmentTypes; +using StudioManager.Domain.Common.Results; +using StudioManager.Domain.ErrorMessages; +using StudioManager.Infrastructure; + +namespace StudioManager.Application.EquipmentTypes.GetById; + +public sealed class GetEquipmentTypeByIdQueryHandler( + IDbContextFactory dbContextFactory, + IMapper mapper) + : IQueryHandler +{ + public async Task> Handle(GetEquipmentTypeByIdQuery request, + CancellationToken cancellationToken) + { + await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); + + var equipmentType = await dbContext.EquipmentTypes + .AsNoTracking() + .Where(x => x.Id == request.Id) + .ProjectTo(mapper.ConfigurationProvider) + .FirstOrDefaultAsync(cancellationToken); + + return equipmentType is null + ? QueryResult.NotFound(string.Format(DB_FORMAT.EQUIPMENT_TYPE_NOT_FOUND, request.Id)) + : QueryResult.Success(equipmentType); + } +} diff --git a/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQueryValidator.cs b/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQueryValidator.cs new file mode 100644 index 0000000..62ff327 --- /dev/null +++ b/StudioManager.Application/EquipmentTypes/GetById/GetEquipmentTypeByIdQueryValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; + +namespace StudioManager.Application.EquipmentTypes.GetById; + +public sealed class GetEquipmentTypeByIdQueryValidator : AbstractValidator +{ + public GetEquipmentTypeByIdQueryValidator() + { + RuleFor(x => x.Id).NotEmpty(); + } +} diff --git a/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommand.cs b/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommand.cs index 4a4e4b7..d1e449f 100644 --- a/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommand.cs +++ b/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommand.cs @@ -1,7 +1,6 @@ -using MediatR; -using StudioManager.API.Contracts.EquipmentTypes; +using StudioManager.API.Contracts.EquipmentTypes; using StudioManager.Domain.Common.Results; namespace StudioManager.Application.EquipmentTypes.Update; -public sealed record UpdateEquipmentTypeCommand(Guid Id, EquipmentTypeWriteDto EquipmentType) : IRequest; +public sealed record UpdateEquipmentTypeCommand(Guid Id, EquipmentTypeWriteDto EquipmentType) : ICommand; diff --git a/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommandHandler.cs b/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommandHandler.cs index 8968eb4..ce04dd6 100644 --- a/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommandHandler.cs +++ b/StudioManager.Application/EquipmentTypes/Update/UpdateEquipmentTypeCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -11,7 +10,7 @@ namespace StudioManager.Application.EquipmentTypes.Update; public sealed class UpdateEquipmentTypeCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(UpdateEquipmentTypeCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/Equipments/Create/CreateEquipmentCommand.cs b/StudioManager.Application/Equipments/Create/CreateEquipmentCommand.cs index 258817f..3f1c52f 100644 --- a/StudioManager.Application/Equipments/Create/CreateEquipmentCommand.cs +++ b/StudioManager.Application/Equipments/Create/CreateEquipmentCommand.cs @@ -1,7 +1,6 @@ -using MediatR; -using StudioManager.API.Contracts.Equipments; +using StudioManager.API.Contracts.Equipments; using StudioManager.Domain.Common.Results; namespace StudioManager.Application.Equipments.Create; -public sealed record CreateEquipmentCommand(EquipmentWriteDto Equipment) : IRequest; +public sealed record CreateEquipmentCommand(EquipmentWriteDto Equipment) : ICommand; diff --git a/StudioManager.Application/Equipments/Create/CreateEquipmentCommandHandler.cs b/StudioManager.Application/Equipments/Create/CreateEquipmentCommandHandler.cs index 50e0ca7..f1353dd 100644 --- a/StudioManager.Application/Equipments/Create/CreateEquipmentCommandHandler.cs +++ b/StudioManager.Application/Equipments/Create/CreateEquipmentCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.Equipments.Common; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -9,7 +8,7 @@ namespace StudioManager.Application.Equipments.Create; public sealed class CreateEquipmentCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(CreateEquipmentCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommand.cs b/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommand.cs index 4c55a5f..f82dd4c 100644 --- a/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommand.cs +++ b/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommand.cs @@ -1,6 +1,5 @@ -using MediatR; -using StudioManager.Domain.Common.Results; +using StudioManager.Domain.Common.Results; namespace StudioManager.Application.Equipments.Delete; -public sealed record DeleteEquipmentCommand(Guid Id) : IRequest; +public sealed record DeleteEquipmentCommand(Guid Id) : ICommand; diff --git a/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommandHandler.cs b/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommandHandler.cs index 110bae2..f89eaa9 100644 --- a/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommandHandler.cs +++ b/StudioManager.Application/Equipments/Delete/DeleteEquipmentCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -11,7 +10,7 @@ namespace StudioManager.Application.Equipments.Delete; public sealed class DeleteEquipmentCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(DeleteEquipmentCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQuery.cs b/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQuery.cs index 201564f..cec6851 100644 --- a/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQuery.cs +++ b/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQuery.cs @@ -1,5 +1,4 @@ -using MediatR; -using StudioManager.API.Contracts.Equipments; +using StudioManager.API.Contracts.Equipments; using StudioManager.API.Contracts.Pagination; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Filters; @@ -9,7 +8,7 @@ namespace StudioManager.Application.Equipments.GetAll; public sealed class GetAllEquipmentsQuery( EquipmentFilter filter, PaginationDto pagination) - : IRequest>> + : IQuery> { public EquipmentFilter Filter { get; } = filter; public PaginationDto Pagination { get; } = pagination; diff --git a/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQueryHandler.cs b/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQueryHandler.cs index 8f88c05..7c73358 100644 --- a/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQueryHandler.cs +++ b/StudioManager.Application/Equipments/GetAll/GetAllEquipmentsQueryHandler.cs @@ -1,6 +1,5 @@ using AutoMapper; using AutoMapper.QueryableExtensions; -using MediatR; using Microsoft.EntityFrameworkCore; using StudioManager.API.Contracts.Equipments; using StudioManager.API.Contracts.Pagination; @@ -13,7 +12,7 @@ namespace StudioManager.Application.Equipments.GetAll; public sealed class GetAllEquipmentsQueryHandler( IMapper mapper, IDbContextFactory dbContextFactory) - : IRequestHandler>> + : IQueryHandler> { public async Task>> Handle(GetAllEquipmentsQuery request, CancellationToken cancellationToken) diff --git a/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQuery.cs b/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQuery.cs new file mode 100644 index 0000000..8920f2f --- /dev/null +++ b/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQuery.cs @@ -0,0 +1,9 @@ +using StudioManager.API.Contracts.Equipments; +using StudioManager.Domain.Common.Results; + +namespace StudioManager.Application.Equipments.GetById; + +public sealed record GetEquipmentByIdQuery(Guid Id) : IQuery +{ + public Guid Id { get; } = Id; +} diff --git a/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQueryHandler.cs b/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQueryHandler.cs new file mode 100644 index 0000000..c9ba255 --- /dev/null +++ b/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQueryHandler.cs @@ -0,0 +1,31 @@ +using AutoMapper; +using AutoMapper.QueryableExtensions; +using Microsoft.EntityFrameworkCore; +using StudioManager.API.Contracts.Equipments; +using StudioManager.Domain.Common.Results; +using StudioManager.Domain.ErrorMessages; +using StudioManager.Infrastructure; + +namespace StudioManager.Application.Equipments.GetById; + +public sealed class GetEquipmentByIdQueryHandler( + IDbContextFactory dbContextFactory, + IMapper mapper) + : IQueryHandler +{ + public async Task> Handle(GetEquipmentByIdQuery request, + CancellationToken cancellationToken) + { + await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); + + var equipment = await dbContext.Equipments + .AsNoTracking() + .Where(x => x.Id == request.Id) + .ProjectTo(mapper.ConfigurationProvider) + .FirstOrDefaultAsync(cancellationToken); + + return equipment is null + ? QueryResult.NotFound(string.Format(DB_FORMAT.EQUIPMENT_DOES_NOT_EXIST, request.Id)) + : QueryResult.Success(equipment); + } +} diff --git a/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQueryValidator.cs b/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQueryValidator.cs new file mode 100644 index 0000000..6bd8c83 --- /dev/null +++ b/StudioManager.Application/Equipments/GetById/GetEquipmentByIdQueryValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; + +namespace StudioManager.Application.Equipments.GetById; + +public sealed class GetEquipmentByIdQueryValidator : AbstractValidator +{ + public GetEquipmentByIdQueryValidator() + { + RuleFor(x => x.Id).NotEmpty(); + } +} diff --git a/StudioManager.Application/Equipments/Update/UpdateEquipmentCommand.cs b/StudioManager.Application/Equipments/Update/UpdateEquipmentCommand.cs index 9eacc0c..0778613 100644 --- a/StudioManager.Application/Equipments/Update/UpdateEquipmentCommand.cs +++ b/StudioManager.Application/Equipments/Update/UpdateEquipmentCommand.cs @@ -1,7 +1,6 @@ -using MediatR; -using StudioManager.API.Contracts.Equipments; +using StudioManager.API.Contracts.Equipments; using StudioManager.Domain.Common.Results; namespace StudioManager.Application.Equipments.Update; -public sealed record UpdateEquipmentCommand(Guid Id, EquipmentWriteDto Equipment) : IRequest; +public sealed record UpdateEquipmentCommand(Guid Id, EquipmentWriteDto Equipment) : ICommand; diff --git a/StudioManager.Application/Equipments/Update/UpdateEquipmentCommandHandler.cs b/StudioManager.Application/Equipments/Update/UpdateEquipmentCommandHandler.cs index 0d21670..33b28a2 100644 --- a/StudioManager.Application/Equipments/Update/UpdateEquipmentCommandHandler.cs +++ b/StudioManager.Application/Equipments/Update/UpdateEquipmentCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Application.Equipments.Common; using StudioManager.Domain.Common.Results; @@ -10,7 +9,7 @@ namespace StudioManager.Application.Equipments.Update; public sealed class UpdateEquipmentCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(UpdateEquipmentCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/Reservations/Create/CreateReservationCommand.cs b/StudioManager.Application/Reservations/Create/CreateReservationCommand.cs index ccef50a..0ce7389 100644 --- a/StudioManager.Application/Reservations/Create/CreateReservationCommand.cs +++ b/StudioManager.Application/Reservations/Create/CreateReservationCommand.cs @@ -1,7 +1,6 @@ -using MediatR; -using StudioManager.API.Contracts.Reservations; +using StudioManager.API.Contracts.Reservations; using StudioManager.Domain.Common.Results; namespace StudioManager.Application.Reservations.Create; -public sealed record CreateReservationCommand(ReservationWriteDto Reservation) : IRequest; +public sealed record CreateReservationCommand(ReservationWriteDto Reservation) : ICommand; diff --git a/StudioManager.Application/Reservations/Create/CreateReservationCommandHandler.cs b/StudioManager.Application/Reservations/Create/CreateReservationCommandHandler.cs index 394cc16..8930b52 100644 --- a/StudioManager.Application/Reservations/Create/CreateReservationCommandHandler.cs +++ b/StudioManager.Application/Reservations/Create/CreateReservationCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.Reservations.Common; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -10,7 +9,7 @@ namespace StudioManager.Application.Reservations.Create; public sealed class CreateReservationCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(CreateReservationCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/Reservations/Delete/DeleteReservationCommand.cs b/StudioManager.Application/Reservations/Delete/DeleteReservationCommand.cs index 6929833..3dc0efd 100644 --- a/StudioManager.Application/Reservations/Delete/DeleteReservationCommand.cs +++ b/StudioManager.Application/Reservations/Delete/DeleteReservationCommand.cs @@ -1,6 +1,5 @@ -using MediatR; -using StudioManager.Domain.Common.Results; +using StudioManager.Domain.Common.Results; namespace StudioManager.Application.Reservations.Delete; -public sealed record DeleteReservationCommand(Guid Id) : IRequest; +public sealed record DeleteReservationCommand(Guid Id) : ICommand; diff --git a/StudioManager.Application/Reservations/Delete/DeleteReservationCommandHandler.cs b/StudioManager.Application/Reservations/Delete/DeleteReservationCommandHandler.cs index 7104322..86e0b63 100644 --- a/StudioManager.Application/Reservations/Delete/DeleteReservationCommandHandler.cs +++ b/StudioManager.Application/Reservations/Delete/DeleteReservationCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Entities; @@ -10,7 +9,7 @@ namespace StudioManager.Application.Reservations.Delete; public sealed class DeleteReservationCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(DeleteReservationCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/Reservations/GetAll/GetAllReservationsQuery.cs b/StudioManager.Application/Reservations/GetAll/GetAllReservationsQuery.cs index 432d437..dd4532f 100644 --- a/StudioManager.Application/Reservations/GetAll/GetAllReservationsQuery.cs +++ b/StudioManager.Application/Reservations/GetAll/GetAllReservationsQuery.cs @@ -1,5 +1,4 @@ -using MediatR; -using StudioManager.API.Contracts.Pagination; +using StudioManager.API.Contracts.Pagination; using StudioManager.API.Contracts.Reservations; using StudioManager.Domain.Common.Results; using StudioManager.Domain.Filters; @@ -9,7 +8,7 @@ namespace StudioManager.Application.Reservations.GetAll; public sealed class GetAllReservationsQuery( ReservationFilter filter, PaginationDto pagination) - : IRequest>> + : IQuery> { public ReservationFilter Filter { get; } = filter; public PaginationDto Pagination { get; } = pagination; diff --git a/StudioManager.Application/Reservations/GetAll/GetAllReservationsQueryHandler.cs b/StudioManager.Application/Reservations/GetAll/GetAllReservationsQueryHandler.cs index f29ad9d..105d8d3 100644 --- a/StudioManager.Application/Reservations/GetAll/GetAllReservationsQueryHandler.cs +++ b/StudioManager.Application/Reservations/GetAll/GetAllReservationsQueryHandler.cs @@ -1,6 +1,5 @@ using AutoMapper; using AutoMapper.QueryableExtensions; -using MediatR; using Microsoft.EntityFrameworkCore; using StudioManager.API.Contracts.Pagination; using StudioManager.API.Contracts.Reservations; @@ -13,7 +12,7 @@ namespace StudioManager.Application.Reservations.GetAll; public sealed class GetAllReservationsQueryHandler( IDbContextFactory dbContextFactory, IMapper mapper) - : IRequestHandler>> + : IQueryHandler> { public async Task>> Handle(GetAllReservationsQuery request, CancellationToken cancellationToken) diff --git a/StudioManager.Application/Reservations/GetById/GetReservationByIdQuery.cs b/StudioManager.Application/Reservations/GetById/GetReservationByIdQuery.cs new file mode 100644 index 0000000..6303e1f --- /dev/null +++ b/StudioManager.Application/Reservations/GetById/GetReservationByIdQuery.cs @@ -0,0 +1,9 @@ +using StudioManager.API.Contracts.Reservations; +using StudioManager.Domain.Common.Results; + +namespace StudioManager.Application.Reservations.GetById; + +public sealed record GetReservationByIdQuery(Guid Id) : IQuery +{ + public Guid Id { get; } = Id; +} diff --git a/StudioManager.Application/Reservations/GetById/GetReservationByIdQueryHandler.cs b/StudioManager.Application/Reservations/GetById/GetReservationByIdQueryHandler.cs new file mode 100644 index 0000000..4e7dd02 --- /dev/null +++ b/StudioManager.Application/Reservations/GetById/GetReservationByIdQueryHandler.cs @@ -0,0 +1,31 @@ +using AutoMapper; +using AutoMapper.QueryableExtensions; +using Microsoft.EntityFrameworkCore; +using StudioManager.API.Contracts.Reservations; +using StudioManager.Domain.Common.Results; +using StudioManager.Domain.ErrorMessages; +using StudioManager.Infrastructure; + +namespace StudioManager.Application.Reservations.GetById; + +public sealed class GetReservationByIdQueryHandler( + IDbContextFactory dbContextFactory, + IMapper mapper) + : IQueryHandler +{ + public async Task> Handle(GetReservationByIdQuery request, + CancellationToken cancellationToken) + { + await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); + + var reservation = await dbContext.Reservations + .AsNoTracking() + .Where(x => x.Id == request.Id) + .ProjectTo(mapper.ConfigurationProvider) + .FirstOrDefaultAsync(cancellationToken); + + return reservation is null + ? QueryResult.NotFound(string.Format(DB_FORMAT.RESERVATION_NOT_FOUND, request.Id)) + : QueryResult.Success(reservation); + } +} diff --git a/StudioManager.Application/Reservations/GetById/GetReservationByIdQueryValidator.cs b/StudioManager.Application/Reservations/GetById/GetReservationByIdQueryValidator.cs new file mode 100644 index 0000000..3877168 --- /dev/null +++ b/StudioManager.Application/Reservations/GetById/GetReservationByIdQueryValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; + +namespace StudioManager.Application.Reservations.GetById; + +public sealed class GetReservationByIdQueryValidator : AbstractValidator +{ + public GetReservationByIdQueryValidator() + { + RuleFor(x => x.Id).NotEmpty(); + } +} diff --git a/StudioManager.Application/Reservations/Update/UpdateReservationCommand.cs b/StudioManager.Application/Reservations/Update/UpdateReservationCommand.cs index e39e102..25ae5cd 100644 --- a/StudioManager.Application/Reservations/Update/UpdateReservationCommand.cs +++ b/StudioManager.Application/Reservations/Update/UpdateReservationCommand.cs @@ -1,7 +1,6 @@ -using MediatR; -using StudioManager.API.Contracts.Reservations; +using StudioManager.API.Contracts.Reservations; using StudioManager.Domain.Common.Results; namespace StudioManager.Application.Reservations.Update; -public sealed record UpdateReservationCommand(Guid Id, ReservationWriteDto Reservation) : IRequest; +public sealed record UpdateReservationCommand(Guid Id, ReservationWriteDto Reservation) : ICommand; diff --git a/StudioManager.Application/Reservations/Update/UpdateReservationCommandHandler.cs b/StudioManager.Application/Reservations/Update/UpdateReservationCommandHandler.cs index a745f13..b9fbeed 100644 --- a/StudioManager.Application/Reservations/Update/UpdateReservationCommandHandler.cs +++ b/StudioManager.Application/Reservations/Update/UpdateReservationCommandHandler.cs @@ -1,5 +1,4 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using StudioManager.Application.DbContextExtensions; using StudioManager.Application.Reservations.Common; using StudioManager.Domain.Common.Results; @@ -10,7 +9,7 @@ namespace StudioManager.Application.Reservations.Update; public sealed class UpdateReservationCommandHandler( IDbContextFactory dbContextFactory) - : IRequestHandler + : ICommandHandler { public async Task Handle(UpdateReservationCommand request, CancellationToken cancellationToken) { diff --git a/StudioManager.Application/StudioManager.Application.csproj b/StudioManager.Application/StudioManager.Application.csproj index 8519368..ee534df 100644 --- a/StudioManager.Application/StudioManager.Application.csproj +++ b/StudioManager.Application/StudioManager.Application.csproj @@ -16,7 +16,6 @@ - diff --git a/StudioManager.Domain/Common/Results/ICommand.cs b/StudioManager.Domain/Common/Results/ICommand.cs new file mode 100644 index 0000000..216639f --- /dev/null +++ b/StudioManager.Domain/Common/Results/ICommand.cs @@ -0,0 +1,5 @@ +using MediatR; + +namespace StudioManager.Domain.Common.Results; + +public interface ICommand : IRequest; diff --git a/StudioManager.Domain/Common/Results/ICommandHandler.cs b/StudioManager.Domain/Common/Results/ICommandHandler.cs new file mode 100644 index 0000000..52a758f --- /dev/null +++ b/StudioManager.Domain/Common/Results/ICommandHandler.cs @@ -0,0 +1,6 @@ +using MediatR; + +namespace StudioManager.Domain.Common.Results; + +public interface ICommandHandler : IRequestHandler + where TCommand : IRequest; diff --git a/StudioManager.Domain/Common/Results/IQuery.cs b/StudioManager.Domain/Common/Results/IQuery.cs new file mode 100644 index 0000000..b63da06 --- /dev/null +++ b/StudioManager.Domain/Common/Results/IQuery.cs @@ -0,0 +1,5 @@ +using MediatR; + +namespace StudioManager.Domain.Common.Results; + +public interface IQuery : IRequest>; diff --git a/StudioManager.Domain/Common/Results/IQueryHandler.cs b/StudioManager.Domain/Common/Results/IQueryHandler.cs new file mode 100644 index 0000000..cd6632a --- /dev/null +++ b/StudioManager.Domain/Common/Results/IQueryHandler.cs @@ -0,0 +1,6 @@ +using MediatR; + +namespace StudioManager.Domain.Common.Results; + +public interface IQueryHandler : IRequestHandler> + where TQuery : IRequest>; diff --git a/StudioManager.Domain/Common/Results/IRequestResult.cs b/StudioManager.Domain/Common/Results/IRequestResult.cs index a1de2dc..cb6c61b 100644 --- a/StudioManager.Domain/Common/Results/IRequestResult.cs +++ b/StudioManager.Domain/Common/Results/IRequestResult.cs @@ -1,11 +1,18 @@ using System.Net; +using System.Text.Json.Serialization; namespace StudioManager.Domain.Common.Results; public interface IRequestResult { public bool Succeeded { get; } + + [JsonIgnore] public HttpStatusCode StatusCode { get; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public T? Data { get; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Error { get; } } diff --git a/StudioManager.Domain/Entities/EntityBase.cs b/StudioManager.Domain/Entities/EntityBase.cs index 2f2cc61..3f81bbb 100644 --- a/StudioManager.Domain/Entities/EntityBase.cs +++ b/StudioManager.Domain/Entities/EntityBase.cs @@ -5,6 +5,7 @@ namespace StudioManager.Domain.Entities; public abstract class EntityBase { + [NotMapped] private readonly List _entityEvents = []; public Guid Id { get; protected init; } diff --git a/StudioManager.Domain/ErrorMessages/DB.cs b/StudioManager.Domain/ErrorMessages/DB.cs index e9bae0d..940dc4d 100644 --- a/StudioManager.Domain/ErrorMessages/DB.cs +++ b/StudioManager.Domain/ErrorMessages/DB.cs @@ -105,6 +105,73 @@ public static class DB_FORMAT "Cannot remove equipment, the initial count ({0}) is not equal to the current count ({1})"; public const string EQUIPMENT_DUPLICATE_NAME_TYPE = "Equipment with name {0} and type {1} already exists"; + public const string EQUIPMENT_DOES_NOT_EXIST = "[NOT FOUND] Equipment with id '{0}' does not exist"; + + + + + + + + + + + + + + + #endregion + #region Reservations + + + + + + + + + + + + + + + public const string RESERVATION_NOT_FOUND = "[NOT FOUND] Reservation with id '{0}' does not exist"; + + + + + + + + + + + + + + + #endregion + + + + + #region EquipmentTypes + + + + + + + + + + + + + + + public const string EQUIPMENT_TYPE_NOT_FOUND = "[NOT FOUND] EquipmentType with id '{0}' does not exist";