forked from sanchezvem/PyroFetes
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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);
 | |
|     }
 | |
| } |