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

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

Set correct answer for question by question owner

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