2023-08-15 22:52:30 -05:00
|
|
|
|
using DamageAssesment.Api.Surveys.Interfaces;
|
2023-08-18 14:30:34 -05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace DamageAssesment.Api.Surveys.Controllers
|
|
|
|
|
{
|
2023-08-25 07:55:11 -05:00
|
|
|
|
[Route("api")]
|
2023-08-15 22:52:30 -05:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class SurveysController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private ISurveyProvider surveyProvider;
|
|
|
|
|
|
|
|
|
|
public SurveysController(ISurveyProvider surveyProvider)
|
|
|
|
|
{
|
|
|
|
|
this.surveyProvider = surveyProvider;
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving surveys.
|
|
|
|
|
/// </summary>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-08-25 07:55:11 -05:00
|
|
|
|
|
|
|
|
|
[Route("Surveys")]
|
|
|
|
|
[Route("{Language}/Surveys")]
|
2023-08-15 22:52:30 -05:00
|
|
|
|
[HttpGet]
|
2023-08-25 07:55:11 -05:00
|
|
|
|
public async Task<ActionResult> GetSurveysAsync(string? Language)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-08-25 07:55:11 -05:00
|
|
|
|
var result = await this.surveyProvider.GetSurveysAsync(Language);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Surveys);
|
|
|
|
|
}
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
2023-08-25 08:17:53 -05:00
|
|
|
|
<<<<<<< HEAD
|
2023-08-18 14:30:34 -05:00
|
|
|
|
|
2023-08-25 07:55:11 -05:00
|
|
|
|
[Route("Surveys/{Id}")]
|
|
|
|
|
[Route("{Language}/Surveys/{Id}")]
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult> GetSurveysAsync(int Id, string? Language)
|
2023-08-25 08:17:53 -05:00
|
|
|
|
=======
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// GET request for retrieving surveys by ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2023-08-15 22:52:30 -05:00
|
|
|
|
[HttpGet("{Id}")]
|
|
|
|
|
public async Task<ActionResult> GetSurveysAsync(int Id)
|
2023-08-25 08:17:53 -05:00
|
|
|
|
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-08-25 07:55:11 -05:00
|
|
|
|
var result = await this.surveyProvider.GetSurveysAsync(Id, Language);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Surveys);
|
|
|
|
|
}
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// POST request for creating a new survey.
|
|
|
|
|
/// </summary>
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-08-25 07:55:11 -05:00
|
|
|
|
[HttpPost("Surveys")]
|
2023-08-15 22:52:30 -05:00
|
|
|
|
public async Task<ActionResult> PostSurveysAsync(Models.Survey survey)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.surveyProvider.PostSurveyAsync(survey);
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Survey);
|
|
|
|
|
}
|
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
|
|
|
}
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// PUT request for updating an existing survey (surveyId,Updated Survey data).
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-08-25 07:55:11 -05:00
|
|
|
|
[HttpPut("Surveys/{Id}")]
|
2023-08-15 22:52:30 -05:00
|
|
|
|
public async Task<ActionResult> PutSurveysAsync(int Id, Models.Survey survey)
|
|
|
|
|
{
|
2023-08-25 07:55:11 -05:00
|
|
|
|
var result = await this.surveyProvider.PutSurveyAsync(Id, survey);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Survey);
|
|
|
|
|
}
|
|
|
|
|
if (result.ErrorMessage == "Not Found")
|
|
|
|
|
return NotFound(result.ErrorMessage);
|
2023-08-25 07:55:11 -05:00
|
|
|
|
|
2023-08-15 22:52:30 -05:00
|
|
|
|
return BadRequest(result.ErrorMessage);
|
|
|
|
|
}
|
2023-08-25 08:17:53 -05:00
|
|
|
|
<<<<<<< HEAD
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-08-25 07:55:11 -05:00
|
|
|
|
[HttpDelete("Surveys/{Id}")]
|
2023-08-25 08:17:53 -05:00
|
|
|
|
=======
|
2023-08-24 20:25:38 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// DELETE request for deleting a survey by ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2023-08-15 22:52:30 -05:00
|
|
|
|
[HttpDelete("{Id}")]
|
2023-08-25 08:17:53 -05:00
|
|
|
|
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
2023-08-15 22:52:30 -05:00
|
|
|
|
public async Task<ActionResult> DeleteSurveysAsync(int Id)
|
|
|
|
|
{
|
|
|
|
|
var result = await this.surveyProvider.DeleteSurveyAsync(Id);
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
return Ok(result.Survey);
|
|
|
|
|
}
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|