17:17 09/10

This commit is contained in:
2025-10-09 17:17:42 +02:00
parent 1734ec0219
commit 91b4aca2fa
76 changed files with 815 additions and 388 deletions

View File

@@ -1,33 +1,34 @@
using PyroFetes.DTO.Material.Request;
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Request;
using API.DTO.Material.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Material;
public class CreateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateMaterialDto, GetMaterialDto>
public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMaterialDto, GetMaterialDto>
{
public override void Configure()
{
Post("/api/material/create");
Post("/material/create");
AllowAnonymous();
}
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
{
Models.Material material = new()
Models.Material quantity = new()
{
Label = req.Label,
Name = req.Label,
Quantity = req.Quantity,
WarehouseId = req.WarehouseId,
};
appDbContext.Materials.Add(material);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Materials.Add(quantity);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Material added");
GetMaterialDto responseDto = new()
{
Id = material.Id,
WarehouseId = material.WarehouseId,
Id = quantity.Id,
WarehouseId = quantity.WarehouseId,
Label = req.Label,
};

View File

@@ -6,17 +6,17 @@ public class DeleteMaterialRequest
{
public int Id { get; set; }
}
public class DeleteMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteMaterialRequest>
public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMaterialRequest>
{
public override void Configure()
{
Delete("/api/materials/{@id}", x => new { x.Id });
Delete("/materials/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
{
Models.Material? materialToDelete = await appDbContext
Models.Material? materialToDelete = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
@@ -27,8 +27,8 @@ public class DeleteMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<
return;
}
appDbContext.Materials.Remove(materialToDelete);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Materials.Remove(materialToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,24 +1,24 @@
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class GetAllMaterialsEndpoint(PyroFetesDbContext appDbContext) : EndpointWithoutRequest<List<GetMaterialDto>>
public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMaterialDto>>
{
public override void Configure()
{
Get("/api/material");
Get("/material");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetMaterialDto> responseDto = await appDbContext.Materials
List<GetMaterialDto> responseDto = await pyrofetesdbcontext.Materials
.Select(a => new GetMaterialDto
{
Id = a.Id,
Label = a.Label,
Label = a.Name,
Quantity = a.Quantity,
WarehouseId = a.WarehouseId,
}

View File

@@ -1,6 +1,5 @@
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
@@ -10,17 +9,17 @@ public class GetMaterialRequest
public int Id { get; set; }
}
public class GetMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<GetMaterialRequest, GetMaterialDto>
public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetMaterialRequest, GetMaterialDto>
{
public override void Configure()
{
Get("/api/material/{@id}", x => new { x.Id });
Get("/material/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
{
Models.Material? material = await appDbContext
Models.Material? material = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
@@ -34,7 +33,7 @@ public class GetMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Get
GetMaterialDto responseDto = new()
{
Id = material.Id,
Label = material.Label,
Label = material.Name,
WarehouseId = material.WarehouseId,
};
await Send.OkAsync(responseDto, ct);

View File

@@ -1,35 +1,34 @@
using PyroFetes.DTO.Material.Request;
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Request;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class UpdateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
{
public override void Configure()
{
Put("/api/material/{@id}", x => new { x.Id });
Put("/material/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
{
Models.Material? materialToEdit = await appDbContext
Models.Material? materialToEdit = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (materialToEdit == null)
{
Console.WriteLine($"Aucun matériel avec l'id {req.Id} trouvé.");
Console.WriteLine("Aucun matériel avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
materialToEdit.Label = req.Label;
materialToEdit.Name = req.Label;
materialToEdit.WarehouseId = req.WarehouseId;
await appDbContext.SaveChangesAsync(ct);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetMaterialDto responseDto = new()
{