First Commit 09/10
This commit is contained in:
39
PyroFetes/Endpoints/Contact/GetContactEndpoint.cs
Normal file
39
PyroFetes/Endpoints/Contact/GetContactEndpoint.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Contact.Request;
|
||||
using PyroFetes.DTO.Contact.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Contact;
|
||||
|
||||
public class GetContactEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetContactRequest, GetContactDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/contacts/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetContactRequest database, CancellationToken ct)
|
||||
{
|
||||
Models.Contact? databaseContact = await pyroFetesDbContext.Contacts.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseContact == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetContactDto dto = new()
|
||||
{
|
||||
Id = databaseContact.Id,
|
||||
LastName = databaseContact.LastName,
|
||||
FirstName = databaseContact.FirstName,
|
||||
PhoneNumber = databaseContact.PhoneNumber,
|
||||
Email = databaseContact.Email,
|
||||
Address = databaseContact.Address,
|
||||
Role = databaseContact.Role,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user