-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
38 lines (31 loc) · 966 Bytes
/
Copy pathProgram.cs
File metadata and controls
38 lines (31 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<ProductRepository>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapGet("/products", (ProductRepository repository) =>
{
return Results.Ok(repository.GetAllProducts());
});
app.MapGet("/product/{id:Guid}", (ProductRepository repository, Guid Id) =>
{
return Results.Ok(repository.GetProductById(Id));
});
app.MapPost("/product/", (ProductRepository repository, Product product) =>
{
repository.Create(product);
return Results.Created($"/product/{product.Id}", product);
});
app.MapDelete("/product/{id:Guid}", (ProductRepository repository, Guid Id) =>
{
repository.Delete(Id);
return Results.Ok();
});
app.MapPut("/product/", (ProductRepository repository, Product product) =>
{
repository.Update(product);
return Results.Ok();
});
app.Run();