Refactor all code
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
@@ -12,21 +11,19 @@ public class GetSupplierRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
public class GetSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/suppliers/{@Id}", x => new {x.Id});
|
||||
Get("/suppliers/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
Supplier? supplier = await suppliersRepository.SingleOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
if (supplier is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user