using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SurveyBackend.Contexts; using SurveyBackend.Core.Contexts; using SurveyBackend.DTOs.Completion; using SurveyBackend.Mappers; using SurveyLib.Core.Models; using SurveyLib.Core.Services; namespace SurveyBackend.Controllers; [ApiController] [Route("api/surveys/{surveyId:int}/completions")] public class CompletionController : ControllerBase { private readonly ICompletionService _completionService; private readonly IUserContext _userContext; public CompletionController(ICompletionService completionService, IUserContext userContext) { _completionService = completionService; _userContext = userContext; } [HttpGet] [Authorize] public async Task GetCompletionsAsync(int surveyId) { return NotFound(); } [HttpGet("{id:int}")] [Authorize] public async Task GetCompletionAsync(int id) { return NotFound(); } [HttpPost] [AllowAnonymous] public async Task PostCompletionAsync([FromBody] CompletionCreateDto dto, [FromRoute] int surveyId) { var userId = _userContext.NullableUserId; var model = CompletionMapper.CreateDtoToModel(dto, surveyId, userId); await _completionService.AddCompletionAsync(model); return Ok(); } }