ajout documentation de l'api

This commit is contained in:
Julien LEICHER 2021-12-14 14:48:08 +01:00
parent 5ca2b509fe
commit 05d068e817
No known key found for this signature in database
GPG Key ID: BE0761B6A007EB96
8 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,56 @@
using HackerNet.Application;
using HackerNet.Infrastructure.AspNet.Filters;
using Microsoft.AspNetCore.Mvc;
namespace HackerNet.Api.Controllers;
[ApiController]
[Route("/api/links")]
public class LinksController : ControllerBase
{
private readonly LinkService _linkService;
public LinksController(LinkService linkService)
{
_linkService = linkService;
}
/// <summary>
/// Retourne les derniers liens publiés de la plateforme.
/// </summary>
/// <returns></returns>
[HttpGet]
public ActionResult<LinkHomePage[]> GetLinks()
{
return _linkService.GetPublishedLinks();
}
/// <summary>
/// Récupère un lien par son identifiant.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id:guid}")] // https://docs.microsoft.com/fr-fr/aspnet/core/fundamentals/routing?view=aspnetcore-6.0#route-constraint-reference
[CustomExceptionFilter]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<LinkHomePage> GetLinkDetail(Guid id)
{
return _linkService.GetLinkDetail(id);
}
/// <summary>
/// Publie un nouveau lien sur la plateforme
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status201Created)]
public ActionResult PublishLink(PublishLinkCommand cmd)
{
var id = _linkService.PublishLink(cmd);
return CreatedAtAction(nameof(GetLinkDetail), new { id = id }, null);
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<ProjectReference Include="..\..\HackerNet.Infrastructure\HackerNet.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NSwag.AspNetCore" Version="13.15.3" />
</ItemGroup>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,20 @@
using HackerNet.Infrastructure.AspNet;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHackerNetServices();
builder.Services.AddControllers();
builder.Services.AddOpenApiDocument(d =>
{
d.Title = "HackerNet API";
});
var app = builder.Build();
app.UseOpenApi();
app.UseSwaggerUi3();
app.MapGet("/", () => "Hello World!");
app.MapControllers();
app.Run();

View File

@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:35593",
"sslPort": 44377
}
},
"profiles": {
"HackerNet.Api": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7252;http://localhost:5230",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,17 @@
@url = https://localhost:7252
GET {{url}}/api/links
###
POST {{url}}/api/links
Content-Type: application/json
{
"url": "https://localhost:7252/api/links",
"description": "kfjkljfe"
}
###
GET {{url}}/api/links/7f92770b-e3ef-4443-ab5d-8aca6449530f

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{EB14E7E3-2
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HackerNet.Web", "Apps\HackerNet.Web\HackerNet.Web.csproj", "{7844261A-7074-4882-9507-B9B1F5A45921}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HackerNet.Api", "Apps\HackerNet.Api\HackerNet.Api.csproj", "{A3BFAAD5-9914-450E-8303-457B29F4990E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -38,8 +40,13 @@ Global
{7844261A-7074-4882-9507-B9B1F5A45921}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7844261A-7074-4882-9507-B9B1F5A45921}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7844261A-7074-4882-9507-B9B1F5A45921}.Release|Any CPU.Build.0 = Release|Any CPU
{A3BFAAD5-9914-450E-8303-457B29F4990E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3BFAAD5-9914-450E-8303-457B29F4990E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3BFAAD5-9914-450E-8303-457B29F4990E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3BFAAD5-9914-450E-8303-457B29F4990E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7844261A-7074-4882-9507-B9B1F5A45921} = {EB14E7E3-2556-4B17-8D81-18F322480B5C}
{A3BFAAD5-9914-450E-8303-457B29F4990E} = {EB14E7E3-2556-4B17-8D81-18F322480B5C}
EndGlobalSection
EndGlobal