From a554693e9ca91761a53cc3096dab3ae547cde900 Mon Sep 17 00:00:00 2001 From: carteronm Date: Thu, 4 Dec 2025 16:31:52 +0100 Subject: [PATCH] =?UTF-8?q?Provider=20typ=C3=AA=20added=20+=20delete=20cus?= =?UTF-8?q?tomer=20updated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeleteCustomerTypeEndpoint.cs | 12 +++--- .../CreateProviderTypeEndpoint.cs | 34 +++++++++++++++++ .../DeleteProviderTypeEndpoint.cs | 30 +++++++++++++++ .../GetAllProviderTypesEndpoint.cs | 25 ++++++++++++ .../ProviderType/GetProviderTypeEndpoint.cs | 34 +++++++++++++++++ .../UpdateProviderTypeEndpoint.cs | 38 +++++++++++++++++++ 6 files changed, 166 insertions(+), 7 deletions(-) create mode 100644 PyroFetes/Endpoints/ProviderType/CreateProviderTypeEndpoint.cs create mode 100644 PyroFetes/Endpoints/ProviderType/DeleteProviderTypeEndpoint.cs create mode 100644 PyroFetes/Endpoints/ProviderType/GetAllProviderTypesEndpoint.cs create mode 100644 PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs create mode 100644 PyroFetes/Endpoints/ProviderType/UpdateProviderTypeEndpoint.cs diff --git a/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs index 48d2982..820271d 100644 --- a/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs +++ b/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs @@ -1,13 +1,11 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Customer.Request; -using PyroFetes.DTO.Customer.Response; using PyroFetes.DTO.CustomerType.Request; using PyroFetes.DTO.CustomerType.Response; namespace PyroFetes.Endpoints.CustomerType; -public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { @@ -15,16 +13,16 @@ public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : AllowAnonymous(); } - public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct) + public override async Task HandleAsync(GetCustomerTypeRequest req, CancellationToken ct) { - Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); - if (databaseCustomer == null) + if (databaseCustomerType == null) { await Send.NotFoundAsync(ct); return; } - pyroFetesDbContext.Customers.Remove(databaseCustomer); + pyroFetesDbContext.CustomerTypes.Remove(databaseCustomerType); await pyroFetesDbContext.SaveChangesAsync(ct); await Send.NoContentAsync(ct); diff --git a/PyroFetes/Endpoints/ProviderType/CreateProviderTypeEndpoint.cs b/PyroFetes/Endpoints/ProviderType/CreateProviderTypeEndpoint.cs new file mode 100644 index 0000000..a82ae38 --- /dev/null +++ b/PyroFetes/Endpoints/ProviderType/CreateProviderTypeEndpoint.cs @@ -0,0 +1,34 @@ +using FastEndpoints; +using PyroFetes.DTO.ProviderType.Request; +using PyroFetes.DTO.ProviderType.Response; + +namespace PyroFetes.Endpoints.ProviderType; + +public class CreateProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Post("/api/providertypes"); + AllowAnonymous(); + } + + + public override async Task HandleAsync(CreateProviderTypeDto req, CancellationToken ct) + { + var providerType = new Models.ProviderType + { + Label = req.Label + }; + pyroFetesDbContext.Add(providerType); + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetProviderTypeDto response = new GetProviderTypeDto() + { + Id = providerType.Id, + Label = providerType.Label + }; + + await Send.OkAsync(response, ct); + + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/ProviderType/DeleteProviderTypeEndpoint.cs b/PyroFetes/Endpoints/ProviderType/DeleteProviderTypeEndpoint.cs new file mode 100644 index 0000000..c075a21 --- /dev/null +++ b/PyroFetes/Endpoints/ProviderType/DeleteProviderTypeEndpoint.cs @@ -0,0 +1,30 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.ProviderType.Request; +using PyroFetes.DTO.ProviderType.Response; + +namespace PyroFetes.Endpoints.ProviderType; + +public class DeleteProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Delete ("/api/providertypes/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetProviderTypeRequest req, CancellationToken ct) + { + Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseProviderType == null) + { + await Send.NotFoundAsync(ct); + return; + } + pyroFetesDbContext.ProviderTypes.Remove(databaseProviderType); + await pyroFetesDbContext.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/ProviderType/GetAllProviderTypesEndpoint.cs b/PyroFetes/Endpoints/ProviderType/GetAllProviderTypesEndpoint.cs new file mode 100644 index 0000000..61f454e --- /dev/null +++ b/PyroFetes/Endpoints/ProviderType/GetAllProviderTypesEndpoint.cs @@ -0,0 +1,25 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.ProviderType.Response; + +namespace PyroFetes.Endpoints.ProviderType; + +public class GetAllProviderTypesEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get ("/api/providertype"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + List providerType= await pyroFetesDbContext.ProviderTypes.Select(x => new GetProviderTypeDto() + { + Id = x.Id, + Label = x.Label, + }).ToListAsync(ct); + + await Send.OkAsync(providerType, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs b/PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs new file mode 100644 index 0000000..79a01f1 --- /dev/null +++ b/PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs @@ -0,0 +1,34 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.ProviderType.Request; +using PyroFetes.DTO.ProviderType.Response; + +namespace PyroFetes.Endpoints.ProviderType; + +public class GetProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Get ("/api/providertype/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetProviderTypeRequest req, CancellationToken ct) + { + Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseProviderType == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetProviderTypeDto dto = new() + { + Id = databaseProviderType.Id, + Label = databaseProviderType.Label, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/ProviderType/UpdateProviderTypeEndpoint.cs b/PyroFetes/Endpoints/ProviderType/UpdateProviderTypeEndpoint.cs new file mode 100644 index 0000000..ce0fb83 --- /dev/null +++ b/PyroFetes/Endpoints/ProviderType/UpdateProviderTypeEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.ProviderType.Request; +using PyroFetes.DTO.ProviderType.Response; + +namespace PyroFetes.Endpoints.ProviderType; + +public class UpdateProviderTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Put ("/api/providertypes/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateProviderTypeDto req, CancellationToken ct) + { + Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseProviderType == null) + { + await Send.NotFoundAsync(ct); + return; + } + else + { + databaseProviderType.Label = req.Label; + } + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetProviderTypeDto dto = new() + { + Id = databaseProviderType.Id, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file