46 lines
No EOL
1.1 KiB
C#
46 lines
No EOL
1.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using SurveyLib.Core.Models;
|
|
using SurveyLib.Core.Services;
|
|
using SurveyLib.Infrastructure.EFCore.Services;
|
|
|
|
namespace SurveyBackend.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/surveys")]
|
|
public class SurveyController : ControllerBase
|
|
{
|
|
private readonly ISurveyService _surveyService;
|
|
|
|
public SurveyController(ISurveyService surveyService)
|
|
{
|
|
_surveyService = surveyService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var result = await _surveyService.GetSurveysAsync();
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<IActionResult> Get(int id)
|
|
{
|
|
var result = await _surveyService.GetSurveyAsync(id);
|
|
return result is not null ? Ok(result) : NotFound();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Post([FromBody] Survey survey)
|
|
{
|
|
await _surveyService.AddSurveyAsync(survey);
|
|
return Ok();
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task<IActionResult> Delete(int id)
|
|
{
|
|
await _surveyService.DeleteSurveyAsync(id);
|
|
return Ok();
|
|
}
|
|
} |