Made an update on database and added CreatingDeliveryNotee
This commit is contained in:
@@ -5,7 +5,8 @@ public class CreateDeliveryNoteDto
|
|||||||
public string? TrackingNumber { get; set; }
|
public string? TrackingNumber { get; set; }
|
||||||
public DateOnly EstimateDeliveryDate { get; set; }
|
public DateOnly EstimateDeliveryDate { get; set; }
|
||||||
public DateOnly ExpeditionDate { get; set; }
|
public DateOnly ExpeditionDate { get; set; }
|
||||||
public DateOnly RealDeliveryDate { get; set; }
|
|
||||||
|
|
||||||
public int DelivererId { get; set; }
|
public int DelivererId { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int,int>? ProductQuantities { get; set; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Deliverers;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
|
public class CreateDeliveryNoteEndpoint(
|
||||||
|
DeliveryNotesRepository deliveryNotesRepository,
|
||||||
|
DeliverersRepository deliverersRepository,
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
ProductDeliveriesRepository productDeliveriesRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateDeliveryNoteDto, GetDeliveryNoteDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/api/DeliveryNote");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
|
||||||
|
|
||||||
|
if (deliverer == null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("No deliverer found", 404, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Creating the Delivery Note
|
||||||
|
DeliveryNote newDeliveryNote = new DeliveryNote()
|
||||||
|
{
|
||||||
|
TrackingNumber = req.TrackingNumber,
|
||||||
|
EstimateDeliveryDate = req.EstimateDeliveryDate,
|
||||||
|
ExpeditionDate = req.ExpeditionDate,
|
||||||
|
DelivererId = req.DelivererId,
|
||||||
|
Deliverer = deliverer,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
await deliveryNotesRepository.AddAsync(newDeliveryNote, ct);
|
||||||
|
|
||||||
|
foreach (var productQuantity in req.ProductQuantities!)
|
||||||
|
{
|
||||||
|
Models.Product? product =
|
||||||
|
await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct);
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
ProductDelivery productDelivery = new ProductDelivery()
|
||||||
|
{
|
||||||
|
DeliveryNote = newDeliveryNote,
|
||||||
|
Quantity = productQuantity.Value,
|
||||||
|
Product = product,
|
||||||
|
DeliveryNoteId = newDeliveryNote.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
await productDeliveriesRepository.AddAsync(productDelivery, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(newDeliveryNote), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -326,7 +326,7 @@ namespace PyroFetes.Migrations
|
|||||||
b.Property<DateOnly>("ExpeditionDate")
|
b.Property<DateOnly>("ExpeditionDate")
|
||||||
.HasColumnType("date");
|
.HasColumnType("date");
|
||||||
|
|
||||||
b.Property<DateOnly>("RealDeliveryDate")
|
b.Property<DateOnly?>("RealDeliveryDate")
|
||||||
.HasColumnType("date");
|
.HasColumnType("date");
|
||||||
|
|
||||||
b.Property<string>("TrackingNumber")
|
b.Property<string>("TrackingNumber")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class DeliveryNote
|
|||||||
public int DelivererId { get; set; }
|
public int DelivererId { get; set; }
|
||||||
[Required] public DateOnly EstimateDeliveryDate { get; set; }
|
[Required] public DateOnly EstimateDeliveryDate { get; set; }
|
||||||
[Required] public DateOnly ExpeditionDate { get; set; }
|
[Required] public DateOnly ExpeditionDate { get; set; }
|
||||||
[Required] public DateOnly RealDeliveryDate { get; set; }
|
public DateOnly? RealDeliveryDate { get; set; }
|
||||||
|
|
||||||
public Deliverer? Deliverer { get; set; }
|
public Deliverer? Deliverer { get; set; }
|
||||||
public List<ProductDelivery>? ProductDeliveries { get; set; }
|
public List<ProductDelivery>? ProductDeliveries { get; set; }
|
||||||
|
|||||||
5
PyroFetes/Repositories/DeliveryNotesRepository.cs
Normal file
5
PyroFetes/Repositories/DeliveryNotesRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.Repositories;
|
||||||
|
|
||||||
|
public class DeliveryNotesRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<DeliveryNote>(pyrofetesContext, mapper);
|
||||||
5
PyroFetes/Repositories/ProductDeliveriesRepository.cs
Normal file
5
PyroFetes/Repositories/ProductDeliveriesRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.Repositories;
|
||||||
|
|
||||||
|
public class ProductDeliveriesRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<ProductDelivery>(pyrofetesContext, mapper);
|
||||||
Reference in New Issue
Block a user