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