using System.Security.Claims; using FastEndpoints; using Microsoft.EntityFrameworkCore; namespace Faben.Api.Endpoints; public class CheckPriceOfferRequestResponse { public bool IsExist { get; set; } } public class CheckPriceOfferRequestEndpoint(FabenDbContext context) : Endpoint { public override void Configure() { Get("check-price-offer/by-product/{id}"); Version(1); AllowAnonymous(); } public override async Task HandleAsync(EmptyRequest req, CancellationToken c) { var h = HttpContext.User.FindFirstValue("Id"); var id = Route("id"); var isExist = await context.PriceOfferRequests.AnyAsync(p => p.UserId == h && p.ProductId == id); await SendOkAsync(new CheckPriceOfferRequestResponse { IsExist = isExist }, c); } } public class SendPriceOfferRequestEndpoint(FabenDbContext context) : Endpoint { public override void Configure() { Post("price-offer"); Version(1); AllowAnonymous(); } public override async Task HandleAsync(SendPriceOfferRequestModel req, CancellationToken c) { var h = HttpContext.User.FindFirstValue("Id"); context.PriceOfferRequests.Add(new PriceOfferRequest { UserId = h!, ProductId = req.ProductId, CreationTime = DateTimeOffset.Now }); await context.SaveChangesAsync(c); await SendNoContentAsync(c); } } public class SendPriceOfferRequestModel { public Guid ProductId { get; set; } }