using DamageAssesment.Api.Surveys.Interfaces; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace DamageAssesment.Api.Surveys.Controllers { [Route("api")] [ApiController] public class SurveysController : ControllerBase { private ISurveyProvider surveyProvider; public SurveysController(ISurveyProvider surveyProvider) { this.surveyProvider = surveyProvider; } [Route("Surveys")] [Route("{Language}/Surveys")] [HttpGet] public async Task GetSurveysAsync(string? Language) { var result = await this.surveyProvider.GetSurveysAsync(Language); if (result.IsSuccess) { return Ok(result.Surveys); } return NoContent(); } [Route("Surveys/{Id}")] [Route("{Language}/Surveys/{Id}")] [HttpGet] public async Task GetSurveysAsync(int Id, string? Language) { var result = await this.surveyProvider.GetSurveysAsync(Id, Language); if (result.IsSuccess) { return Ok(result.Surveys); } return NotFound(); } [HttpPost("Surveys")] public async Task PostSurveysAsync(Models.Survey survey) { var result = await this.surveyProvider.PostSurveyAsync(survey); if (result.IsSuccess) { return Ok(result.Survey); } return BadRequest(result.ErrorMessage); } [HttpPut("Surveys/{Id}")] public async Task PutSurveysAsync(int Id, Models.Survey survey) { var result = await this.surveyProvider.PutSurveyAsync(Id, survey); if (result.IsSuccess) { return Ok(result.Survey); } if (result.ErrorMessage == "Not Found") return NotFound(result.ErrorMessage); return BadRequest(result.ErrorMessage); } [HttpDelete("Surveys/{Id}")] public async Task DeleteSurveysAsync(int Id) { var result = await this.surveyProvider.DeleteSurveyAsync(Id); if (result.IsSuccess) { return Ok(result.Survey); } return NotFound(); } } }