124 lines
3.8 KiB
C#
124 lines
3.8 KiB
C#
List<Request> requests = new()
|
|
{
|
|
new Request() { Uuid= Guid.Parse("7777fa5f-b786-4478-863a-99cc000eb752"), Title = "Документ (прием на работу)", DateDocument = new DateTime(2023, 8, 05), Employee = "Иванов Иван Иванович", IsAgreed = false },
|
|
new Request() { Uuid= Guid.Parse("77a9aed1-218a-468e-92b9-99f6a6a34543"), Title = "Документ (увольнение)", DateDocument = new DateTime(2023, 8, 05), Employee = "Петров Петр Петрович", IsAgreed = 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,
|
|
DateDocument = r.DateDocument,
|
|
Employee = r.Employee,
|
|
IsAgreed = r.IsAgreed,
|
|
});
|
|
})
|
|
.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,
|
|
DateDocument = request.DateDocument,
|
|
Employee = request.Employee,
|
|
IsAgreed = request.IsAgreed,
|
|
});
|
|
})
|
|
.WithName("GetRequestByGUID")
|
|
.WithOpenApi();
|
|
|
|
app.MapPost("/{title}/{Employee}/{DateDocument}/{IsAgreed}", (string title, string Employee, DateTime DateDocument, bool IsAgreed) =>
|
|
{
|
|
Guid NewGuid = Guid.NewGuid();
|
|
requests.Add(new Request() { Uuid = NewGuid, Title = (string)title, Employee = (string)Employee, DateDocument = (DateTime)DateDocument, IsAgreed = (bool)IsAgreed});
|
|
|
|
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,
|
|
DateDocument = request.DateDocument,
|
|
Employee = request.Employee,
|
|
IsAgreed = request.IsAgreed,
|
|
});
|
|
})
|
|
.WithName("PostRequest")
|
|
.WithOpenApi();
|
|
|
|
app.MapPatch("/{uuid}/{title}/{Employee}/{DateDocument}/{IsAgreed}", (Guid uuid, string? title, string? Employee, DateTime DateDocument, bool IsAgreed) =>
|
|
{
|
|
var request = requests.FirstOrDefault(r => r.Uuid == uuid);
|
|
if (request == null)
|
|
return Results.NotFound();
|
|
if (title != null) request.Title = title;
|
|
if (Employee != ",") request.Employee = Employee;
|
|
if (DateDocument != request.DateDocument) request.DateDocument = DateDocument;
|
|
if (IsAgreed != request.IsAgreed) request.IsAgreed = IsAgreed;
|
|
|
|
return Results.Json(new RequestEntityDto()
|
|
{
|
|
Uuid = request.Uuid,
|
|
Title = request.Title,
|
|
DateDocument = request.DateDocument,
|
|
Employee = request.Employee,
|
|
IsAgreed = request.IsAgreed,
|
|
});
|
|
})
|
|
.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,
|
|
DateDocument = request.DateDocument,
|
|
Employee = request.Employee,
|
|
IsAgreed = request.IsAgreed,
|
|
});
|
|
})
|
|
.WithName("DeleteRequestByGUID")
|
|
.WithOpenApi();
|
|
|
|
app.Run();
|
|
|
|
public class Request
|
|
{
|
|
public Guid Uuid { get; set; }
|
|
public string Title { get; set; } = string.Empty;
|
|
public string Employee { get; set; } = string.Empty;
|
|
public DateTime DateDocument { get; set; }
|
|
public bool IsAgreed { get; set; }
|
|
}
|
|
|
|
public class RequestEntityDto : Request { } |