add needed routes in LinksController
This commit is contained in:
parent
5f389ae5f8
commit
1d5570c578
@ -18,9 +18,10 @@ namespace HN.Application
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommentLinkCommand(Guid linkId)
|
public CommentLinkCommand(Guid linkId, string content = null)
|
||||||
{
|
{
|
||||||
LinkId = linkId;
|
LinkId = linkId;
|
||||||
|
Content = content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,8 @@
|
|||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Api.Models;
|
||||||
using HN.Application;
|
using HN.Application;
|
||||||
|
using HN.Domain;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -18,7 +21,7 @@ namespace Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve all links already posted.
|
/// Récupère tous les liens postés.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[ProducesResponseType(typeof(LinkDto[]), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(LinkDto[]), StatusCodes.Status200OK)]
|
||||||
@ -29,7 +32,68 @@ namespace Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Post a new link.
|
/// Récupère um lien particulier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<ActionResult<LinkDto>> GetLinkById(Guid id)
|
||||||
|
{
|
||||||
|
return Ok(await _bus.Send(new GetLinkQuery(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upvote un lien 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 VoteForLinkCommand(id, VoteType.Up));
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Downvote un lien 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 VoteForLinkCommand(id, VoteType.Down));
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère les commentaires d'un lien particulier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{id}/comments")]
|
||||||
|
public async Task<ActionResult<CommentDto[]>> Comments(Guid id)
|
||||||
|
{
|
||||||
|
return Ok(await _bus.Send(new GetLinkCommentsQuery(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Poste un nouveau commentaire sur un lien.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="command"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("{id}/comments")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||||
|
public async Task<IActionResult> AddComment(Guid id, AddCommentViewModel command)
|
||||||
|
{
|
||||||
|
var commentId = await _bus.Send(new CommentLinkCommand(id, command.Content));
|
||||||
|
return CreatedAtAction("", "", new { id = commentId }, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Poste un nouveau lien.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command"></param>
|
/// <param name="command"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -38,7 +102,7 @@ namespace Api.Controllers
|
|||||||
{
|
{
|
||||||
var result = await _bus.Send(command);
|
var result = await _bus.Send(command);
|
||||||
|
|
||||||
return Created("blabla", result);
|
return CreatedAtAction(nameof(GetLinkById), new { id = result });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
10
Apps/Api/Models/AddCommentViewModel.cs
Normal file
10
Apps/Api/Models/AddCommentViewModel.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Api.Models
|
||||||
|
{
|
||||||
|
public sealed class AddCommentViewModel
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string Content { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,7 +11,7 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"Links"
|
"Links"
|
||||||
],
|
],
|
||||||
"summary": "Retrieve all links already posted.",
|
"summary": "Récupère tous les liens postés.",
|
||||||
"operationId": "Links_GetLinks",
|
"operationId": "Links_GetLinks",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@ -43,7 +43,7 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"Links"
|
"Links"
|
||||||
],
|
],
|
||||||
"summary": "Post a new link.",
|
"summary": "Poste un nouveau lien.",
|
||||||
"operationId": "Links_CreateLink",
|
"operationId": "Links_CreateLink",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"x-name": "command",
|
"x-name": "command",
|
||||||
@ -71,6 +71,163 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/api/links/{id}": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Links"
|
||||||
|
],
|
||||||
|
"summary": "Récupère um lien particulier.",
|
||||||
|
"operationId": "Links_GetLinkById",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/LinkDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/links/{id}/upvote": {
|
||||||
|
"put": {
|
||||||
|
"tags": [
|
||||||
|
"Links"
|
||||||
|
],
|
||||||
|
"summary": "Upvote un lien particulier.",
|
||||||
|
"operationId": "Links_Upvote",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/links/{id}/downvote": {
|
||||||
|
"put": {
|
||||||
|
"tags": [
|
||||||
|
"Links"
|
||||||
|
],
|
||||||
|
"summary": "Downvote un lien particulier.",
|
||||||
|
"operationId": "Links_Downvote",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/api/links/{id}/comments": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Links"
|
||||||
|
],
|
||||||
|
"summary": "Récupère les commentaires d'un lien particulier.",
|
||||||
|
"operationId": "Links_Comments",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/CommentDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Links"
|
||||||
|
],
|
||||||
|
"summary": "Poste un nouveau commentaire sur un lien.",
|
||||||
|
"operationId": "Links_AddComment",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"x-position": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestBody": {
|
||||||
|
"x-name": "command",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/AddCommentViewModel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": true,
|
||||||
|
"x-position": 2
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
@ -139,6 +296,45 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"CommentDto": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "guid"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"upVotes": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
},
|
||||||
|
"downVotes": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AddCommentViewModel": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"required": [
|
||||||
|
"content"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"content": {
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"AddLinkCommand": {
|
"AddLinkCommand": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user