AJout des DTO et endpoint sur le nouveau git

This commit is contained in:
2025-10-08 15:46:36 +02:00
parent 04cb47802b
commit c729af3d32
66 changed files with 1703 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
using API.DTO.Movement.Request;
using API.DTO.Movement.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Movement;
public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMovementDto, GetMovementDto>
{
public override void Configure()
{
Post("/api/movements");
AllowAnonymous();
}
public override async Task HandleAsync(CreateMovementDto req, CancellationToken ct)
{
Models.Movement movement = new ()
{
Date = req.Date,
Start = req.Start,
Arrival = req.Arrival,
Quantity = req.Quantity
};
pyrofetesdbcontext.Movements.Add(movement);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Movement créée avec succès !");
GetMovementDto responseDto = new ()
{
Date = req.Date,
Start = req.Start,
Arrival = req.Arrival,
Quantity = req.Quantity
};
await Send.OkAsync(responseDto, ct);
}
}

View File

@@ -0,0 +1,38 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Movement;
public class DeleteMovementRequest
{
public int Id { get; set; }
}
public class DeleteMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMovementRequest>
{
public override void Configure()
{
Delete("/api/Movements/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct)
{
Models.Movement? movementToDelete = await pyrofetesdbcontext
.Movements
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
if (movementToDelete == null)
{
Console.WriteLine($"Aucune mouvement avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
pyrofetesdbcontext.Movements.Remove(movementToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,31 @@
using API.DTO.Movement.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Movement;
public class GetAllMovementsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMovementDto>>
{
public override void Configure()
{
Get("/api/movements");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetMovementDto> responseDto = await pyrofetesdbcontext.Movements
.Select(a => new GetMovementDto
{
Id = a.Id,
Date = a.Date,
Start = a.Start,
Arrival = a.Arrival,
Quantity = a.Quantity
}
).ToListAsync(ct);
await Send.OkAsync(responseDto, ct);
}
}

View File

@@ -0,0 +1,45 @@
using API.DTO.Movement.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Movement;
public class GetMovementRequest
{
public int Id { get; set; }
}
public class GetMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetMovementRequest, GetMovementDto>
{
public override void Configure()
{
Get("/api/movements/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct)
{
Models.Movement? movement = await pyrofetesdbcontext
.Movements
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
if (movement == null)
{
Console.WriteLine($"Aucun mouvement avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
GetMovementDto responseDto = new()
{
Id = req.Id,
Date = movement.Date,
Start = movement.Start,
Arrival = movement.Arrival,
Quantity = movement.Quantity
};
await Send.OkAsync(responseDto, ct);
}
}

View File

@@ -0,0 +1,40 @@
using API.DTO.Movement.Request;
using API.DTO.Movement.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Movement;
public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMovementDto, GetMovementDto>
{
public override void Configure()
{
Post("/api/movements");
AllowAnonymous();
}
public override async Task HandleAsync(UpdateMovementDto req, CancellationToken ct)
{
Models.Movement movement = new()
{
Date = req.Date,
Start = req.Start,
Arrival = req.Arrival,
Quantity = req.Quantity
};
pyrofetesdbcontext.Add(movement);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetMovementDto response = new()
{
Id = req.Id,
Date = req.Date,
Start = req.Start,
Arrival = req.Arrival,
Quantity = req.Quantity
};
await Send.OkAsync(response, ct);
}
}