add missed dto/enbdpoints
This commit is contained in:
34
PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Customer/CreateCustomerEndpoint.cs
Normal file
@@ -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<CreateCustomerDto, GetCustomerDto>
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
30
PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Customer/DeleteCustomerEndpoint.cs
Normal file
@@ -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 <GetCustomerRequest, GetCustomerDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
25
PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs
Normal file
25
PyroFetes/Endpoints/Customer/GetAllCustomerEndpoint.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Customer.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Customer;
|
||||
|
||||
public class GetAllCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCustomerDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/Customer");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetCustomerDto> customer= await pyroFetesDbContext.Customers.Select(x => new GetCustomerDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
Note = x.Note,
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(customer, ct);
|
||||
}
|
||||
}
|
||||
34
PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Customer/GetCustomerEndpoint.cs
Normal file
@@ -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 <GetCustomerRequest, GetCustomerDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
38
PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Customer/UpdateCustomerEndpoint.cs
Normal file
@@ -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 <UpdateCustomerDto, GetCustomerDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user