customer type + communication added
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user