DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Controllers/SurveyResponsesController.cs
2023-08-15 23:52:30 -04:00

158 lines
5.5 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;
}
[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);
}
[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();
}
[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();
}
[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();
}
[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();
}
[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();
}
[HttpGet("SurveyResponse/{responseId}")]
public async Task<ActionResult> GetSurveyResponseByIdAsync(int responseId)
{
var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(responseId);
if (result.IsSuccess)
{
return Ok(result.SurveyResponse);
}
return NoContent();
}
[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);
}
[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);
}
[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();
}
[HttpPost("SurveyResponses/Answers")]
public async Task<ActionResult> PostSurveyAnswersAsync(AnswerRequest answers)
{
/* var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(surveyAnswers);
if (result.IsSuccess)
{
return Ok(result.SurveyResponse);
}
return BadRequest(result.ErrorMessage);*/
var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(answers);
if (result.IsSuccess)
return Ok(result.SurveyResponse);
else
return BadRequest(result.ErrorMessage);
}
}
}