From 81efaedbc24388e5ff05bb7c8db517d6313394c4 Mon Sep 17 00:00:00 2001 From: Chris Chen Date: Thu, 28 May 2026 16:34:18 -0700 Subject: [PATCH] feat(giving): add giving-categories controller --- .../Controllers/GivingCategoriesController.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 API/ROLAC.API/Controllers/GivingCategoriesController.cs 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(); } + } +}