using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Distribution.Features.Store; [ApiController] [Route("api/stores")] [Authorize] public class StoreController(StoreService service) : ControllerBase { [HttpGet] [Authorize(Policy = "stores.view")] public async Task GetAll() => Ok(await service.GetAllAsync()); [HttpGet("{id:guid}")] [Authorize(Policy = "stores.view")] public async Task GetById(Guid id) { var result = await service.GetByIdAsync(id); return result is null ? NotFound() : Ok(result); } [HttpPost] [Authorize(Policy = "stores.create")] public async Task Create(CreateStoreRequest request, CancellationToken ct) { var result = await service.CreateAsync(request, ct); return CreatedAtAction(nameof(GetById), new { id = result.Id }, result); } [HttpPut("{id:guid}")] [Authorize(Policy = "stores.update")] public async Task Update(Guid id, UpdateStoreRequest request, CancellationToken ct) { var result = await service.UpdateAsync(id, request, ct); return result is null ? NotFound() : Ok(result); } [HttpDelete("{id:guid}")] [Authorize(Policy = "stores.delete")] public async Task Delete(Guid id, CancellationToken ct) { var deleted = await service.DeleteAsync(id, ct); return deleted ? NoContent() : NotFound(); } }