From b5a15dd9f22e9e96c12c87773c0d7b714be34e6e Mon Sep 17 00:00:00 2001 From: Chris Chen Date: Thu, 28 May 2026 16:54:24 -0700 Subject: [PATCH] feat(giving): add offering-sessions controller --- .../Controllers/OfferingSessionsController.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 API/ROLAC.API/Controllers/OfferingSessionsController.cs diff --git a/API/ROLAC.API/Controllers/OfferingSessionsController.cs b/API/ROLAC.API/Controllers/OfferingSessionsController.cs new file mode 100644 index 0000000..b17b556 --- /dev/null +++ b/API/ROLAC.API/Controllers/OfferingSessionsController.cs @@ -0,0 +1,59 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using ROLAC.API.DTOs.Giving; +using ROLAC.API.Services; + +namespace ROLAC.API.Controllers; + +[ApiController] +[Route("api/offering-sessions")] +[Authorize(Roles = "finance,super_admin")] +public class OfferingSessionsController : ControllerBase +{ + private readonly IOfferingSessionService _svc; + public OfferingSessionsController(IOfferingSessionService svc) => _svc = svc; + + [HttpGet] + public async Task GetPaged( + [FromQuery] int page = 1, [FromQuery] int pageSize = 20, + [FromQuery] DateOnly? from = null, [FromQuery] DateOnly? to = null) + => Ok(await _svc.GetPagedAsync(page, pageSize, from, to)); + + [HttpGet("check-date")] + public async Task CheckDate([FromQuery] DateOnly date) + => Ok(new { exists = await _svc.DateExistsAsync(date) }); + + [HttpGet("{id:int}")] + public async Task GetById(int id) + { + var dto = await _svc.GetByIdAsync(id); + return dto is null ? NotFound() : Ok(dto); + } + + [HttpPost] + public async Task Create([FromBody] CreateOfferingSessionRequest request) + { + try + { + var id = await _svc.CreateAsync(request); + return CreatedAtAction(nameof(GetById), new { id }, new { id }); + } + catch (InvalidOperationException ex) { return Conflict(new { message = ex.Message }); } + } + + [HttpPost("{id:int}/reopen")] + public async Task Reopen(int id) + { + try { await _svc.ReopenAsync(id); return NoContent(); } + catch (KeyNotFoundException) { return NotFound(); } + catch (InvalidOperationException ex) { return Conflict(new { message = ex.Message }); } + } + + [HttpPut("{id:int}")] + public async Task Replace(int id, [FromBody] CreateOfferingSessionRequest request) + { + try { await _svc.ReplaceAsync(id, request); return NoContent(); } + catch (KeyNotFoundException) { return NotFound(); } + catch (InvalidOperationException ex) { return Conflict(new { message = ex.Message }); } + } +}