Provider typê added + delete customer updated
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.Customer.Request;
|
|
||||||
using PyroFetes.DTO.Customer.Response;
|
|
||||||
using PyroFetes.DTO.CustomerType.Request;
|
using PyroFetes.DTO.CustomerType.Request;
|
||||||
using PyroFetes.DTO.CustomerType.Response;
|
using PyroFetes.DTO.CustomerType.Response;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.CustomerType;
|
namespace PyroFetes.Endpoints.CustomerType;
|
||||||
|
|
||||||
public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerRequest, GetCustomerDto>
|
public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCustomerTypeRequest, GetCustomerTypeDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -15,16 +13,16 @@ public class DeleteCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
|||||||
AllowAnonymous();
|
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);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pyroFetesDbContext.Customers.Remove(databaseCustomer);
|
pyroFetesDbContext.CustomerTypes.Remove(databaseCustomerType);
|
||||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
|
|||||||
@@ -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<CreateProviderTypeDto, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 <GetProviderTypeRequest, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.ProviderType.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.ProviderType;
|
||||||
|
|
||||||
|
public class GetAllProviderTypesEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetProviderTypeDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get ("/api/providertype");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetProviderTypeDto> providerType= await pyroFetesDbContext.ProviderTypes.Select(x => new GetProviderTypeDto()
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Label = x.Label,
|
||||||
|
}).ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(providerType, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs
Normal file
34
PyroFetes/Endpoints/ProviderType/GetProviderTypeEndpoint.cs
Normal file
@@ -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 <GetProviderTypeRequest, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 <UpdateProviderTypeDto, GetProviderTypeDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user