add-api-project #29
@ -26,6 +26,11 @@ namespace Api.Controllers
|
|||||||
_tokenParameters = tokenParameters;
|
_tokenParameters = tokenParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère un jeton d'accès pour un utilisateur particulier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command"></param>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IActionResult> Login(LoginViewModel command)
|
public async Task<IActionResult> Login(LoginViewModel command)
|
||||||
|
|||||||
48
Apps/Api/Controllers/CommentsController.cs
Normal file
48
Apps/Api/Controllers/CommentsController.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -71,7 +71,7 @@ namespace Api
|
|||||||
o.Filters.Add(new AuthorizeFilter()); // Ou MapControllers().RequireAuthentication()
|
o.Filters.Add(new AuthorizeFilter()); // Ou MapControllers().RequireAuthentication()
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddSwaggerDocument(d =>
|
services.AddOpenApiDocument(d =>
|
||||||
{
|
{
|
||||||
// cf. https://github.com/RicoSuter/NSwag/wiki/AspNetCore-Middleware#enable-authentication-in-generator-and-swagger-ui
|
// cf. https://github.com/RicoSuter/NSwag/wiki/AspNetCore-Middleware#enable-authentication-in-generator-and-swagger-ui
|
||||||
|
|
||||||
@ -100,8 +100,6 @@ namespace Api
|
|||||||
{
|
{
|
||||||
od.Info.Title = "Hacker news like API in .Net";
|
od.Info.Title = "Hacker news like API in .Net";
|
||||||
};
|
};
|
||||||
|
|
||||||
d.SchemaType = NJsonSchema.SchemaType.OpenApi3;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"Accounts"
|
"Accounts"
|
||||||
],
|
],
|
||||||
|
"summary": "Récupère un jeton d'accès pour un utilisateur particulier.",
|
||||||
"operationId": "Accounts_Login",
|
"operationId": "Accounts_Login",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"x-name": "command",
|
"x-name": "command",
|
||||||
@ -39,6 +40,58 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/comments/{id}/upvote": {
|
||||||
|
"put": {
|
||||||
|
"tags": [
|
||||||
|
"Comments"
|
||||||
|
],
|
||||||
|
"summary": "Upvote un commentaire particulier.",
|
||||||
|
"operationId": "Comments_Upvote",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/comments/{id}/downvote": {
|
||||||
|
"put": {
|
||||||
|
"tags": [
|
||||||
|
"Comments"
|
||||||
|
],
|
||||||
|
"summary": "Downvote un commentaire particulier.",
|
||||||
|
"operationId": "Comments_Downvote",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/links": {
|
"/api/links": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user