51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Distribution.Features.DriverProfile;
|
|
|
|
[ApiController]
|
|
[Route("api/driver-profiles")]
|
|
[Authorize]
|
|
public class DriverProfileController(DriverProfileService service) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
[Authorize(Policy = "driver_profiles.view")]
|
|
public async Task<IActionResult> GetAll([FromQuery] int page = 1, [FromQuery] int pageSize = 20)
|
|
{
|
|
var result = await service.GetAllAsync(page, pageSize);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
[Authorize(Policy = "driver_profiles.view")]
|
|
public async Task<IActionResult> GetById(Guid id)
|
|
{
|
|
var result = await service.GetByIdAsync(id);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize(Policy = "driver_profiles.create")]
|
|
public async Task<IActionResult> Create(CreateDriverProfileRequest request, CancellationToken ct)
|
|
{
|
|
var result = await service.CreateAsync(request, ct);
|
|
return CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
|
|
}
|
|
|
|
[HttpPut("{id:guid}")]
|
|
[Authorize(Policy = "driver_profiles.update")]
|
|
public async Task<IActionResult> Update(Guid id, UpdateDriverProfileRequest request, CancellationToken ct)
|
|
{
|
|
var result = await service.UpdateAsync(id, request, ct);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
[Authorize(Policy = "driver_profiles.deactivate")]
|
|
public async Task<IActionResult> Deactivate(Guid id, CancellationToken ct)
|
|
{
|
|
var success = await service.DeactivateAsync(id, ct);
|
|
return success ? NoContent() : NotFound();
|
|
}
|
|
}
|