From 77a49ff49b97325108bec3e52f2ff71821857691 Mon Sep 17 00:00:00 2001 From: shept Date: Wed, 16 Apr 2025 21:54:48 +0500 Subject: [PATCH] created SurveyController for tests --- .../Controllers/SurveyController.cs | 46 +++++++++++++++++++ .../Controllers/TestController.cs | 13 ------ 2 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 SurveyBackend/SurveyBackend.API/Controllers/SurveyController.cs diff --git a/SurveyBackend/SurveyBackend.API/Controllers/SurveyController.cs b/SurveyBackend/SurveyBackend.API/Controllers/SurveyController.cs new file mode 100644 index 0000000..6209e8c --- /dev/null +++ b/SurveyBackend/SurveyBackend.API/Controllers/SurveyController.cs @@ -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 Get() + { + var result = await _surveyService.GetSurveysAsync(); + return Ok(result); + } + + [HttpGet("{id}")] + public async Task Get(int id) + { + var result = await _surveyService.GetSurveyAsync(id); + return result is not null ? Ok(result) : NotFound(); + } + + [HttpPost] + public async Task Post([FromBody] Survey survey) + { + await _surveyService.AddSurveyAsync(survey); + return Ok(); + } + + [HttpDelete("{id}")] + public async Task Delete(int id) + { + await _surveyService.DeleteSurveyAsync(id); + return Ok(); + } +} \ No newline at end of file diff --git a/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs b/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs index 0056728..2860970 100644 --- a/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs +++ b/SurveyBackend/SurveyBackend.API/Controllers/TestController.cs @@ -7,17 +7,4 @@ namespace SurveyBackend.Controllers; [Route("test")] public class TestController : ControllerBase { - private readonly ISurveyService _surveyService; - - public TestController(ISurveyService surveyService) - { - _surveyService = surveyService; - } - - [HttpGet] - public async Task Get() - { - var result = await _surveyService.GetSurveysAsync(); - return Ok(result); - } } \ No newline at end of file