Skip to content

Commit

Permalink
[feat]: refactor MediatR interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-oberaj committed May 26, 2024
1 parent 14d2149 commit a7cb936
Show file tree
Hide file tree
Showing 40 changed files with 95 additions and 101 deletions.
2 changes: 1 addition & 1 deletion StudioManager.API/Controllers/V1/ReservationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using StudioManager.API.Base;
using StudioManager.API.Contracts.Pagination;
using StudioManager.API.Contracts.Reservations;
using StudioManager.Application.Reservations.BetById;
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FluentAssertions;
using NUnit.Framework;
using StudioManager.API.Contracts.Reservations;
using StudioManager.Application.Reservations.BetById;
using StudioManager.Application.Reservations.GetById;
using StudioManager.Application.Tests.Reservations.Common;
using StudioManager.Domain.Common.Results;
using StudioManager.Domain.Entities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions;
using NUnit.Framework;
using StudioManager.Application.Reservations.BetById;
using StudioManager.Application.Reservations.GetById;

namespace StudioManager.Application.Tests.Reservations.GetReservationByIdQueryHandlerTests;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record CreateEquipmentTypeCommand(EquipmentTypeWriteDto EquipmentType) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +10,7 @@ namespace StudioManager.Application.EquipmentTypes.Create;

