Refactor all code

This commit is contained in:
2026-05-24 17:22:03 +01:00
parent fe58e5e7e7
commit 656100d15e
117 changed files with 3317 additions and 1562 deletions
@@ -6,9 +6,7 @@ using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Deliverers;
public class CreateDelivererEndpoint(
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateDelivererDto, GetDelivererDto>
public class CreateDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<CreateDelivererDto, GetDelivererDto>
{
public override void Configure()
{
@@ -18,13 +16,12 @@ public class CreateDelivererEndpoint(
public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct)
{
Deliverer newDeliverer = new Deliverer()
Deliverer newDeliverer = new()
{
Transporter = req.Transporter,
};
await deliverersRepository.AddAsync(newDeliverer, ct);
await Send.OkAsync(mapper.Map<GetDelivererDto>(newDeliverer), ct);
await Send.NoContentAsync(ct);
}
}
}
@@ -9,28 +9,26 @@ public class DeleteDelivererRequest
{
public int DelivererId { get; set; }
}
public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<DeleteDelivererRequest>
{
public override void Configure()
{
Delete("/deliverers/{@id}", x=>new {x.DelivererId});
Delete("/deliverers/{@Id}", x => new { x.DelivererId });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteDelivererRequest req, CancellationToken ct)
{
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
if (deliverer == null)
if (deliverer is null)
{
await Send.NotFoundAsync(ct);
return;
}
await deliverersRepository.DeleteAsync(deliverer, ct);
await Send.OkAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,6 +1,4 @@
using AutoMapper.QueryableExtensions;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Repositories;
@@ -12,12 +10,10 @@ public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository)
{
Get("/deliverers");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct);
}
}
@@ -1,5 +1,4 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
@@ -12,22 +11,19 @@ public class GetDelivererRequest
public int DelivererId { get; set; }
}
public class GetDelivererEndpoint(
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
public class GetDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
{
public override void Configure()
{
Get("/deliverers/{@id}", x=>new {x.DelivererId});
Get("/deliverers/{@Id}", x => new { x.DelivererId });
AllowAnonymous();
}
public override async Task HandleAsync(GetDelivererRequest req, CancellationToken ct)
{
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
if (deliverer == null)
if (deliverer is null)
{
await Send.NotFoundAsync(ct);
return;
@@ -35,5 +31,4 @@ public class GetDelivererEndpoint(
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
}
}
@@ -1,5 +1,4 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Request;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
@@ -8,32 +7,27 @@ using PyroFetes.Specifications.Deliverers;
namespace PyroFetes.Endpoints.Deliverers;
public class UpdateDelivererEndpoint(
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
public class UpdateDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
{
public override void Configure()
{
Put("/deliverers/{@id}", x=>new {x.Id});
Put("/deliverers/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateDelivererDto req, CancellationToken ct)
{
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.Id), ct);
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.Id), ct);
if (deliverer == null)
if (deliverer is null)
{
await Send.NotFoundAsync(ct);
return;
}
deliverer.Transporter = req.Transporter;
await deliverersRepository.UpdateAsync(deliverer,ct);
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
mapper.Map(req, deliverer);
await deliverersRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}