source: src/FinkiChattery/FinkiChattery.Api/Controllers/v1/AnswersController.cs@ 7e7cc4c

dev
Last change on this file since 7e7cc4c was cbdbb49, checked in by Стојков Марко <mst@…>, 3 years ago

Fixed response for answer question

  • Property mode set to 100644
File size: 1.8 KB
Line 
1using FinkiChattery.Api.ApplicationServices.Authentication;
2using FinkiChattery.Api.ApplicationServices.Questioning;
3using FinkiChattery.Commands.Questioning;
4using FinkiChattery.Common.Mediator.Interfaces;
5using FinkiChattery.Contracts.Questioning;
6using IdentityServer4.AccessTokenValidation;
7using Microsoft.AspNetCore.Authorization;
8using Microsoft.AspNetCore.Mvc;
9using System;
10using System.Threading.Tasks;
11
12namespace FinkiChattery.Api.Controllers.v1
13{
14 [ApiVersion(ApiVersions.ApiVersion1)]
15 [Route("api/v{version:apiVersion}/questions/{questionUid:Guid}/[controller]/")]
16 [ApiController]
17 public class AnswersController : ControllerBase
18 {
19 public AnswersController(IMediatorService mediatorService)
20 {
21 MediatorService = mediatorService;
22 }
23
24 public IMediatorService MediatorService { get; }
25
26 [HttpPost]
27 [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
28 public async Task<IActionResult> AnswerQuestion([FromRoute] Guid questionUid, [FromBody] AnswerQuestionRequest request)
29 {
30 var answer = await MediatorService.SendAsync(new AnswerQuestionCommand(questionUid, request.Text));
31 return Ok(answer.ToAnswerQuestionStateResponse());
32 }
33
34 [HttpPut("{answerUid:Guid}/correct")]
35 [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
36 public async Task<IActionResult> MarkAnswerCorrect([FromRoute] Guid questionUid, [FromRoute] Guid answerUid)
37 {
38 await MediatorService.SendAsync(new MarkAnswerCorrectCommand(questionUid, answerUid));
39 return Ok(answerUid);
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.