133 lines
3.3 KiB
C#
133 lines
3.3 KiB
C#
|
|
using System.Diagnostics.Contracts;
|
|
|
|
List<Contract> agrs = new()
|
|
{
|
|
new Contract() { Uuid= Guid.NewGuid(), Number = "Договор №655/55 от 01.07.2023", IdRequest = Guid.Parse("a1b5c571-a859-4bb8-9fd2-7431ddd6c464") }
|
|
};
|
|
|
|
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 agrs.Select(r => new ContractEntityDto()
|
|
{
|
|
Uuid = r.Uuid,
|
|
Number = r.Number,
|
|
IdRequest = r.IdRequest,
|
|
});
|
|
})
|
|
.WithName("GetAgreements")
|
|
.WithOpenApi();
|
|
|
|
app.MapGet("/{uuid}", (Guid uuid) =>
|
|
{
|
|
var agr = agrs.FirstOrDefault(r => r.Uuid == uuid);
|
|
if (agr == null)
|
|
return Results.NotFound();
|
|
return Results.Json(new ContractEntityDto()
|
|
{
|
|
Uuid = agr.Uuid,
|
|
Number = agr.Number,
|
|
IdRequest = agr.IdRequest,
|
|
});
|
|
})
|
|
.WithName("GetAgreementByGUID")
|
|
.WithOpenApi();
|
|
|
|
app.MapPost("/{number}/{date}/{sum}/{idRequest}", (string? number, DateOnly date, decimal sum, Guid idRequest) =>
|
|
{
|
|
Guid NewGuid = Guid.NewGuid();
|
|
agrs.Add(new Contract() { Uuid = NewGuid, Number = (string)number, IdRequest = (Guid)idRequest });
|
|
|
|
var agr = agrs.FirstOrDefault(r => r.Uuid == NewGuid);
|
|
if (agr == null)
|
|
return Results.NotFound();
|
|
return Results.Json(new ContractEntityDto()
|
|
{
|
|
Uuid = agr.Uuid,
|
|
Number = agr.Number,
|
|
IdRequest = agr.IdRequest,
|
|
});
|
|
})
|
|
.WithName("PostAgreement")
|
|
.WithOpenApi();
|
|
|
|
app.MapPatch("/{uuid}/{number}/{date}/{sum}/{idRequest}", (Guid uuid, string? number, DateOnly date, decimal sum, Guid idRequest) =>
|
|
{
|
|
var agr = agrs.FirstOrDefault(r => r.Uuid == uuid);
|
|
if (agr == null)
|
|
return Results.NotFound();
|
|
if (number != ",") agr.Number = number;
|
|
if (idRequest != agr.IdRequest) agr.IdRequest = idRequest;
|
|
|
|
return Results.Json(new ContractEntityDto()
|
|
{
|
|
Uuid = agr.Uuid,
|
|
Number = agr.Number,
|
|
IdRequest = agr.IdRequest,
|
|
});
|
|
})
|
|
.WithName("UpdateAgreement")
|
|
.WithOpenApi();
|
|
|
|
app.MapDelete("/{uuid}", (Guid uuid) =>
|
|
{
|
|
var agr = agrs.FirstOrDefault(r => r.Uuid == uuid);
|
|
if (agr == null)
|
|
return Results.NotFound();
|
|
agrs.Remove(agr);
|
|
return Results.Json(new ContractEntityDto()
|
|
{
|
|
Uuid = agr.Uuid,
|
|
Number = agr.Number,
|
|
IdRequest = agr.IdRequest,
|
|
});
|
|
})
|
|
.WithName("DeleteAgreement")
|
|
.WithOpenApi();
|
|
|
|
app.MapGet("/Requests/", async () =>
|
|
{
|
|
var httpClient = new HttpClient();
|
|
var secondWorkerResponse = await httpClient.GetStringAsync("http://worker-1:8080/");
|
|
|
|
return secondWorkerResponse.ToArray();
|
|
})
|
|
.WithName("GetRequests")
|
|
.WithOpenApi();
|
|
|
|
app.Run();
|
|
|
|
public class Contract
|
|
{
|
|
public Guid Uuid { get; set; }
|
|
public string Number { get; set; } = string.Empty;
|
|
public Guid IdRequest { get; set; }
|
|
}
|
|
|
|
public class ContractEntityDto : Contract { }
|
|
|
|
public class Request
|
|
{
|
|
public Guid Uuid { get; set; }
|
|
public string Title { get; set; } = string.Empty;
|
|
public string Student { get; set; } = string.Empty;
|
|
public DateTime DateAgreement { get; set; }
|
|
public bool AgreementValid { get; set; }
|
|
}
|
|
|
|
public class RequestEntityDto : Request { } |