dev
Last change
on this file since ad079e5 was ad079e5, checked in by Стојков Марко <mst@…>, 3 years ago |
Vote answer endpoint
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | using FinkiChattery.Api.ApplicationServices.Authentication;
|
---|
2 | using FinkiChattery.Commands.Questioning;
|
---|
3 | using FinkiChattery.Common.Mediator.Interfaces;
|
---|
4 | using FinkiChattery.Contracts.Questioning;
|
---|
5 | using FinkiChattery.Persistence.Helpers;
|
---|
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}/answers/{answerUid:Guid}/[controller]")]
|
---|
16 | [ApiController]
|
---|
17 | public class VotesController : ControllerBase
|
---|
18 | {
|
---|
19 | public VotesController(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> VoteAnswer([FromRoute] Guid questionUid, [FromRoute] Guid answerUid, [FromBody] VoteAnswerRequest request)
|
---|
29 | {
|
---|
30 | VoteType voteType = request.VoteType == VoteTypeRequest.Upvote ? VoteType.Upvote : VoteType.Downvote;
|
---|
31 | var voteUid = await MediatorService.SendAsync(new VoteAnswerCommand(voteType, answerUid, questionUid));
|
---|
32 | return Ok(voteUid);
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.