integrate swagger

This commit is contained in:
Adam R Grey 2024-06-02 18:37:04 -04:00
parent 2f7bc2c0ea
commit c6ea3ef790
3 changed files with 51 additions and 0 deletions

View File

@ -13,6 +13,7 @@ builder.Services.Configure<RazorViewEngineOptions>(o => {
o.ViewLocationFormats.Add("/WebInterface/Views/{1}/{0}" + RazorViewEngine.ViewExtension); o.ViewLocationFormats.Add("/WebInterface/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
o.ViewLocationFormats.Add("/WebInterface/Views/Shared/{0}" + RazorViewEngine.ViewExtension); o.ViewLocationFormats.Add("/WebInterface/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
}); });
builder.Services.AddSwaggerGen();
var app = builder.Build(); var app = builder.Build();
@ -29,5 +30,11 @@ app.MapControllerRoute(
name: "default", name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Sample API");
});
app.Run(); app.Run();

View File

@ -0,0 +1,41 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using vassago.Models;
namespace vassago.Controllers;
[Route("[controller]")]
[ApiController]
public class EmployeeController : ControllerBase
{
[HttpGet]
[Produces("application/json")]
public IEnumerable<Account> Get()
{
return GetEmployeesDeatils();
}
[HttpGet("{id}")]
[Produces("application/json")]
public Account Get(Guid id)
{
return GetEmployeesDeatils().Find(e => e.Id == id);
}
[HttpPost]
[Produces("application/json")]
public Account Post([FromBody] Account employee)
{
// Write logic to insert employee data
return new Account();
}
private List<Account> GetEmployeesDeatils()
{
return new List<Account>()
{
new Account()
};
}
}

View File

@ -19,6 +19,9 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="QRCoder" Version="1.4.2" /> <PackageReference Include="QRCoder" Version="1.4.2" />
<PackageReference Include="RestSharp" Version="110.2.0" /> <PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.6.2" />
<PackageReference Include="TwitchLib" Version="3.5.3" /> <PackageReference Include="TwitchLib" Version="3.5.3" />
<PackageReference Include="youtubedlsharp" Version="0.3.1" /> <PackageReference Include="youtubedlsharp" Version="0.3.1" />
</ItemGroup> </ItemGroup>