add missed dto/enbdpoints
This commit is contained in:
@@ -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<CreateCustomerTypeDto, GetCustomerTypeDto>
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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 <GetCustomerRequest, GetCustomerDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.CustomerType.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.CustomerType;
|
||||
|
||||
public class GetAllCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCustomerTypeDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/CustomerType");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetCustomerTypeDto> customerType= await pyroFetesDbContext.CustomerTypes.Select(x => new GetCustomerTypeDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
Label = x.Label,
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(customerType, ct);
|
||||
}
|
||||
}
|
||||
34
PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs
Normal file
34
PyroFetes/Endpoints/CustomerType/GetCustomerTypeEndpoint.cs
Normal file
@@ -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 <GetCustomerTypeRequest, GetCustomerTypeDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
38
PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs
Normal file
38
PyroFetes/Endpoints/CustomerType/UpdateCustomerEndpoint.cs
Normal file
@@ -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 <UpdateCustomerTypeDto, GetCustomerTypeDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user