diff --git a/PyroFetes/DTO/Customer/Request/CreateCustomerDto.cs b/PyroFetes/DTO/Customer/Request/CreateCustomerDto.cs new file mode 100644 index 0000000..6a90c75 --- /dev/null +++ b/PyroFetes/DTO/Customer/Request/CreateCustomerDto.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.Customer.Request; + +public class CreateCustomerDto +{ + public string? Note { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Customer/Request/GetCustomerRequest.cs b/PyroFetes/DTO/Customer/Request/GetCustomerRequest.cs new file mode 100644 index 0000000..e31bd35 --- /dev/null +++ b/PyroFetes/DTO/Customer/Request/GetCustomerRequest.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.Customer.Request; + +public class GetCustomerRequest +{ + public int Id { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Customer/Request/UpdateCustomerDto.cs b/PyroFetes/DTO/Customer/Request/UpdateCustomerDto.cs new file mode 100644 index 0000000..2e18b07 --- /dev/null +++ b/PyroFetes/DTO/Customer/Request/UpdateCustomerDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.Customer.Request; + +public class UpdateCustomerDto +{ + public int Id { get; set; } + public string? Note { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Customer/Response/GetCustomerDto.cs b/PyroFetes/DTO/Customer/Response/GetCustomerDto.cs new file mode 100644 index 0000000..53a00c5 --- /dev/null +++ b/PyroFetes/DTO/Customer/Response/GetCustomerDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.Customer.Response; + +public class GetCustomerDto +{ + public int Id { get; set; } + public string? Note { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/CustomerType/Request/CreateCustomerTypeDto.cs b/PyroFetes/DTO/CustomerType/Request/CreateCustomerTypeDto.cs new file mode 100644 index 0000000..8ccffe0 --- /dev/null +++ b/PyroFetes/DTO/CustomerType/Request/CreateCustomerTypeDto.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.CustomerType.Request; + +public class CreateCustomerTypeDto +{ + public string? Label { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/CustomerType/Request/GetCustomerTypeRequest.cs b/PyroFetes/DTO/CustomerType/Request/GetCustomerTypeRequest.cs new file mode 100644 index 0000000..ce7d70f --- /dev/null +++ b/PyroFetes/DTO/CustomerType/Request/GetCustomerTypeRequest.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.CustomerType.Request; + +public class GetCustomerTypeRequest +{ + public int Id { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/CustomerType/Request/UpdateCustomerTypeDto.cs b/PyroFetes/DTO/CustomerType/Request/UpdateCustomerTypeDto.cs new file mode 100644 index 0000000..a0cd25b --- /dev/null +++ b/PyroFetes/DTO/CustomerType/Request/UpdateCustomerTypeDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.CustomerType.Request; + +public class UpdateCustomerTypeDto +{ + public int Id { get; set; } + public string? Label { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/CustomerType/Response/GetCustomerTypeDto.cs b/PyroFetes/DTO/CustomerType/Response/GetCustomerTypeDto.cs new file mode 100644 index 0000000..ba06dfe --- /dev/null +++ b/PyroFetes/DTO/CustomerType/Response/GetCustomerTypeDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.CustomerType.Response; + +public class GetCustomerTypeDto +{ + public int Id { get; set; } + public string? Label { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Provider/Request/CreateProviderDto.cs b/PyroFetes/DTO/Provider/Request/CreateProviderDto.cs new file mode 100644 index 0000000..2f548d9 --- /dev/null +++ b/PyroFetes/DTO/Provider/Request/CreateProviderDto.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.Provider.Request; + +public class CreateProviderDto +{ + public int? Price { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Provider/Request/GetProviderRequest.cs b/PyroFetes/DTO/Provider/Request/GetProviderRequest.cs new file mode 100644 index 0000000..7af3e05 --- /dev/null +++ b/PyroFetes/DTO/Provider/Request/GetProviderRequest.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.Provider.Request; + +public class GetProviderRequest +{ + public int Id { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Provider/Request/UpdateProviderDto.cs b/PyroFetes/DTO/Provider/Request/UpdateProviderDto.cs new file mode 100644 index 0000000..8b7c0a6 --- /dev/null +++ b/PyroFetes/DTO/Provider/Request/UpdateProviderDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.Provider.Request; + +public class UpdateProviderDto +{ + public int Id { get; set; } + public int? Price { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/Provider/Response/GetProviderDto.cs b/PyroFetes/DTO/Provider/Response/GetProviderDto.cs new file mode 100644 index 0000000..1a5c3ca --- /dev/null +++ b/PyroFetes/DTO/Provider/Response/GetProviderDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.Provider.Response; + +public class GetProviderDto +{ + public int Id { get; set; } + public int? Price { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/ProviderType/Request/CreateProviderTypeDto.cs b/PyroFetes/DTO/ProviderType/Request/CreateProviderTypeDto.cs new file mode 100644 index 0000000..ad598b4 --- /dev/null +++ b/PyroFetes/DTO/ProviderType/Request/CreateProviderTypeDto.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.ProviderType.Request; + +public class CreateProviderTypeDto +{ + public string? Label { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/ProviderType/Request/GetProviderTypeRequest.cs b/PyroFetes/DTO/ProviderType/Request/GetProviderTypeRequest.cs new file mode 100644 index 0000000..897aac3 --- /dev/null +++ b/PyroFetes/DTO/ProviderType/Request/GetProviderTypeRequest.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.DTO.ProviderType.Request; + +public class GetProviderTypeRequest +{ + public int Id { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/ProviderType/Request/UpdateProviderTypeDto.cs b/PyroFetes/DTO/ProviderType/Request/UpdateProviderTypeDto.cs new file mode 100644 index 0000000..ee1d894 --- /dev/null +++ b/PyroFetes/DTO/ProviderType/Request/UpdateProviderTypeDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.ProviderType.Request; + +public class UpdateProviderTypeDto +{ + public int Id { get; set; } + public string? Label { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/ProviderType/Response/GetProviderTypeDto.cs b/PyroFetes/DTO/ProviderType/Response/GetProviderTypeDto.cs new file mode 100644 index 0000000..eb569b5 --- /dev/null +++ b/PyroFetes/DTO/ProviderType/Response/GetProviderTypeDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.ProviderType.Response; + +public class GetProviderTypeDto +{ + public int Id { get; set; } + public string? Label { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs new file mode 100644 index 0000000..0d92c29 --- /dev/null +++ b/PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs @@ -0,0 +1,34 @@ +using FastEndpoints; +using PyroFetes.DTO.Customer.Request; +using PyroFetes.DTO.Customer.Response; + +namespace PyroFetes.Endpoints.Customer; + +public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Post("/api/Customer"); + AllowAnonymous(); + } + + + public override async Task HandleAsync(CreateCustomerDto req, CancellationToken ct) + { + var customer = new Models.Customer + { + Note = req.Note + }; + pyroFetesDbContext.Add(customer); + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetCustomerDto response = new GetCustomerDto() + { + Id = customer.Id, + Note = customer.Note + }; + + await Send.OkAsync(response, ct); + + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs new file mode 100644 index 0000000..aa434d8 --- /dev/null +++ b/PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs @@ -0,0 +1,30 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Customer.Request; +using PyroFetes.DTO.Customer.Response; + +namespace PyroFetes.Endpoints.Customer; + +public class DeleteCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Delete ("/api/Customer/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct) + { + Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCustomer == null) + { + await Send.NotFoundAsync(ct); + return; + } + pyroFetesDbContext.Customers.Remove(databaseCustomer); + await pyroFetesDbContext.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs new file mode 100644 index 0000000..216f8d8 --- /dev/null +++ b/PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs @@ -0,0 +1,25 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Customer.Response; + +namespace PyroFetes.Endpoints.Customer; + +public class GetAllCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get ("/api/Customer"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + List customer= await pyroFetesDbContext.Customers.Select(x => new GetCustomerDto() + { + Id = x.Id, + Note = x.Note, + }).ToListAsync(ct); + + await Send.OkAsync(customer, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs new file mode 100644 index 0000000..0c9de44 --- /dev/null +++ b/PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs @@ -0,0 +1,34 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Customer.Request; +using PyroFetes.DTO.Customer.Response; + +namespace PyroFetes.Endpoints.Customer; + +public class GetCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Get ("/api/Customer/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct) + { + Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCustomer == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetCustomerDto dto = new() + { + Id = databaseCustomer.Id, + Note = databaseCustomer.Note, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs b/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs new file mode 100644 index 0000000..9cdcaf8 --- /dev/null +++ b/PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Customer.Request; +using PyroFetes.DTO.Customer.Response; + +namespace PyroFetes.Endpoints.Customer; + +public class UpdateCustomer(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Put ("/api/Customer/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateCustomerDto req, CancellationToken ct) + { + Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCustomer == null) + { + await Send.NotFoundAsync(ct); + return; + } + else + { + databaseCustomer.Note = req.Note; + } + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetCustomerDto dto = new() + { + Id = databaseCustomer.Id, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs new file mode 100644 index 0000000..096f773 --- /dev/null +++ b/PyroFetes/Endpoints/CustomerType/CreateCustomerTypeEndpoint.cs @@ -0,0 +1,34 @@ +using FastEndpoints; +using PyroFetes.DTO.CustomerType.Response; +using PyroFetes.DTO.CustomerType.Request; + +namespace PyroFetes.Endpoints.CustomerType; + +public class CreateCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Post("/api/CustomerType"); + AllowAnonymous(); + } + + + public override async Task HandleAsync(CreateCustomerTypeDto req, CancellationToken ct) + { + var customerType = new Models.CustomerType + { + Label = req.Label + }; + pyroFetesDbContext.Add(customerType); + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetCustomerTypeDto response = new GetCustomerTypeDto() + { + Id = customerType.Id, + Label = customerType.Label + }; + + await Send.OkAsync(response, ct); + + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs new file mode 100644 index 0000000..9e67e81 --- /dev/null +++ b/PyroFetes/Endpoints/CustomerType/DeleteCustomerTypeEndpoint.cs @@ -0,0 +1,32 @@ +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 override void Configure() + { + Delete ("/api/CustomerType/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetCustomerRequest req, CancellationToken ct) + { + Models.Customer? databaseCustomer = await pyroFetesDbContext.Customers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCustomer == null) + { + await Send.NotFoundAsync(ct); + return; + } + pyroFetesDbContext.Customers.Remove(databaseCustomer); + await pyroFetesDbContext.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs new file mode 100644 index 0000000..449aa9f --- /dev/null +++ b/PyroFetes/Endpoints/CustomerType/GetAllCustomerTypeEndpoint.cs @@ -0,0 +1,25 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.CustomerType.Response; + +namespace PyroFetes.Endpoints.CustomerType; + +public class GetAllCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get ("/api/CustomerType"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + List customerType= await pyroFetesDbContext.CustomerTypes.Select(x => new GetCustomerTypeDto() + { + Id = x.Id, + Label = x.Label, + }).ToListAsync(ct); + + await Send.OkAsync(customerType, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs b/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs new file mode 100644 index 0000000..c1f7599 --- /dev/null +++ b/PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs @@ -0,0 +1,34 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.CustomerType.Request; +using PyroFetes.DTO.CustomerType.Response; + +namespace PyroFetes.Endpoints.CustomerType; + +public class GetCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Get ("/api/CustomerType/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetCustomerTypeRequest req, CancellationToken ct) + { + Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCustomerType == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetCustomerTypeDto dto = new() + { + Id = databaseCustomerType.Id, + Label = databaseCustomerType.Label, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs b/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs new file mode 100644 index 0000000..0c8a362 --- /dev/null +++ b/PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.CustomerType.Request; +using PyroFetes.DTO.CustomerType.Response; + +namespace PyroFetes.Endpoints.CustomerType; + +public class UpdateCustomerType(PyroFetesDbContext pyroFetesDbContext) : Endpoint +{ + public override void Configure() + { + Put ("/api/CustomerType/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateCustomerTypeDto req, CancellationToken ct) + { + Models.CustomerType? databaseCustomerType = await pyroFetesDbContext.CustomerTypes.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseCustomerType == null) + { + await Send.NotFoundAsync(ct); + return; + } + else + { + databaseCustomerType.Label = req.Label; + } + await pyroFetesDbContext.SaveChangesAsync(ct); + + GetCustomerTypeDto dto = new() + { + Id = databaseCustomerType.Id, + }; + + await Send.OkAsync(dto, ct); + } +} \ No newline at end of file