Compare commits
2 Commits
8bd7fadabc
...
3ada21adae
Author | SHA1 | Date | |
---|---|---|---|
3ada21adae | |||
4f12911263 |
@@ -1,7 +1,10 @@
|
||||
namespace PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.DTO.PurchaseOrder.Response;
|
||||
|
||||
public class GetPurchaseOrderDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? PurchaseConditions { get; set; }
|
||||
public List<GetPurchaseProductDto>? GetPurchaseProductDto { get; set; }
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class DeletePurchaseOrderRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseOrders/{Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.Include(po => po.PurchaseProducts)
|
||||
.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
||||
{
|
||||
database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts);
|
||||
}
|
||||
|
||||
database.PurchaseOrders.Remove(purchaseOrder);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/purchaseOrders");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.Include(p => p.PurchaseProducts)
|
||||
.Select(purchaseOrder => new GetPurchaseOrderDto()
|
||||
{
|
||||
Id = purchaseOrder.Id,
|
||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
||||
.Select(p => new GetPurchaseProductDto
|
||||
{
|
||||
ProductId = p.ProductId,
|
||||
ProductReferences = p.Product.Reference,
|
||||
ProductName = p.Product.Name,
|
||||
ProductDuration = p.Product.Duration,
|
||||
ProductCaliber = p.Product.Caliber,
|
||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
||||
ProductWeight = p.Product.Weight,
|
||||
ProductNec = p.Product.Nec,
|
||||
ProductImage = p.Product.Image,
|
||||
ProductLink = p.Product.Link,
|
||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
||||
PurchaseOrderId = p.PurchaseOrderId,
|
||||
Quantity = p.Quantity,
|
||||
}).ToList()
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(purchaseOrder, ct);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
||||
|
||||
public class GetPurchaseOrderRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetPurchaseOrderDto responseDto = new()
|
||||
{
|
||||
Id = purchaseOrder.Id,
|
||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
||||
.Select(p => new GetPurchaseProductDto
|
||||
{
|
||||
ProductId = p.ProductId,
|
||||
ProductReferences = p.Product.Reference,
|
||||
ProductName = p.Product.Name,
|
||||
ProductDuration = p.Product.Duration,
|
||||
ProductCaliber = p.Product.Caliber,
|
||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
||||
ProductWeight = p.Product.Weight,
|
||||
ProductNec = p.Product.Nec,
|
||||
ProductImage = p.Product.Image,
|
||||
ProductLink = p.Product.Link,
|
||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
||||
PurchaseOrderId = p.PurchaseOrderId,
|
||||
Quantity = p.Quantity,
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
@@ -3,37 +3,32 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
||||
|
||||
public class DeletePurchaseOrderRequest
|
||||
public class DeletePurchaseProductRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseOrderId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseOrders/{Id}", x => new {x.Id});
|
||||
Delete("/api/purchaseProducts/{ProductId}/{PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
|
||||
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = await database.PurchaseOrders
|
||||
.Include(po => po.PurchaseProducts)
|
||||
.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
var purchaseProduct = await database.PurchaseProducts
|
||||
.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
||||
{
|
||||
database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts);
|
||||
}
|
||||
|
||||
database.PurchaseOrders.Remove(purchaseOrder);
|
||||
database.PurchaseProducts.Remove(purchaseProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
|
@@ -9,7 +9,7 @@ public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) :
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/purchaseOrders/{ProductId}/{PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||
Patch("/api/purchaseProducts/{ProductId}/{PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
32
PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs
Normal file
32
PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using FastEndpoints;
|
||||
namespace PyroFetes.Endpoints.Setting;
|
||||
|
||||
public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<CreateSettingDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/setting");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct)
|
||||
{
|
||||
var setting = new Models.Setting()
|
||||
{
|
||||
ElectronicSignature = req.ElectronicSignature,
|
||||
Logo = req.Logo
|
||||
};
|
||||
|
||||
database.Settings.Add(setting);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
33
PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs
Normal file
33
PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.Setting;
|
||||
|
||||
public class DeleteSettingRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSettingRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/setting/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
database.Settings.Remove(setting);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
38
PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Setting;
|
||||
|
||||
public class GetSettingRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSettingRequest, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Setting;
|
||||
|
||||
public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
setting.ElectronicSignature = req.ElectronicSignature;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
37
PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Setting;
|
||||
|
||||
public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}/Logo", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
||||
{
|
||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
setting.Logo = req.Logo;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user