40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using MediatR;
|
|
using AdsManagerService.Domain.AggregatesModel.SampleAggregate;
|
|
|
|
namespace AdsManagerService.API.Application.Queries;
|
|
|
|
/// <summary>
|
|
/// EN: Handler for GetSampleQuery.
|
|
/// VI: Handler cho GetSampleQuery.
|
|
/// </summary>
|
|
public class GetSampleQueryHandler : IRequestHandler<GetSampleQuery, SampleViewModel?>
|
|
{
|
|
private readonly ISampleRepository _sampleRepository;
|
|
|
|
public GetSampleQueryHandler(ISampleRepository sampleRepository)
|
|
{
|
|
_sampleRepository = sampleRepository ?? throw new ArgumentNullException(nameof(sampleRepository));
|
|
}
|
|
|
|
public async Task<SampleViewModel?> Handle(
|
|
GetSampleQuery request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var sample = await _sampleRepository.GetAsync(request.SampleId);
|
|
|
|
if (sample is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new SampleViewModel(
|
|
sample.Id,
|
|
sample.Name,
|
|
sample.Description,
|
|
sample.Status.Name,
|
|
sample.CreatedAt,
|
|
sample.UpdatedAt
|
|
);
|
|
}
|
|
}
|