diff --git a/PyroFetes/Endpoints/Color/CreateColorEndpoint b/PyroFetes/Endpoints/Color/CreateColorEndpoint new file mode 100644 index 0000000..c194cea --- /dev/null +++ b/PyroFetes/Endpoints/Color/CreateColorEndpoint @@ -0,0 +1,35 @@ +using API.DTO.Color.Request; +using API.DTO.Color.Response; +using FastEndpoints; + +namespace API.Endpoints.Color; + +public class CreateColorEndpoint(AppDbContext appDbContext) : Endpoint +{ + public override void Configure() + { + Post("/color/create"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreateColorDto req, CancellationToken ct) + { + Models.Color color = new() + { + Label = req.Label, + }; + + appDbContext.Colors.Add(color); + await appDbContext.SaveChangesAsync(ct); + Console.WriteLine("Added Color"); + + GetColorDto responseDto = new() + { + Id = color.Id, + Label = req.Label, + }; + + await Send.OkAsync(responseDto, ct); + } + +} \ No newline at end of file