First Commit 09/10
This commit is contained in:
30
PyroFetes/Endpoints/Contact/GetAllContactsEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Contact/GetAllContactsEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Contact.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Contact;
|
||||
|
||||
public class GetAllContactxuest(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetContactDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/contacts");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetContactDto> contacts = await pyroFetesDbContext.Contacts.Select(x => new GetContactDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
LastName = x.LastName,
|
||||
FirstName = x.FirstName,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
Email = x.Email,
|
||||
Address = x.Address,
|
||||
Role = x.Role,
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(contacts, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user