using Microsoft.AspNetCore.Mvc; namespace Distribution.Features.Vehicle; [ApiController] [Route("api/vehicles")] public class VehicleController(VehicleService service, VehicleDashboardService dashboardService) : ControllerBase { [HttpGet] public async Task GetAll() => Ok(await service.GetAllAsync()); [HttpGet("{id:guid}")] public async Task GetById(Guid id) { var result = await service.GetByIdAsync(id); return result is null ? NotFound() : Ok(result); } [HttpGet("{id:guid}/dashboard")] public async Task Dashboard(Guid id, [FromQuery] DateTime? from, [FromQuery] DateTime? to) { var error = VehicleDashboardService.Validate(from, to); if (error is not null) return BadRequest(new { message = error }); var result = await dashboardService.GetAsync(id, from, to); return result is null ? NotFound() : Ok(result); } [HttpPost] public async Task Create(CreateVehicleRequest request, CancellationToken ct) { var result = await service.CreateAsync(request, ct); return CreatedAtAction(nameof(GetById), new { id = result.Id }, result); } [HttpPut("{id:guid}")] public async Task Update(Guid id, UpdateVehicleRequest request, CancellationToken ct) { var result = await service.UpdateAsync(id, request, ct); return result is null ? NotFound() : Ok(result); } [HttpDelete("{id:guid}")] public async Task Delete(Guid id, CancellationToken ct) { var deleted = await service.DeleteAsync(id, ct); return deleted ? NoContent() : NotFound(); } }