List requests = new() { new Request() { Uuid= Guid.Parse("7184fa5f-b786-4478-863a-99cc000eb752"), Title = "Расход на полив полей", WateringField = "Закирова", Sum = 100000, IsCompleted = false }, new Request() { Uuid= Guid.Parse("55a9aed1-218a-468e-92b9-99f6a6a34543"), Title = "Расход времени", WateringField = "Амина", Sum = 25000, IsCompleted = true }, }; var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.MapGet("/", () => { return requests.Select(r => new RequestEntityDto() { Uuid = r.Uuid, Title = r.Title, Sum = r.Sum, WateringField = r.WateringField, IsCompleted = r.IsCompleted, }); }) .WithName("GetRequests") .WithOpenApi(); app.MapGet("/{uuid}", (Guid uuid) => { var request = requests.FirstOrDefault(r => r.Uuid == uuid); if (request == null) return Results.NotFound(); return Results.Json(new RequestEntityDto() { Uuid = request.Uuid, Title = request.Title, Sum = request.Sum, WateringField = request.WateringField, IsCompleted = request.IsCompleted, }); }) .WithName("GetRequestByGUID") .WithOpenApi(); app.MapPost("/{title}/{wateringField}/{sum}/{isCompleted}", (string title, string wateringField, decimal sum, bool isCompleted) => { Guid NewGuid = Guid.NewGuid(); requests.Add(new Request() { Uuid = NewGuid, Title = (string)title, WateringField = (string)wateringField, Sum = (decimal)sum, IsCompleted = (bool)isCompleted}); var request = requests.FirstOrDefault(r => r.Uuid == NewGuid); if (request == null) return Results.NotFound(); return Results.Json(new RequestEntityDto() { Uuid = request.Uuid, Title = request.Title, Sum = request.Sum, WateringField = request.WateringField, IsCompleted = request.IsCompleted, }); }) .WithName("PostRequest") .WithOpenApi(); app.MapPatch("/{uuid}/{title}/{wateringField}/{sum}/{isCompleted}", (Guid uuid, string ?title, string ?wateringField, decimal sum, bool isCompleted) => { var request = requests.FirstOrDefault(r => r.Uuid == uuid); if (request == null) return Results.NotFound(); if (title != null) request.Title = title; if (wateringField != ",") request.WateringField = wateringField; if (sum != request.Sum && sum != 0) request.Sum = sum; if (isCompleted != request.IsCompleted) request.IsCompleted = isCompleted; return Results.Json(new RequestEntityDto() { Uuid = request.Uuid, Title = request.Title, Sum = request.Sum, WateringField = request.WateringField, IsCompleted = request.IsCompleted, }); }) .WithName("UpdateRequest") .WithOpenApi(); app.MapDelete("/{uuid}", (Guid uuid) => { var request = requests.FirstOrDefault(r => r.Uuid == uuid); if (request == null) return Results.NotFound(); requests.Remove(request); return Results.Json(new RequestEntityDto() { Uuid = request.Uuid, Title = request.Title, Sum = request.Sum, WateringField = request.WateringField, IsCompleted = request.IsCompleted, }); }) .WithName("DeleteRequestByGUID") .WithOpenApi(); app.Run(); public class Request { public Guid Uuid { get; set; } public string Title { get; set; } = string.Empty; public string WateringField { get; set; } = string.Empty; public decimal Sum { get; set; } = 0; public bool IsCompleted { get; set; } } public class RequestEntityDto : Request { }