Add Swagger frontend

This commit is contained in:
code liturgy 2022-11-25 22:35:47 +00:00
parent 712478814e
commit 76732a0d63
16 changed files with 212 additions and 20 deletions

View File

@ -1,16 +1,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using CodeLiturgy.Data.Application.Users; using CodeLiturgy.Data.Application.Users;
using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
public class SiteEnvironment [MapFrom(new [] {typeof(SiteEnvironmentCreate)})]
public partial class SiteEnvironment
{ {
public string Id { get; set; } public string Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public ApplicationUser User { get; set; }
public string UserId { get; set; } public string UserId { get; set; }
public ApplicationUser User { get; set; }
public List<Site> Sites { get; set; } public List<Site> Sites { get; set; }
} }
} }

View File

@ -0,0 +1,13 @@
using System.Collections.Generic;
using CodeLiturgy.Data.Application.Users;
using MapTo;
namespace CodeLiturgy.Data.Application
{
[MapFrom(typeof(SiteEnvironment))]
public partial class SiteEnvironmentCreate
{
public string Name { get; set; }
public List<Site> Sites { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using CodeLiturgy.Data.Application.Users;
using MapTo;
namespace CodeLiturgy.Data.Application
{
[MapFrom(typeof(SiteEnvironment))]
public partial class SiteEnvironmentUnique
{
public string Id { get; set; }
public string Name { get; set; }
public string UserId { get; set; }
public List<Site> Sites { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace CodeLiturgy.Startup.Application
{
public class SwaggerEnumSchemaFilter : ISchemaFilter
{
/// <summary>
/// Apply Swagger OpenApi schema
/// </summary>
/// <param name="model">OpenApiSchema model</param>
/// <param name="context">Schema filter context</param>
public void Apply(OpenApiSchema model, SchemaFilterContext context)
{
if (context.Type.IsEnum)
{
model.Enum.Clear();
Enum.GetNames(context.Type)
.ToList()
.ForEach(n => model.Enum.Add(new OpenApiString(n)));
}
}
}
}

View File

@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<PublishTrimmed>true</PublishTrimmed> <PublishTrimmed>true</PublishTrimmed>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -24,6 +25,10 @@
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.2-mauipre.1.22102.15" /> <PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.2-mauipre.1.22102.15" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.7" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.4.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-grid.css" /> <_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-grid.css" />

View File

@ -0,0 +1,63 @@
using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Domain;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace CodeLiturgy.Views.Controllers
{
[ApiController]
[Authorize]
public class EnvironmentController : ControllerBase
{
private ApplicationUserManager _userManager;
private ILogger<SitesController> _logger;
private readonly SiteDbContext _siteDbContext;
public EnvironmentController(ApplicationUserManager userManager, ILogger<SitesController> logger, SiteDbContext siteDbContext)
{
_logger = logger;
_userManager = userManager;
_siteDbContext = siteDbContext;
}
[HttpGet("/api/environments")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public ActionResult GetEnvironments(
int skip = 0, int take = 50, int orderDir = 1)
{
var (success, sites) = _siteDbContext.GetEnvironments(skip, take, orderDir);
if (!success) return new NotFoundResult();
return Ok(sites);
}
/// <summary>
/// Get Country by Id
/// </summary>
/// <param name="countryId">ISO 3166-1 countryId numeric code</param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("/api/environments/{environmentId}", Name = nameof(GetEnvironmentById))]
public ActionResult GetEnvironmentById(string siteId)
{
var (success, environment) = _siteDbContext.GetOneSiteById(siteId);
if (success)
{
return Ok(environment);
}
return new NotFoundResult();
}
}
}

View File

@ -47,6 +47,8 @@ namespace CodeLiturgy.Views.Controllers
/// <returns></returns> /// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("{siteId}", Name = nameof(GetSiteById))] [HttpGet("{siteId}", Name = nameof(GetSiteById))]
public ActionResult GetSiteById(string siteId) public ActionResult GetSiteById(string siteId)
{ {

View File

@ -14,6 +14,9 @@ namespace CodeLiturgy.Domain
public DbSet<Site> Sites { get; set; } public DbSet<Site> Sites { get; set; }
[EfGetOneBy(nameof(SiteEnvironment.Id), typeof(SiteEnvironmentUnique))]
[EfGetOne(typeof(SiteEnvironmentUnique))]
[EfGetMany(typeof(SiteEnvironmentUnique))]
public DbSet<SiteEnvironment> Environments { get; set; } public DbSet<SiteEnvironment> Environments { get; set; }
/// <summary> /// <summary>

View File

@ -1,8 +1,11 @@
using System.Globalization; using System.Globalization;
using System.Reflection;
using CodeLiturgy.Data.Auth; using CodeLiturgy.Data.Auth;
using CodeLiturgy.Startup.Application;
using CodeLiturgy.Views.Utils; using CodeLiturgy.Views.Utils;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Localization;
using Microsoft.OpenApi.Models;
namespace CodeLiturgy.Views; namespace CodeLiturgy.Views;
@ -42,6 +45,12 @@ public class Startup
builder.AddSimpleConsole(); builder.AddSimpleConsole();
}); });
if (_environment.IsDevelopment())
{
services.ConfigureSwagger();
}
services.AddControllersWithViews(x => x.EnableEndpointRouting = false); services.AddControllersWithViews(x => x.EnableEndpointRouting = false);
@ -59,13 +68,22 @@ public class Startup
{ {
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!env.IsDevelopment()) if (!_environment.IsDevelopment())
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.RoutePrefix = "swagger";
c.SwaggerEndpoint("/swagger/v1/swagger.json", "CodeLiturgy.Views v1");
});
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();

View File

@ -1,3 +1,4 @@
using System.Reflection;
using System.Text; using System.Text;
using BlueWest.Cryptography; using BlueWest.Cryptography;
using CodeLiturgy.Data.Application.Users; using CodeLiturgy.Data.Application.Users;
@ -5,19 +6,64 @@ using CodeLiturgy.Data.Auth;
using CodeLiturgy.Data.Auth.Context.Users; using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Domain; using CodeLiturgy.Domain;
using BlueWest.WebApi.Context.Users; using BlueWest.WebApi.Context.Users;
using CodeLiturgy.Startup.Application;
using CodeLiturgy.Views.Utils; using CodeLiturgy.Views.Utils;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
namespace CodeLiturgy.Views; namespace CodeLiturgy.Views;
public static class StartupExtensions public static class StartupExtensions
{ {
/*
private static MySqlServerVersion GetMySqlServerVersion(int major, int minor, int build) => public static IServiceCollection ConfigureSwagger(this IServiceCollection serviceCollection)
new(new Version(major, minor, build)); {
*/ return serviceCollection
.AddSwaggerGen(options =>
{
options.SchemaFilter<SwaggerEnumSchemaFilter>();
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "CodeLiturgy.Views.App",
Version = "v1"
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme (Example: 'Bearer 12345abcdef')",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
options.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
Array.Empty<string>()
}
});
});
}
private static string GetDbConnectionString(this IConfiguration configurationRoot, string key) private static string GetDbConnectionString(this IConfiguration configurationRoot, string key)
{ {

View File

@ -1 +1 @@
.no-environments-diplay.svelte-877bn7{text-align:center;height:100%;display:flex;width:100%;justify-content:center;align-items:center}.environment-manager-container.svelte-877bn7{width:100%;height:100%;display:flex;align-items:center;margin-left:25rem}.dropdown.svelte-1c41377.svelte-1c41377{position:relative;width:200px}.dropdown.svelte-1c41377 select.svelte-1c41377{width:100%}.dropdown.svelte-1c41377>.svelte-1c41377{box-sizing:border-box;height:1.5em}.dropdown.svelte-1c41377 input.svelte-1c41377{position:absolute;width:calc(100% - 20px)}.page-container.svelte-1pmz6nl{display:flex;min-width:100%;min-height:87vh}button.env-button.svelte-1pmz6nl{width:100%;background-color:#3a3a3a;border-radius:0;color:#fbfbfb;margin-bottom:15px!important}button.env-button.svelte-1pmz6nl:not(:last-child){margin-bottom:15px!important}.actions-menu.svelte-1pmz6nl{background:#152842;height:100%;padding:50rem 30rem 30rem;display:flex;flex-direction:column;align-items:center} .site-input.svelte-k7xnb2{font-size:inherit}.action-icon.svelte-k7xnb2{margin-left:10px;color:#fff}.site-domain.svelte-k7xnb2{cursor:pointer}.site-text.svelte-k7xnb2{margin:10px}.no-margin.svelte-k7xnb2{margin:0}.site-item.svelte-k7xnb2{padding-top:5px;color:var(--on-surface);padding-bottom:5px}.site-row.svelte-k7xnb2{display:flex;justify-content:flex-start;align-items:flex-start;background-color:#b8cde3;margin:0}.site-data.site-domain.svelte-k7xnb2{display:flex}.row.site-display.svelte-k7xnb2{margin:inherit;padding-top:10px;background:var(--background)}.form-title.svelte-14ayx1a{margin-bottom:20px}.site-container.svelte-14ayx1a{text-align:left;margin-top:60px}.new-site-button-section.svelte-14ayx1a{float:right;min-width:150px;text-align:end}.no-sites-display.svelte-14ayx1a{text-align:center;display:flex;justify-content:center;align-items:center;min-height:150px}.site-manager-container.svelte-14ayx1a{min-height:150px}.environment-item.svelte-vhp27k{background-color:var(--primary-container);padding:10px;border:1px solid transparent;border-radius:10px;margin-bottom:10px}.environment-manager-container.svelte-vfhf4x{display:flex;flex-direction:column;margin-top:20rem}.dropdown.svelte-1c41377.svelte-1c41377{position:relative;width:200px}.dropdown.svelte-1c41377 select.svelte-1c41377{width:100%}.dropdown.svelte-1c41377>.svelte-1c41377{box-sizing:border-box;height:1.5em}.dropdown.svelte-1c41377 input.svelte-1c41377{position:absolute;width:calc(100% - 20px)}.no-environments-diplay.svelte-r2bb58{text-align:center;height:100%;display:flex;width:100%;justify-content:center;align-items:center}.environments-container.svelte-r2bb58{width:100%;margin:30px}.modal-content.svelte-r2bb58{padding:5px;text-align:center}.page-container.svelte-r2bb58{display:flex;min-width:100%;min-height:87vh}button.env-button.svelte-r2bb58{width:100%;background-color:#3a3a3a;border-radius:0;color:#fbfbfb;margin-bottom:15px!important}button.env-button.svelte-r2bb58:not(:last-child){margin-bottom:15px!important}.actions-menu.svelte-r2bb58{background:#152842;height:100%;padding:50rem 30rem 0rem;display:flex;flex-direction:column;align-items:center}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -4,7 +4,7 @@
:root { :root {
--primary: rgb(53, 71, 100); --primary: rgb(53, 71, 100);
--on-primary: #FFFFFF; --on-primary: #FFFFFF;
--primary-container: #EADDFF; --primary-container: #6d9bdb38;
--on-primary-container: #21005E; --on-primary-container: #21005E;
--secondary: rgb(29, 54, 92); --secondary: rgb(29, 54, 92);
--on-secondary: #FFFFFF; --on-secondary: #FFFFFF;
@ -2710,19 +2710,18 @@ img.empty-state, video.empty-state {
position: fixed; position: fixed;
box-shadow: var(--shadow2); box-shadow: var(--shadow2);
color: var(--on-surface-variant); color: var(--on-surface-variant);
background-color: var(--surface-variant); background-color: var(--background);
padding: 16rem; padding: 16rem;
box-sizing: border-box; box-sizing: border-box;
z-index: 100; z-index: 100;
left: 20%; left: 5%;
right: 20%; right: 5%;
top: 5%; top: 5%;
min-width: 320rem; min-width: 90%;
max-width: 100%; max-width: 100%;
max-height: 100%; max-height: 100%;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
} }
.modal.border { .modal.border {