distributed-computing/tasks/khalitova-am/lab_3/worker-1/Program.cs

71 lines
1.8 KiB
C#
Raw Permalink Normal View History

var clients = new List<Client>() {
new Client { Id = "638f2a30-ca73-4772-b827-f9e6d0e81a86", Address = "ул. Улица", Name = "Иван" },
new Client { Id = "638f2a30-ca73-4772-b827-f9e6d0e81a89", Address = "ул. Бульвар", Name = "Петр" }
};
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("/getClients", () =>
{
return clients;
})
.WithName("GetClients");
app.MapGet("getClient/{id}", (string id) =>
{
Client? client = clients.FirstOrDefault(x => x.Id == id);
if (client == null)
return Results.NotFound(new { message = "Клиент не найден" });
return Results.Json(client);
})
.WithName("GetClient");
app.MapPost("createClient", (Client client) =>
{
client.Id = Guid.NewGuid().ToString();
clients.Add(client);
return client;
})
.WithName("CreateClient");
app.MapPut("updateClient/{id}", (Client data) =>
{
Client? client = clients.FirstOrDefault(x => x.Id == data.Id);
if (client == null)
return Results.NotFound(new { message = "Клиент не найден" });
client.Address = data.Address;
client.Name = data.Name;
return Results.Json(client);
})
.WithName("UpdateClient");
app.MapDelete("deleteClient/{id}", (string id) =>
{
Client? client = clients.FirstOrDefault(x => x.Id == id);
if (client == null)
return Results.NotFound(new { message = "Клиент не найден" });
clients.Remove(client);
return Results.Ok();
})
.WithName("DeleteClient");
app.Run();
public class Client
{
public string Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}