using Microsoft.AspNetCore.Mvc; using vendorApproverBackend.Responses; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using System.Security.Claims; using vendorApproverBackend.Services; using vendorApproverBackend.Entities; [ApiController] [Route("api/[controller]")] public class ClarificationController : ControllerBase { private readonly RenewClarificationService _service; private readonly UserService _userService; public ClarificationController(RenewClarificationService service, UserService userService) { _service = service; _userService = userService; } [HttpPost("add/{renewId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task AddClarification(long renewId, [FromBody] string message) { var username = User.FindFirstValue(ClaimTypes.Name); var currentUser = await _userService.FindByUsernameAsync(username); if (currentUser == null) return Unauthorized(); var result = await _service.AddClarificationAsync(renewId, message, currentUser.Id); return Ok(result); } [HttpGet("all-renew-paginated/{renewId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task>> GetClarificationsPaginated( long renewId, [FromQuery] int page = 0, [FromQuery] int size = 5) { try { var result = await _service.GetClarificationsPaginatedAsync(page, size, renewId); return Ok(result); } catch (Exception ex) { return StatusCode(500, $"Internal server error: {ex.Message}"); } } [HttpGet("all-renew-clarification-list/{renewId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task GetByRenewId(long renewId) { var result = await _service.GetClarificationsListByRenewIdAsync(renewId); return Ok(result); } [HttpPut("update/{id}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task UpdateClarification(long id, [FromBody] string message) { var result = await _service.UpdateClarificationAsync(id, message); if (result == null) return NotFound(); return Ok(result); } // ====== PQ REQUEST CLARIFICATIONS ====== [HttpPost("add-pq/{pqId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task AddPqClarification(long pqId, [FromBody] string message) { var username = User.FindFirstValue(ClaimTypes.Name); var currentUser = await _userService.FindByUsernameAsync(username); if (currentUser == null) return Unauthorized(); var result = await _service.AddPqClarificationAsync(pqId, message, currentUser.Id); return Ok(result); } [HttpGet("all-pq-clarification-list/{pqId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task GetByPqId(long pqId) { var result = await _service.GetClarificationsListByPqIdAsync(pqId); return Ok(result); } // ====== VENDOR LETTER CLARIFICATIONS ====== [HttpPost("add-letter/{letterId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task AddLetterClarification(long letterId, [FromBody] string message) { var username = User.FindFirstValue(ClaimTypes.Name); var currentUser = await _userService.FindByUsernameAsync(username); if (currentUser == null) return Unauthorized(); var result = await _service.AddLetterClarificationAsync(letterId, message, currentUser.Id); return Ok(result); } [HttpGet("all-letter-clarification-list/{letterId}")] [Authorize(Roles = "ADMIN,EMPLOYEE,VENDOR,FINANCIAL")] public async Task GetByLetterId(long letterId) { var result = await _service.GetClarificationsListByLetterIdAsync(letterId); return Ok(result); } }