using Microsoft.AspNetCore.Mvc; using SurveyBackend.DTOs.Survey; 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] CreateSurveyDTO dto) { var survey = new Survey { Title = dto.Title, Description = dto.Description, }; await _surveyService.AddSurveyAsync(survey); return Ok(); } [HttpDelete("{id}")] public async Task Delete(int id) { await _surveyService.DeleteSurveyAsync(id); return Ok(); } }