30 lines
861 B
C#
30 lines
861 B
C#
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);
|
|
}
|
|
} |