feat(vehicles): API /api/vehicles - contrôleur + recherche par plaque (#150)
Résumé
Implémentation complète de l'API Vehicles (Phase 17 spec) : contrôleur REST + handlers CQRS MediatR.
Endpoints
GET /api/vehicles - Liste avec recherche par plaque (?search=XX-XXX-XX) + pagination
GET /api/vehicles/{id} - Détail avec historique events (50 derniers) + personne associée
POST /api/vehicles - Créer un véhicule
PUT /api/vehicles/{id} - Mettre à jour + associer/dissocier une personne
DELETE /api/vehicles/{id} - Supprimer un véhicule
Fichiers modifiés/créés
- src/Heimdall.Domain/Entities/Vehicle.cs - AssignPerson accepte Guid? (permet unassign)
- src/Heimdall.Infrastructure/Security/AppPermissions.cs - VehicleRead/VehicleWrite ajoutés
- src/Heimdall.Application/DTOs/VehicleDto.cs - Response, Request, EventSummary
- src/Heimdall.Application/Vehicles/ - Commands + Queries + Mapping
- src/Heimdall.Web/Controllers/VehiclesController.cs - 5 endpoints
- tests/Heimdall.Application.Tests/Handlers/Vehicles/ - 16 tests unitaires
Tests
Build 0 erreurs 0 warnings
16 nouveaux tests unitaires
Suite complète ~1149 tests 0 échec
Closes #9
Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/150
This commit is contained in:
1 parent
66cec88e6e
commit
f7e6b0cec3
15 files changed
+677
-3
No files matched your search
@@ -0,0 +1,65 @@
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Vehicles.Commands.CreateVehicle;
|
||||
using Heimdall.Application.Vehicles.Commands.UpdateVehicle;
|
||||
using Heimdall.Application.Vehicles.Commands.DeleteVehicle;
|
||||
using Heimdall.Application.Vehicles.Queries.GetVehicle;
|
||||
using Heimdall.Application.Vehicles.Queries.GetVehicles;
|
||||
using Heimdall.Infrastructure.Security;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
||||
namespace Heimdall.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/vehicles")]
|
||||
[EnableRateLimiting("Api")]
|
||||
public class VehiclesController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public VehiclesController(IMediator mediator) => _mediator = mediator;
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.VehicleRead)]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll([FromQuery] string? search, [FromQuery] int page = 1, [FromQuery] int pageSize = 50, CancellationToken ct = default)
|
||||
{
|
||||
var result = await _mediator.Send(new GetVehiclesQuery(search, page, pageSize), ct);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.VehicleRead)]
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _mediator.Send(new GetVehicleQuery(id), ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.VehicleWrite)]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateVehicleRequest request, CancellationToken ct)
|
||||
{
|
||||
var command = new CreateVehicleCommand(request.LicensePlate, request.PersonId, request.Make, request.Model, request.Color);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.VehicleWrite)]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateVehicleRequest request, CancellationToken ct)
|
||||
{
|
||||
var command = new UpdateVehicleCommand(id, request.LicensePlate, request.Make, request.Model, request.Color, request.PersonId);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess ? Ok(result.Data) : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.VehicleWrite)]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||||
{
|
||||
var result = await _mediator.Send(new DeleteVehicleCommand(id), ct);
|
||||
return result.IsSuccess ? Ok() : StatusCode(result.StatusCode ?? 404, new { error = result.Error });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user