2023-10-04 17:45:51 -05:00
|
|
|
|
using DamageAssesment.Api.Responses.Interfaces;
|
|
|
|
|
using DamageAssesment.Api.Responses.Models;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
|
namespace DamageAssesment.Api.Responses.Controllers
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class SurveyResponsesController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ISurveysResponse surveyResponseProvider;
|
|
|
|
|
|
2023-11-01 10:35:20 -05:00
|
|
|
|
public SurveyResponsesController(ISurveysResponse surveyResponseProvider)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
this.surveyResponseProvider = surveyResponseProvider;
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving survey responses.
|
|
|
|
|
/// </summary>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/{employeeid:int}")]
|
|
|
|
|
[Route("responses")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult> GetSurveyResponsesAsync(int? employeeid)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-20 23:58:29 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesAsync(employeeid ?? 0);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.surveyResponses);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.ErrorMessage == "No Data Found")
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving survey responses by survey ID.
|
|
|
|
|
/// </summary>
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/bysurvey/{surveyid:int}/{employeeid:int}")]
|
|
|
|
|
[Route("responses/bysurvey/{surveyid:int}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult> GetSurveyResponsesAsync(int surveyid, int? employeeid)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-20 23:58:29 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAsync(surveyid, employeeid ?? 0);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponses);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving survey responses by survey and location IDs.
|
|
|
|
|
/// </summary>
|
2023-09-13 00:28:24 -05:00
|
|
|
|
/// <param name="surveyid">The ID of the survey for which responses are to be retrieved.</param>
|
|
|
|
|
/// <param name="locationid">The ID of the location for which responses are to be retrieved.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/{surveyid:int}/{locationid:int}/{employeeid:int}")]
|
|
|
|
|
[Route("responses/{surveyid:int}/{locationid:int}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
2023-11-01 10:35:20 -05:00
|
|
|
|
public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyid, int locationid,int? employeeid)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-11-01 10:35:20 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(surveyid, locationid,employeeid ?? 0);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponses);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving survey responses by survey, question, and answer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
|
|
|
|
|
/// <param name="questionId">The ID of the question for which responses are to be retrieved.</param>
|
|
|
|
|
/// <param name="answer">The answer for which responses are to be retrieved.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/byanswer/{surveyid:int}/{questionid:int}/{answer:alpha}/{employeeid:int}")]
|
|
|
|
|
[Route("responses/byanswer/{surveyid:int}/{questionid:int}/{answer:alpha}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyid, int questionid, string answer, int? employeeid)
|
|
|
|
|
{
|
|
|
|
|
var result = await surveyResponseProvider.GetResponsesByAnswerAsync(surveyid, questionid, answer, employeeid ?? 0);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponses);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving answers from survey responses by survey ID and region.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="surveyId">The ID of the survey for which answers are to be retrieved.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/byregion/{surveyid:int}")]
|
|
|
|
|
[Route("responses/byregion/{surveyid:int}/{employeeid}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult> GetAnswersByRegionAsync(int surveyid, int? employeeid)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-20 23:58:29 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.GetAnswersByRegionAsync(surveyid, employeeid ?? 0);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Answers);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving survey responses by survey ID and maintenance center.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/bymaintenancecenter/{surveyid:int}/{employeeid:int}")]
|
|
|
|
|
[Route("responses/bymaintenancecenter/{surveyid:int}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyid, int? employeeid)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-20 23:58:29 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesByMaintenanceCenterAsync(surveyid, employeeid ?? 0);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponses);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving a survey response by response ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="responseId">The ID of the survey response to be retrieved.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[HttpGet("responses/{id}")]
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public async Task<ActionResult> GetSurveyResponseByIdAsync(int id)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(id);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponse);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// POST request for creating a new survey response.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="surveyResponse">The survey response object to be created.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[HttpPost("responses")]
|
2023-08-15 22:52:30 -05:00
|
|
|
|
public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.surveyResponseProvider.PostSurveyResponseAsync(surveyResponse);
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponse);
|
|
|
|
|
}
|
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// PUT request for updating an existing survey response.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Id">The ID of the survey response to be updated.</param>
|
|
|
|
|
/// <param name="surveyResponse">The updated survey response object.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[HttpPut("responses/{id}")]
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public async Task<ActionResult> PutSurveyResponseAsync(int id, Models.SurveyResponse surveyResponse)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.PutSurveyResponseAsync(id, surveyResponse);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponse);
|
|
|
|
|
}
|
|
|
|
|
if (result.ErrorMessage == "Not Found")
|
|
|
|
|
return NotFound(result.ErrorMessage);
|
|
|
|
|
|
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// DELETE request for deleting an existing survey response.
|
|
|
|
|
/// </summary>
|
2023-09-20 23:58:29 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[HttpDelete("responses/{id}")]
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public async Task<ActionResult> DeleteSurveyResponseAsync(int id)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.DeleteSurveyResponseAsync(id);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.SurveyResponse);
|
|
|
|
|
}
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// POST request for submitting survey with multiple answers.
|
|
|
|
|
/// </summary>
|
2023-08-27 10:55:58 -05:00
|
|
|
|
/// <param name="request">The answers to be submitted for the survey.</param>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[HttpPost("responses/answers")]
|
2023-08-27 10:55:58 -05:00
|
|
|
|
public async Task<ActionResult> PostSurveyAnswersAsync(Request request)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-08-27 10:55:58 -05:00
|
|
|
|
var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
return Ok(result.SurveyResponse);
|
|
|
|
|
else
|
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
|
|
|
}
|
2023-11-01 10:35:20 -05:00
|
|
|
|
|
2023-10-16 13:13:20 -05:00
|
|
|
|
[Route("responses/surveys/active")]
|
|
|
|
|
[Route("responses/surveys/active/{language:alpha}")]
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/surveys/active/{employeeid:int}")]
|
|
|
|
|
[Route("responses/surveys/active/{employeeid:int}/{language:alpha}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
2023-10-16 13:13:20 -05:00
|
|
|
|
public async Task<ActionResult> GetActiveSurveysAsync(int? employeeid, string? language)
|
2023-09-20 23:58:29 -05:00
|
|
|
|
{
|
|
|
|
|
var result = await this.surveyResponseProvider.GetActiveSurveysAsync(employeeid, language);
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Surveys);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-16 13:13:20 -05:00
|
|
|
|
[Route("responses/surveys/historic")]
|
|
|
|
|
[Route("responses/surveys/historic/{language:alpha}")]
|
2023-10-04 10:55:35 -05:00
|
|
|
|
[Route("responses/surveys/historic/{employeeid:int}")]
|
|
|
|
|
[Route("responses/surveys/historic/{employeeid:int}/{language:alpha}")]
|
2023-09-20 23:58:29 -05:00
|
|
|
|
[HttpGet]
|
2023-10-16 13:13:20 -05:00
|
|
|
|
public async Task<ActionResult> GetHistoricSurveysAsync(int? employeeid, string? language)
|
2023-09-20 23:58:29 -05:00
|
|
|
|
{
|
|
|
|
|
var result = await this.surveyResponseProvider.GetHistoricSurveysAsync(employeeid, language);
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Surveys);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|