using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using eprintServer.Services; using eprintServer.Requests.FormElement; namespace eprintServer.Controllers; [ApiController] [Route("api/admin/[controller]")] [Authorize(Roles = "ADMIN,SUB_ADMIN")] public class FormElementController : ControllerBase { private readonly FormElementService _service; public FormElementController(FormElementService service) { _service = service; } [HttpPost] public async Task Create([FromBody] CreateFormElementRequest request) { try { var element = await _service.CreateFormElementAsync(request); return Ok(element); } catch (Exception ex) { return BadRequest(new { message = ex.Message }); } } // NEW: BULK CREATE FORM ELEMENTS [HttpPost("bulk")] public async Task CreateBulk([FromBody] CreateFormElementsRequest request) { try { var elements = await _service.CreateFormElementsAsync(request); return Ok(elements); } catch (Exception ex) { return BadRequest(new { message = ex.Message }); } } [HttpPut("{id}")] public async Task Update(long id, [FromBody] UpdateFormElementRequest request) { try { var element = await _service.UpdateFormElementAsync(id, request); return Ok(element); } catch (Exception ex) { return BadRequest(new { message = ex.Message }); } } [HttpGet("{id}")] [AllowAnonymous] public async Task GetById(long id) { try { var element = await _service.GetFormElementByIdAsync(id); return Ok(element); } catch (Exception ex) { return NotFound(new { message = ex.Message }); } } [HttpGet("step/{stepId}")] [AllowAnonymous] public async Task GetByStep(long stepId) { var elements = await _service.GetFormElementsByStepIdAsync(stepId); return Ok(elements); } [HttpDelete("{id}")] public async Task Delete(long id) { var result = await _service.DeleteFormElementAsync(id); if (!result) return NotFound(new { message = "FormElement not found" }); return Ok(new { message = "FormElement deleted successfully" }); } }