diff --git a/API/ROLAC.API/Controllers/GivingCategoriesController.cs b/API/ROLAC.API/Controllers/GivingCategoriesController.cs new file mode 100644 index 0000000..235492e --- /dev/null +++ b/API/ROLAC.API/Controllers/GivingCategoriesController.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using ROLAC.API.DTOs.Giving; +using ROLAC.API.Services; + +namespace ROLAC.API.Controllers; + +[ApiController] +[Route("api/giving-categories")] +[Authorize(Roles = "finance,super_admin")] +public class GivingCategoriesController : ControllerBase +{ + private readonly IGivingCategoryService _svc; + public GivingCategoriesController(IGivingCategoryService svc) => _svc = svc; + + [HttpGet] + public async Task GetAll([FromQuery] bool includeInactive = false) + => Ok(await _svc.GetAllAsync(includeInactive)); + + [HttpPost] + public async Task Create([FromBody] CreateGivingCategoryRequest request) + { + var id = await _svc.CreateAsync(request); + return CreatedAtAction(nameof(GetAll), new { id }, new { id }); + } + + [HttpPut("{id:int}")] + public async Task Update(int id, [FromBody] UpdateGivingCategoryRequest request) + { + try { await _svc.UpdateAsync(id, request); return NoContent(); } + catch (KeyNotFoundException) { return NotFound(); } + } + + [HttpDelete("{id:int}")] + public async Task Deactivate(int id) + { + try { await _svc.DeactivateAsync(id); return NoContent(); } + catch (KeyNotFoundException) { return NotFound(); } + } +}