197 lines
7.7 KiB
C#
197 lines
7.7 KiB
C#
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
using DamageAssesment.Api.SurveyResponses.Models;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace DamageAssesment.Api.SurveyResponses.Controllers
|
|
{
|
|
[Route("api")]
|
|
[ApiController]
|
|
public class SurveyResponsesController : ControllerBase
|
|
{
|
|
private readonly ISurveysResponse surveyResponseProvider;
|
|
|
|
public SurveyResponsesController(ISurveysResponse surveyResponseProvider)
|
|
{
|
|
this.surveyResponseProvider = surveyResponseProvider;
|
|
}
|
|
/// <summary>
|
|
/// GET request for retrieving survey responses.
|
|
/// </summary>
|
|
|
|
[HttpGet("SurveyResponses")]
|
|
public async Task<ActionResult> GetSurveyResponsesAsync()
|
|
{
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesAsync();
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.surveyResponses);
|
|
}
|
|
|
|
if (result.ErrorMessage == "No Data Found")
|
|
return NoContent();
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
}
|
|
/// <summary>
|
|
/// GET request for retrieving survey responses by survey ID.
|
|
/// </summary>
|
|
|
|
[HttpGet("SurveyResponses/{surveyId}")]
|
|
public async Task<ActionResult> GetSurveyResponsesAsync(int surveyId)
|
|
{
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAsync(surveyId);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponses);
|
|
}
|
|
return NoContent();
|
|
}
|
|
/// <summary>
|
|
/// GET request for retrieving survey responses by survey and location IDs.
|
|
/// </summary>
|
|
/// <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>
|
|
|
|
[HttpGet("Responses/{surveyId}/{locationId}")]
|
|
public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, string locationId)
|
|
{
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(surveyId, locationId);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponses);
|
|
}
|
|
|
|
return NoContent();
|
|
}
|
|
/// <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>
|
|
|
|
[HttpGet("ResponsesByAnswer/{surveyId}/{questionId}/{answer}")]
|
|
public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyId, int questionId, string answer)
|
|
{
|
|
var result = await surveyResponseProvider.GetResponsesByAnswerAsync(surveyId, questionId, answer);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponses);
|
|
}
|
|
|
|
return NoContent();
|
|
}
|
|
/// <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>
|
|
|
|
[HttpGet("AnswersByRegion/{surveyId}")]
|
|
public async Task<ActionResult> GetAnswersByRegionAsync(int surveyId)
|
|
{
|
|
var result = await this.surveyResponseProvider.GetAnswersByRegionAsync(surveyId);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.Answers);
|
|
}
|
|
return NoContent();
|
|
}
|
|
/// <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>
|
|
|
|
[HttpGet("AnswersByMaintenanceCenter/{surveyId}")]
|
|
public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyId)
|
|
{
|
|
var result = await this.surveyResponseProvider.GetSurveyResponsesByMaintenanceCenterAsync(surveyId);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponses);
|
|
}
|
|
return NoContent();
|
|
}
|
|
/// <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>
|
|
|
|
[HttpGet("SurveyResponse/{Id}")]
|
|
public async Task<ActionResult> GetSurveyResponseByIdAsync(int Id)
|
|
{
|
|
var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(Id);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponse);
|
|
}
|
|
return NoContent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// POST request for creating a new survey response.
|
|
/// </summary>
|
|
/// <param name="surveyResponse">The survey response object to be created.</param>
|
|
|
|
[HttpPost("SurveyResponses")]
|
|
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);
|
|
}
|
|
/// <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>
|
|
|
|
[HttpPut("SurveyResponses/{Id}")]
|
|
public async Task<ActionResult> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse)
|
|
{
|
|
var result = await this.surveyResponseProvider.PutSurveyResponseAsync(Id, surveyResponse);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponse);
|
|
}
|
|
if (result.ErrorMessage == "Not Found")
|
|
return NotFound(result.ErrorMessage);
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
}
|
|
/// <summary>
|
|
/// DELETE request for deleting an existing survey response.
|
|
/// </summary>
|
|
|
|
[HttpDelete("SurveyResponses/{Id}")]
|
|
public async Task<ActionResult> DeleteSurveyResponseAsync(int Id)
|
|
{
|
|
var result = await this.surveyResponseProvider.DeleteSurveyResponseAsync(Id);
|
|
if (result.IsSuccess)
|
|
{
|
|
return Ok(result.SurveyResponse);
|
|
}
|
|
return NotFound();
|
|
}
|
|
/// <summary>
|
|
/// POST request for submitting survey with multiple answers.
|
|
/// </summary>
|
|
/// <param name="request">The answers to be submitted for the survey.</param>
|
|
|
|
[HttpPost("SurveyResponses/Answers")]
|
|
public async Task<ActionResult> PostSurveyAnswersAsync(Request request)
|
|
{
|
|
var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request);
|
|
|
|
if (result.IsSuccess)
|
|
return Ok(result.SurveyResponse);
|
|
else
|
|
return BadRequest(result.ErrorMessage);
|
|
}
|
|
}
|
|
}
|