created SurveyController for tests

This commit is contained in:
Вячеслав 2025-04-16 21:54:48 +05:00
parent 720f041abf
commit 77a49ff49b
2 changed files with 46 additions and 13 deletions

View file

@ -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();
}
}

View file

@ -7,17 +7,4 @@ namespace SurveyBackend.Controllers;
[Route("test")] [Route("test")]
public class TestController : ControllerBase public class TestController : ControllerBase
{ {
private readonly ISurveyService _surveyService;
public TestController(ISurveyService surveyService)
{
_surveyService = surveyService;
}
[HttpGet]
public async Task<IActionResult> Get()
{
var result = await _surveyService.GetSurveysAsync();
return Ok(result);
}
} }