1 | using FinkiChattery.Api.ApplicationServices.Authentication;
|
---|
2 | using FinkiChattery.Api.ApplicationServices.Questioning;
|
---|
3 | using FinkiChattery.Commands.Questioning;
|
---|
4 | using FinkiChattery.Common.Mediator.Interfaces;
|
---|
5 | using FinkiChattery.Contracts.Questioning;
|
---|
6 | using IdentityServer4.AccessTokenValidation;
|
---|
7 | using Microsoft.AspNetCore.Authorization;
|
---|
8 | using Microsoft.AspNetCore.Mvc;
|
---|
9 | using System;
|
---|
10 | using System.Threading.Tasks;
|
---|
11 |
|
---|
12 | namespace 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 | }
|
---|