forked from sanchezvem/PyroFetes
Added last endpoints for delivery Note
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository) : EndpointWithoutRequest<List<GetDeliveryNoteDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/deliveryNotes");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync<GetDeliveryNoteDto>(ct), ct);
|
||||
}
|
||||
|
||||
}
|
||||
35
PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs
Normal file
35
PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.DeliveryNotes;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
public class GetDeliveryNoteRequest
|
||||
{
|
||||
public int DeliveryNoteId { get; set; }
|
||||
}
|
||||
public class GetDeliveryNoteEndpoint(
|
||||
DeliveryNotesRepository deliveryNotesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetDeliveryNoteRequest, GetDeliveryNoteDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/deliveryNote/{@id}", x=> new {x.DeliveryNoteId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetDeliveryNoteRequest req, CancellationToken ct)
|
||||
{
|
||||
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.DeliveryNoteId), ct);
|
||||
|
||||
if (deliveryNote == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNote), ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Request;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Deliverers;
|
||||
using PyroFetes.Specifications.DeliveryNotes;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
public class PatchRealDeliveryDateEndpoint(
|
||||
DeliveryNotesRepository deliveryNotesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchDeliveryNoteRealDeliveryDateDto, GetDeliveryNoteDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/deliveryNote/{@id}", x=> new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct)
|
||||
{
|
||||
DeliveryNote? deliveryNoteToPath =
|
||||
await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id),ct);
|
||||
|
||||
if (deliveryNoteToPath == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate;
|
||||
|
||||
await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNoteToPath), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user