customer type + communication added
This commit is contained in:
@@ -5,7 +5,7 @@ using PyroFetes.DTO.Communication.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Communication;
|
||||
|
||||
public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationDto, GetCommunicationEndpoint>
|
||||
public class DeleteCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationDto, GetAllCommunicationsEndpoint>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Communication.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Communication;
|
||||
|
||||
public class GetAllCommunicationsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetCommunicationDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/communications");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetCommunicationDto> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<List<GetCommunicationDto>>
|
||||
public class GetCommunicationEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetCommunicationRequest, GetCommunicationDto>
|
||||
{
|
||||
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<GetCommunicationDto> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <UpdateCommunicationDto, GetCommunicationDto>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public class CreateCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/customer");
|
||||
Post("/api/customers");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class GetAllCustomerEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/customer");
|
||||
Get ("/api/customers");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public class UpdateCustomer(PyroFetesDbContext pyroFetesDbContext) : Endpoint <U
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put ("/api/customer/{@Id}", x => new { x.Id });
|
||||
Put ("/api/customers/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class CreateCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/customertype");
|
||||
Post("/api/customertypes");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class GetAllCustomerTypeEndpoint(PyroFetesDbContext pyroFetesDbContext) :
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/customertype");
|
||||
Get ("/api/customertypes");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user