diff --git a/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs index 5c1eb67..7cac0f3 100644 --- a/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs +++ b/PyroFetes/Endpoints/Communication/DeleteCommunicationEndpoint.cs @@ -5,7 +5,7 @@ using PyroFetes.DTO.Communication.Response; namespace PyroFetes.Endpoints.Communication; -public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { diff --git a/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs b/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs new file mode 100644 index 0000000..6ff4e27 --- /dev/null +++ b/PyroFetes/Endpoints/Communication/GetAllCommunicationsEndpoint.cs @@ -0,0 +1,27 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Communication.Response; + +namespace PyroFetes.Endpoints.Communication; + +public class GetAllCommunicationsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get ("/api/communications"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + List communications = await pyroFetesDbContext.Communications.Select(x => new GetCommunicationDto() + { + Id = x.Id, + Calling = x.Calling, + Email = x.Email, + Meeting = x.Meeting, + }).ToListAsync(ct); + + await Send.OkAsync(communications, ct); + } +} diff --git a/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs index 18a8fc0..e860621 100644 --- a/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs +++ b/PyroFetes/Endpoints/Communication/GetCommunicationEndpoint.cs @@ -1,28 +1,36 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Availability.Response; +using PyroFetes.DTO.Communication.Request; using PyroFetes.DTO.Communication.Response; namespace PyroFetes.Endpoints.Communication; -public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> +public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { - Get ("/api/communications"); + Get ("/api/communications/{@Id}", x => new { x.Id }); AllowAnonymous(); } - public override async Task HandleAsync(CancellationToken ct) + public override async Task HandleAsync(GetCommunicationRequest database, CancellationToken ct) { - List communications = await pyroFetesDbContext.Communications.Select(x => new GetCommunicationDto() - { - Id = x.Id, - Calling = x.Calling, - Email = x.Email, - Meeting = x.Meeting, - }).ToListAsync(ct); + Models.Communication? databaseCommunications = await pyroFetesDbContext.Communications.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct); - await Send.OkAsync(communications, ct); + if (databaseCommunications == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetCommunicationDto dto = new() + { + Id = databaseCommunications.Id, + Calling = databaseCommunications.Calling, + Email = databaseCommunications.Email, + Meeting = databaseCommunications.Meeting + }; + + await Send.OkAsync(dto, ct); } -} +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Communication/UpdateCommunicationEndpoint.cs b/PyroFetes/Endpoints/Communication/UpdateCommunicationEndpoint.cs new file mode 100644 index 0000000..f44731f --- /dev/null +++ b/PyroFetes/Endpoints/Communication/UpdateCommunicationEndpoint.cs @@ -0,0 +1,43 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Communication.Request; +using PyroFetes.DTO.Communication.Response; + +namespace PyroFetes.Endpoints.Communication; + +public class UpdateCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Put ("/api/communications/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateCommunicationDto req, CancellationToken ct) + { + Models.Communication? databaseCommunication = await pyroFetesDbContext.Communications.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCommunication == null) + { + await Send.NotFoundAsync(ct); + return; + } + else + { + databaseCommunication.Calling = req.Calling; + databaseCommunication.Email = req.Email; + databaseCommunication.Meeting = req.Meeting; + } + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetCommunicationDto dto = new() + { + Id = databaseCommunication.Id, + Calling = req.Calling, + Email = req.Email, + Meeting = req.Meeting, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs index 3b51b5b..6bce1f4 100644 --- a/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs +++ b/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs @@ -8,7 +8,7 @@ public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End { public override void Configure() { - Post("/api/customer"); + Post("/api/customers"); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs index a812115..703ee11 100644 --- a/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs +++ b/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs @@ -9,7 +9,7 @@ public class DeleteCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End { public override void Configure() { - Delete ("/api/customer/{@Id}", x => new { x.Id }); + Delete ("/api/customers/{@Id}", x => new { x.Id }); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs index d96f3dc..be9ea63 100644 --- a/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs +++ b/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs @@ -8,7 +8,7 @@ public class GetAllCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End { public override void Configure() { - Get ("/api/customer"); + Get ("/api/customers"); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs index be1d2e0..30bd36f 100644 --- a/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs +++ b/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs @@ -9,7 +9,7 @@ public class GetCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi { public override void Configure() { - Get ("/api/customer/{@Id}", x => new { x.Id }); + Get ("/api/customers/{@Id}", x => new { x.Id }); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs index 4f4c22b..0ea7848 100644 --- a/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs +++ b/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs @@ -9,7 +9,7 @@ public class UpdateCustomer(PyroFetesDbContext pyroFetesDbContext) : Endpoint new { x.Id }); + Put ("/api/customers/{@Id}", x => new { x.Id }); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs index b0d00d7..8be7f1e 100644 --- a/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs +++ b/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs @@ -8,7 +8,7 @@ public class CreateCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : { public override void Configure() { - Post("/api/customertype"); + Post("/api/customertypes"); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs index 820271d..9849ad2 100644 --- a/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs +++ b/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs @@ -9,7 +9,7 @@ public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : { public override void Configure() { - Delete ("/api/customertype/{@Id}", x => new { x.Id }); + Delete ("/api/customertypes/{@Id}", x => new { x.Id }); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs index 5dba9e7..e78b1bd 100644 --- a/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs +++ b/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs @@ -8,7 +8,7 @@ public class GetAllCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : { public override void Configure() { - Get ("/api/customertype"); + Get ("/api/customertypes"); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs index e5047f4..25648d1 100644 --- a/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs +++ b/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs @@ -9,7 +9,7 @@ public class GetCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : En { public override void Configure() { - Get ("/api/customertype/{@Id}", x => new { x.Id }); + Get ("/api/customertypes/{@Id}", x => new { x.Id }); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs b/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs index 981953f..53f1741 100644 --- a/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs +++ b/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs @@ -9,7 +9,7 @@ public class UpdateCustomerType(PyroFetesDbContext pyroFetesDbContext) : Endpoin { public override void Configure() { - Put ("/api/customertype/{@Id}", x => new { x.Id }); + Put ("/api/customertypes/{@Id}", x => new { x.Id }); AllowAnonymous(); }