public sealed class CreateEquipmentTypeCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<CreateEquipmentTypeCommand, CommandResult>
: ICommandHandler<CreateEquipmentTypeCommand>
{
public async Task<CommandResult> Handle(CreateEquipmentTypeCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record DeleteEquipmentTypeCommand(Guid Id) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +9,7 @@ namespace StudioManager.Application.EquipmentTypes.Delete;

public sealed class DeleteEquipmentTypeCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<DeleteEquipmentTypeCommand, CommandResult>
: ICommandHandler<DeleteEquipmentTypeCommand>
{
public async Task<CommandResult> Handle(DeleteEquipmentTypeCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<QueryResult<List<EquipmentTypeReadDto>>>
public sealed class GetEquipmentTypesQuery : IQuery<List<EquipmentTypeReadDto>>
{
public required EquipmentTypeFilter Filter { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using StudioManager.API.Contracts.EquipmentTypes;
using StudioManager.Domain.Common.Results;
Expand All @@ -11,7 +10,7 @@ namespace StudioManager.Application.EquipmentTypes.GetAll;
public sealed class GetEquipmentTypesQueryHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory,
IMapper mapper)
: IRequestHandler<GetEquipmentTypesQuery, QueryResult<List<EquipmentTypeReadDto>>>
: IQueryHandler<GetEquipmentTypesQuery, List<EquipmentTypeReadDto>>
{
public async Task<QueryResult<List<EquipmentTypeReadDto>>> Handle(
GetEquipmentTypesQuery request,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using MediatR;
using StudioManager.API.Contracts.EquipmentTypes;
using StudioManager.API.Contracts.EquipmentTypes;
using StudioManager.Domain.Common.Results;

namespace StudioManager.Application.EquipmentTypes.GetById;

public sealed record GetEquipmentTypeByIdQuery(Guid Id) : IRequest<QueryResult<EquipmentTypeReadDto>>
public sealed record GetEquipmentTypeByIdQuery(Guid Id) : IQuery<EquipmentTypeReadDto>
{
public Guid Id { get; } = Id;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using StudioManager.API.Contracts.EquipmentTypes;
using StudioManager.Domain.Common.Results;
Expand All @@ -12,9 +11,10 @@ namespace StudioManager.Application.EquipmentTypes.GetById;
public sealed class GetEquipmentTypeByIdQueryHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory,
IMapper mapper)
: IRequestHandler<GetEquipmentTypeByIdQuery, QueryResult<EquipmentTypeReadDto>>
: IQueryHandler<GetEquipmentTypeByIdQuery, EquipmentTypeReadDto>
{
public async Task<QueryResult<EquipmentTypeReadDto>> Handle(GetEquipmentTypeByIdQuery request, CancellationToken cancellationToken)
public async Task<QueryResult<EquipmentTypeReadDto>> Handle(GetEquipmentTypeByIdQuery request,
CancellationToken cancellationToken)
{
await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record UpdateEquipmentTypeCommand(Guid Id, EquipmentTypeWriteDto EquipmentType) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +10,7 @@ namespace StudioManager.Application.EquipmentTypes.Update;

public sealed class UpdateEquipmentTypeCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<UpdateEquipmentTypeCommand, CommandResult>
: ICommandHandler<UpdateEquipmentTypeCommand>
{
public async Task<CommandResult> Handle(UpdateEquipmentTypeCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record CreateEquipmentCommand(EquipmentWriteDto Equipment) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +8,7 @@ namespace StudioManager.Application.Equipments.Create;

public sealed class CreateEquipmentCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<CreateEquipmentCommand, CommandResult>
: ICommandHandler<CreateEquipmentCommand>
{
public async Task<CommandResult> Handle(CreateEquipmentCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record DeleteEquipmentCommand(Guid Id) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +10,7 @@ namespace StudioManager.Application.Equipments.Delete;

public sealed class DeleteEquipmentCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<DeleteEquipmentCommand, CommandResult>
: ICommandHandler<DeleteEquipmentCommand>
{
public async Task<CommandResult> Handle(DeleteEquipmentCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +8,7 @@ namespace StudioManager.Application.Equipments.GetAll;
public sealed class GetAllEquipmentsQuery(
EquipmentFilter filter,
PaginationDto pagination)
: IRequest<QueryResult<PagingResultDto<EquipmentReadDto>>>
: IQuery<PagingResultDto<EquipmentReadDto>>
{
public EquipmentFilter Filter { get; } = filter;
public PaginationDto Pagination { get; } = pagination;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using StudioManager.API.Contracts.Equipments;
using StudioManager.API.Contracts.Pagination;
Expand All @@ -13,7 +12,7 @@ namespace StudioManager.Application.Equipments.GetAll;
public sealed class GetAllEquipmentsQueryHandler(
IMapper mapper,
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<GetAllEquipmentsQuery, QueryResult<PagingResultDto<EquipmentReadDto>>>
: IQueryHandler<GetAllEquipmentsQuery, PagingResultDto<EquipmentReadDto>>
{
public async Task<QueryResult<PagingResultDto<EquipmentReadDto>>> Handle(GetAllEquipmentsQuery request,
CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using MediatR;
using StudioManager.API.Contracts.Equipments;
using StudioManager.API.Contracts.Equipments;
using StudioManager.Domain.Common.Results;

namespace StudioManager.Application.Equipments.GetById;

public sealed record GetEquipmentByIdQuery(Guid Id) : IRequest<QueryResult<EquipmentReadDto>>
public sealed record GetEquipmentByIdQuery(Guid Id) : IQuery<EquipmentReadDto>
{
public Guid Id { get; } = Id;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AutoMapper;
using AutoMapper.QueryableExtensions;
using MediatR;
using Microsoft.EntityFrameworkCore;
using StudioManager.API.Contracts.Equipments;
using StudioManager.Domain.Common.Results;
Expand All @@ -12,9 +11,10 @@ namespace StudioManager.Application.Equipments.GetById;
public sealed class GetEquipmentByIdQueryHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory,
IMapper mapper)
: IRequestHandler<GetEquipmentByIdQuery, QueryResult<EquipmentReadDto>>
: IQueryHandler<GetEquipmentByIdQuery, EquipmentReadDto>
{
public async Task<QueryResult<EquipmentReadDto>> Handle(GetEquipmentByIdQuery request, CancellationToken cancellationToken)
public async Task<QueryResult<EquipmentReadDto>> Handle(GetEquipmentByIdQuery request,
CancellationToken cancellationToken)
{
await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record UpdateEquipmentCommand(Guid Id, EquipmentWriteDto Equipment) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +9,7 @@ namespace StudioManager.Application.Equipments.Update;

public sealed class UpdateEquipmentCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<UpdateEquipmentCommand, CommandResult>
: ICommandHandler<UpdateEquipmentCommand>
{
public async Task<CommandResult> Handle(UpdateEquipmentCommand request, CancellationToken cancellationToken)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record CreateReservationCommand(ReservationWriteDto Reservation) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +9,7 @@ namespace StudioManager.Application.Reservations.Create;

public sealed class CreateReservationCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<CreateReservationCommand, CommandResult>
: ICommandHandler<CreateReservationCommand>
{
public async Task<CommandResult> Handle(CreateReservationCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CommandResult>;
public sealed record DeleteReservationCommand(Guid Id) : ICommand;
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +9,7 @@ namespace StudioManager.Application.Reservations.Delete;

public sealed class DeleteReservationCommandHandler(
IDbContextFactory<StudioManagerDbContext> dbContextFactory)
: IRequestHandler<DeleteReservationCommand, CommandResult>
: ICommandHandler<DeleteReservationCommand>
{
public async Task<CommandResult> Handle(DeleteReservationCommand request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,7 +8,7 @@ namespace StudioManager.Application.Reservations.GetAll;
public sealed class GetAllReservationsQuery(
ReservationFilter filter,
PaginationDto pagination)
: IRequest<QueryResult<PagingResultDto<ReservationReadDto>>>
: IQuery<PagingResultDto<ReservationReadDto>>
{
public ReservationFilter Filter { get; } = filter;
public PaginationDto Pagination { get; } = pagination;
Expand Down
Loading

0 comments on commit a7cb936

Please sign in to comment.