69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using AyaNova.Models;
|
|
using AyaNova.Api.ControllerHelpers;
|
|
using AyaNova.Biz;
|
|
|
|
|
|
namespace AyaNova.Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[ApiVersion("8.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
public class FormFieldsDefinitionsController : ControllerBase
|
|
{
|
|
private readonly AyContext ct;
|
|
private readonly ILogger<FormFieldsDefinitionsController> log;
|
|
private readonly ApiServerState serverState;
|
|
|
|
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
/// <param name="dbcontext"></param>
|
|
/// <param name="logger"></param>
|
|
/// <param name="apiServerState"></param>
|
|
public FormFieldsDefinitionsController(AyContext dbcontext, ILogger<FormFieldsDefinitionsController> logger, ApiServerState apiServerState)
|
|
{
|
|
ct = dbcontext;
|
|
log = logger;
|
|
serverState = apiServerState;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get available fields for Form specified
|
|
/// Used at UI for customizing forms
|
|
/// </summary>
|
|
/// <param name="FormFieldDefinitionKey"></param>
|
|
/// <returns>List of form fields and their properties</returns>
|
|
[HttpGet("{FormFieldDefinitionKey}")]
|
|
public ActionResult GetFormFields([FromRoute] string FormFieldDefinitionKey)
|
|
{
|
|
if (!serverState.IsOpen)
|
|
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
|
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(new ApiErrorResponse(ModelState));
|
|
|
|
if (AyaFormFieldDefinitions.IsValidFormFieldDefinitionKey(FormFieldDefinitionKey))
|
|
{
|
|
return Ok(ApiOkResponse.Response(AyaFormFieldDefinitions.AyaFormFields(FormFieldDefinitionKey), true));
|
|
}
|
|
else
|
|
{
|
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}//eoc
|
|
}//ens |