using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using eprintServer.Services; using eprintServer.Requests.FormElementOption; using System; using System.Threading.Tasks; namespace eprintServer.Controllers; [ApiController] [Route("api/admin/[controller]")] [Authorize(Roles = "ADMIN,SUB_ADMIN")] public class FormElementOptionController : ControllerBase { private readonly FormElementOptionService _service; public FormElementOptionController(FormElementOptionService service) { _service = service; } [HttpPost] public async Task Create([FromBody] CreateFormElementOptionRequest request) { try { var option = await _service.CreateOptionAsync(request); return Ok(option); } catch (Exception ex) { return BadRequest(new { message = ex.Message }); } } // NEW: BULK CREATE OPTIONS [HttpPost("bulk")] public async Task CreateBulk([FromBody] CreateFormElementOptionsRequest request) { try { var options = await _service.CreateOptionsAsync(request); return Ok(options); } catch (Exception ex) { return BadRequest(new { message = ex.Message }); } } [HttpPut("{id}")] public async Task Update(long id, [FromBody] UpdateFormElementOptionRequest request) { try { var option = await _service.UpdateOptionAsync(id, request); return Ok(option); } catch (Exception ex) { return BadRequest(new { message = ex.Message }); } } [HttpGet("{id}")] [AllowAnonymous] public async Task GetById(long id) { try { var option = await _service.GetOptionByIdAsync(id); return Ok(option); } catch (Exception ex) { return NotFound(new { message = ex.Message }); } } [HttpGet("element/{formElementId}")] [AllowAnonymous] public async Task GetByFormElement(long formElementId) { var options = await _service.GetOptionsByFormElementIdAsync(formElementId); return Ok(options); } [HttpDelete("{id}")] public async Task Delete(long id) { var result = await _service.DeleteOptionAsync(id); if (!result) return NotFound(new { message = "Option not found" }); return Ok(new { message = "Option deleted successfully" }); } }