Uso de unit of work para create director
This commit is contained in:
@@ -11,6 +11,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="Features\Directors\Commands\DeleteDirector\" />
|
||||||
|
<Folder Include="Features\Directors\Commands\UpdateDirector\" />
|
||||||
|
<Folder Include="Features\Directors\Queries\" />
|
||||||
<Folder Include="Features\Streamers\Queries\" />
|
<Folder Include="Features\Streamers\Queries\" />
|
||||||
<Folder Include="Features\Videos\Commands\" />
|
<Folder Include="Features\Videos\Commands\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace CleanArchitecture.Application.Features.Directors.Commands.CreateDirector
|
||||||
|
{
|
||||||
|
public class CreateDirectorCommand: IRequest<int>
|
||||||
|
{
|
||||||
|
public string Nombre { get; set; } = string.Empty;
|
||||||
|
public string Apellido { get; set; } = string.Empty;
|
||||||
|
public int VideoId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using CleanArchitecture.Application.Contracts.Persistence;
|
||||||
|
using CleanArchitecture.Domain;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace CleanArchitecture.Application.Features.Directors.Commands.CreateDirector
|
||||||
|
{
|
||||||
|
public class CreateDirectorCommandHandler : IRequestHandler<CreateDirectorCommand, int>
|
||||||
|
{
|
||||||
|
private readonly ILogger<CreateDirectorCommandHandler> logger;
|
||||||
|
private readonly IMapper mapper;
|
||||||
|
private readonly IUnitOfWork unitOfWork;
|
||||||
|
|
||||||
|
public CreateDirectorCommandHandler(ILogger<CreateDirectorCommandHandler> logger, IMapper mapper, IUnitOfWork unitOfWork)
|
||||||
|
{
|
||||||
|
this.logger = logger;
|
||||||
|
this.mapper = mapper;
|
||||||
|
this.unitOfWork = unitOfWork;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<int> Handle(CreateDirectorCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var directorEntity = mapper.Map<Director>(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer;
|
||||||
|
using FluentValidation;
|
||||||
|
|
||||||
|
namespace CleanArchitecture.Application.Features.Directors.Commands.CreateDirector
|
||||||
|
{
|
||||||
|
public class CreateDirectorCommandValidator : AbstractValidator<CreateDirectorCommand>
|
||||||
|
{
|
||||||
|
|
||||||
|
public CreateDirectorCommandValidator()
|
||||||
|
{
|
||||||
|
RuleFor(p=>p.Nombre).NotEmpty().WithMessage("{Nombre} is required.")
|
||||||
|
.NotNull()
|
||||||
|
.MaximumLength(50).WithMessage("{Nombre} must not exceed 50 characters.");
|
||||||
|
|
||||||
|
RuleFor(p => p.Apellido)
|
||||||
|
.NotEmpty().WithMessage("{Apellido} is required.")
|
||||||
|
.NotNull()
|
||||||
|
.MaximumLength(100).WithMessage("{Apellido} must not exceed 50 characters.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using CleanArchitecture.Application.Features.Directors.Commands.CreateDirector;
|
||||||
using CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer;
|
using CleanArchitecture.Application.Features.Streamers.Commands.CreateStreamer;
|
||||||
using CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer;
|
using CleanArchitecture.Application.Features.Streamers.Commands.UpdateStreamer;
|
||||||
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
|
using CleanArchitecture.Application.Features.Videos.Queries.GetVideosList;
|
||||||
@@ -11,12 +12,24 @@ namespace CleanArchitecture.Application.Mappings
|
|||||||
{
|
{
|
||||||
public MappingProfile()
|
public MappingProfile()
|
||||||
{
|
{
|
||||||
CreateMap<Video, VideosVm>();
|
#region Video
|
||||||
CreateMap<VideosVm, Video>();
|
CreateMap<Video, VideosVm>();
|
||||||
CreateMap<CreateStreamerCommand, Streamer>();
|
CreateMap<VideosVm, Video>();
|
||||||
CreateMap<Streamer, CreateStreamerCommand>();
|
#endregion Video
|
||||||
CreateMap<UpdateStreamerCommand, Streamer>();
|
|
||||||
CreateMap<Streamer, UpdateStreamerCommand>();
|
#region Streamer
|
||||||
|
CreateMap<CreateStreamerCommand, Streamer>();
|
||||||
|
CreateMap<Streamer, CreateStreamerCommand>();
|
||||||
|
|
||||||
|
CreateMap<UpdateStreamerCommand, Streamer>();
|
||||||
|
CreateMap<Streamer, UpdateStreamerCommand>();
|
||||||
|
#endregion Streamer
|
||||||
|
|
||||||
|
#region Director
|
||||||
|
CreateMap<CreateDirectorCommand, Director>();
|
||||||
|
CreateMap<Director, CreateDirectorCommand>();
|
||||||
|
|
||||||
|
#endregion Director
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user