created SurveyController for tests
This commit is contained in:
parent
720f041abf
commit
77a49ff49b
2 changed files with 46 additions and 13 deletions
|
|
@ -0,0 +1,46 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue