48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using HN.Application;
|
|
using HN.Domain;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public sealed class CommentsController : ControllerBase
|
|
{
|
|
private readonly IMediator _bus;
|
|
|
|
public CommentsController(IMediator bus)
|
|
{
|
|
_bus = bus;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upvote un commentaire particulier.
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("{id}/upvote")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
public async Task<IActionResult> Upvote(Guid id)
|
|
{
|
|
await _bus.Send(new VoteForCommentCommand(id, VoteType.Up));
|
|
return NoContent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Downvote un commentaire particulier.
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("{id}/downvote")]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
public async Task<IActionResult> Downvote(Guid id)
|
|
{
|
|
await _bus.Send(new VoteForCommentCommand(id, VoteType.Down));
|
|
return NoContent();
|
|
}
|
|
}
|
|
} |