ajout documentation de l'api
This commit is contained in:
parent
5ca2b509fe
commit
05d068e817
56
Apps/HackerNet.Api/Controllers/LinksController.cs
Normal file
56
Apps/HackerNet.Api/Controllers/LinksController.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Apps/HackerNet.Api/HackerNet.Api.csproj
Normal file
19
Apps/HackerNet.Api/HackerNet.Api.csproj
Normal 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>
|
||||||
20
Apps/HackerNet.Api/Program.cs
Normal file
20
Apps/HackerNet.Api/Program.cs
Normal 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();
|
||||||
28
Apps/HackerNet.Api/Properties/launchSettings.json
Normal file
28
Apps/HackerNet.Api/Properties/launchSettings.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Apps/HackerNet.Api/api.http
Normal file
17
Apps/HackerNet.Api/api.http
Normal 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
|
||||||
8
Apps/HackerNet.Api/appsettings.Development.json
Normal file
8
Apps/HackerNet.Api/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Apps/HackerNet.Api/appsettings.json
Normal file
9
Apps/HackerNet.Api/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apps", "Apps", "{EB14E7E3-2
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HackerNet.Web", "Apps\HackerNet.Web\HackerNet.Web.csproj", "{7844261A-7074-4882-9507-B9B1F5A45921}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HackerNet.Web", "Apps\HackerNet.Web\HackerNet.Web.csproj", "{7844261A-7074-4882-9507-B9B1F5A45921}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HackerNet.Api", "Apps\HackerNet.Api\HackerNet.Api.csproj", "{A3BFAAD5-9914-450E-8303-457B29F4990E}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{7844261A-7074-4882-9507-B9B1F5A45921}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{7844261A-7074-4882-9507-B9B1F5A45921} = {EB14E7E3-2556-4B17-8D81-18F322480B5C}
|
{7844261A-7074-4882-9507-B9B1F5A45921} = {EB14E7E3-2556-4B17-8D81-18F322480B5C}
|
||||||
|
{A3BFAAD5-9914-450E-8303-457B29F4990E} = {EB14E7E3-2556-4B17-8D81-18F322480B5C}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user