[846cf1a] | 1 | using FinkiChattery.Api.ApplicationServices.Authentication;
|
---|
[cbdbb49] | 2 | using FinkiChattery.Api.ApplicationServices.Questioning;
|
---|
[846cf1a] | 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 | {
|
---|
[cbdbb49] | 30 | var answer = await MediatorService.SendAsync(new AnswerQuestionCommand(questionUid, request.Text));
|
---|
| 31 | return Ok(answer.ToAnswerQuestionStateResponse());
|
---|
[846cf1a] | 32 | }
|
---|
[2a9d9d1] | 33 |
|
---|
[9df3069] | 34 | [HttpPut("{answerUid:Guid}")]
|
---|
| 35 | [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
|
---|
| 36 | public async Task<IActionResult> EditAnswer([FromRoute] Guid questionUid, [FromRoute] Guid answerUid, [FromBody] AnswerQuestionRequest request)
|
---|
| 37 | {
|
---|
| 38 | var answer = await MediatorService.SendAsync(new EditAnswerCommand(questionUid, answerUid, request.Text));
|
---|
| 39 | return Ok(answer.ToAnswerQuestionStateResponse());
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[2a9d9d1] | 42 | [HttpPut("{answerUid:Guid}/correct")]
|
---|
| 43 | [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
|
---|
| 44 | public async Task<IActionResult> MarkAnswerCorrect([FromRoute] Guid questionUid, [FromRoute] Guid answerUid)
|
---|
| 45 | {
|
---|
| 46 | await MediatorService.SendAsync(new MarkAnswerCorrectCommand(questionUid, answerUid));
|
---|
| 47 | return Ok(answerUid);
|
---|
| 48 | }
|
---|
[846cf1a] | 49 | }
|
---|
| 50 | }
|
---|