Created static object provider + added some properties
This commit is contained in:
@@ -22,8 +22,4 @@
|
||||
<None Include="README.md" Pack="true" PackagePath="\"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HopFrame.Web.Admin\HopFrame.Web.Admin.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using HopFrame.Web.Admin.Attributes;
|
||||
using HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
namespace HopFrame.Database.Models;
|
||||
|
||||
[AdminName("Groups")]
|
||||
[AdminDescription("On this page you can view, create, edit and delete permission groups.")]
|
||||
public class PermissionGroup : IPermissionOwner {
|
||||
|
||||
[Key, Required, MaxLength(50)]
|
||||
public string Name { get; init; }
|
||||
|
||||
[Required, DefaultValue(false), AdminUnsortable]
|
||||
[Required, DefaultValue(false)]
|
||||
public bool IsDefaultGroup { get; set; }
|
||||
|
||||
[MaxLength(500)]
|
||||
public string Description { get; set; }
|
||||
|
||||
[Required, AdminUneditable]
|
||||
[Required]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
[AdminIgnore(onlyForListing: true)]
|
||||
public virtual IList<Permission> Permissions { get; set; }
|
||||
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
using HopFrame.Web.Admin.Attributes;
|
||||
using HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
namespace HopFrame.Database.Models;
|
||||
|
||||
[AdminDescription("On this page you can manage all user accounts.")]
|
||||
public class User : IPermissionOwner {
|
||||
|
||||
[Key, Required, MinLength(36), MaxLength(36)]
|
||||
@@ -17,16 +14,15 @@ public class User : IPermissionOwner {
|
||||
[Required, MaxLength(50), EmailAddress]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Required, MinLength(8), MaxLength(255), JsonIgnore, AdminIgnore(onlyForListing: true), AdminHideValue]
|
||||
[Required, MinLength(8), MaxLength(255), JsonIgnore]
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required, AdminUneditable]
|
||||
[Required]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
[AdminIgnore(onlyForListing: true)]
|
||||
public virtual IList<Permission> Permissions { get; set; }
|
||||
|
||||
[JsonIgnore, AdminIgnore]
|
||||
[JsonIgnore]
|
||||
public virtual IList<Token> Tokens { get; set; }
|
||||
|
||||
}
|
||||
@@ -4,6 +4,6 @@ namespace HopFrame.Web.Admin;
|
||||
|
||||
public abstract class AdminPagesContext {
|
||||
|
||||
public abstract void OnModelCreating(IAdminContextGenerator generator);
|
||||
public virtual void OnModelCreating(IAdminContextGenerator generator) {}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
|
||||
public class AdminDescriptionAttribute(string description) : Attribute {
|
||||
public sealed class AdminDescriptionAttribute(string description) : Attribute {
|
||||
public string Description { get; set; } = description;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
|
||||
public class AdminNameAttribute(string name) : Attribute {
|
||||
public sealed class AdminNameAttribute(string name) : Attribute {
|
||||
public string Name { get; set; } = name;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Classes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class AdminButtonConfigAttribute(bool showCreateButton = true, bool showDeleteButton = true, bool showUpdateButton = true) : Attribute {
|
||||
public sealed class AdminButtonConfigAttribute(bool showCreateButton = true, bool showDeleteButton = true, bool showUpdateButton = true) : Attribute {
|
||||
public bool ShowCreateButton { get; set; } = showCreateButton;
|
||||
public bool ShowDeleteButton { get; set; } = showDeleteButton;
|
||||
public bool ShowUpdateButton { get; set; } = showUpdateButton;
|
||||
|
||||
@@ -3,6 +3,11 @@ using HopFrame.Web.Admin.Models;
|
||||
namespace HopFrame.Web.Admin.Attributes.Classes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class AdminPermissionsAttribute(AdminPagePermissions permissions) : Attribute {
|
||||
public AdminPagePermissions Permissions { get; set; } = permissions;
|
||||
public sealed class AdminPermissionsAttribute(string view = null, string create = null, string update = null, string delete = null) : Attribute {
|
||||
public AdminPagePermissions Permissions { get; set; } = new() {
|
||||
Create = create,
|
||||
Update = update,
|
||||
Delete = delete,
|
||||
View = view
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminBoldAttribute : Attribute;
|
||||
public sealed class AdminBoldAttribute : Attribute;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminHideValueAttribute : Attribute;
|
||||
public sealed class AdminHideValueAttribute : Attribute;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminIgnoreAttribute(bool onlyForListing = false) : Attribute {
|
||||
public sealed class AdminIgnoreAttribute(bool onlyForListing = false) : Attribute {
|
||||
public bool OnlyForListing { get; set; } = onlyForListing;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class AdminPrefixAttribute(string prefix) : Attribute {
|
||||
public string Prefix { get; set; } = prefix;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminUneditableAttribute : Attribute;
|
||||
public sealed class AdminUneditableAttribute : Attribute;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace HopFrame.Web.Admin.Attributes.Members;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AdminUnsortableAttribute : Attribute;
|
||||
public sealed class AdminUnsortableAttribute : Attribute;
|
||||
|
||||
@@ -7,8 +7,10 @@ public interface IAdminPropertyGenerator {
|
||||
IAdminPropertyGenerator DisplayValueWhileEditing(bool display);
|
||||
IAdminPropertyGenerator DisplayInListing(bool display = true);
|
||||
IAdminPropertyGenerator Bold(bool isBold = true);
|
||||
IAdminPropertyGenerator Ignore(bool ignore = true);
|
||||
|
||||
IAdminPropertyGenerator DisplayName(string displayName);
|
||||
IAdminPropertyGenerator Description(string description);
|
||||
IAdminPropertyGenerator Prefix(string prefix);
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Reflection;
|
||||
using HopFrame.Web.Admin.Attributes;
|
||||
using HopFrame.Web.Admin.Attributes.Classes;
|
||||
using HopFrame.Web.Admin.Models;
|
||||
using HopFrame.Web.Admin.Providers;
|
||||
|
||||
namespace HopFrame.Web.Admin.Generators.Implementation;
|
||||
|
||||
@@ -40,7 +41,7 @@ internal class AdminContextGenerator : IAdminContextGenerator {
|
||||
foreach (var property in properties) {
|
||||
var propertyType = property.PropertyType.GenericTypeArguments[0];
|
||||
var pageGeneratorType = typeof(AdminPageGenerator<>).MakeGenericType(propertyType);
|
||||
var generatorInstance = Activator.CreateInstance(pageGeneratorType, [propertyType.Name]);
|
||||
var generatorInstance = Activator.CreateInstance(pageGeneratorType, [property.Name]); // Calls constructor with title attribute
|
||||
|
||||
var populatorMethod = typeof(AdminContextGenerator)
|
||||
.GetMethod(nameof(ApplyConfigurationFromAttributes))?
|
||||
@@ -88,4 +89,15 @@ internal class AdminContextGenerator : IAdminContextGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterPages(AdminPagesContext context, IAdminPagesProvider provider) {
|
||||
var properties = context.GetType().GetProperties();
|
||||
|
||||
foreach (var property in properties) {
|
||||
var page = property.GetValue(context) as AdminPage;
|
||||
if (page is null) continue;
|
||||
|
||||
provider.RegisterAdminPage(page.Title.ToLower(), page);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,6 @@ internal sealed class AdminPageGenerator<TModel> : IAdminPageGenerator<TModel>,
|
||||
|
||||
foreach (var property in properties) {
|
||||
var attributes = property.GetCustomAttributes(false);
|
||||
var ignoreProperty = attributes
|
||||
.SingleOrDefault(a => a is AdminIgnoreAttribute) as AdminIgnoreAttribute;
|
||||
if (ignoreProperty?.OnlyForListing == false) continue;
|
||||
|
||||
var generator = Activator.CreateInstance(typeof(AdminPropertyGenerator), [property.Name, property.PropertyType]) as AdminPropertyGenerator;
|
||||
|
||||
@@ -139,8 +136,12 @@ internal sealed class AdminPageGenerator<TModel> : IAdminPageGenerator<TModel>,
|
||||
if (attributes.Any(a => a is AdminBoldAttribute))
|
||||
generator.Bold();
|
||||
|
||||
if (attributes.Any(a => a is AdminIgnoreAttribute))
|
||||
if (attributes.Any(a => a is AdminIgnoreAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminIgnoreAttribute) as AdminIgnoreAttribute;
|
||||
generator.DisplayInListing(false);
|
||||
generator.Sortable(false);
|
||||
generator.Ignore(attribute?.OnlyForListing == false);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminHideValueAttribute))
|
||||
generator.DisplayValueWhileEditing(false);
|
||||
@@ -154,6 +155,11 @@ internal sealed class AdminPageGenerator<TModel> : IAdminPageGenerator<TModel>,
|
||||
var attribute = attributes.Single(a => a is AdminDescriptionAttribute) as AdminDescriptionAttribute;
|
||||
generator.Description(attribute?.Description);
|
||||
}
|
||||
|
||||
if (attributes.Any(a => a is AdminPrefixAttribute)) {
|
||||
var attribute = attributes.Single(a => a is AdminPrefixAttribute) as AdminPrefixAttribute;
|
||||
generator.Prefix(attribute?.Prefix);
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyInfo GetPropertyInfo<TSource, TProperty>(Expression<Func<TSource, TProperty>> propertyLambda) {
|
||||
|
||||
@@ -26,6 +26,7 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
|
||||
|
||||
public IAdminPropertyGenerator DisplayInListing(bool display = true) {
|
||||
_property.DisplayInListing = display;
|
||||
_property.Sortable = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -34,6 +35,11 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Ignore(bool ignore = false) {
|
||||
_property.Ignore = ignore;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator DisplayName(string displayName) {
|
||||
_property.DisplayName = displayName;
|
||||
return this;
|
||||
@@ -44,6 +50,11 @@ internal sealed class AdminPropertyGenerator(string name, Type type) : IAdminPro
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAdminPropertyGenerator Prefix(string prefix) {
|
||||
_property.Prefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdminPageProperty Compile() {
|
||||
_property.DisplayName ??= _property.Name;
|
||||
|
||||
|
||||
@@ -3,11 +3,14 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace HopFrame.Web.Admin.Models;
|
||||
|
||||
public class AdminPage<TModel> : IAdminPageEntry {
|
||||
public sealed class AdminPage<TModel> : AdminPage;
|
||||
|
||||
public class AdminPage {
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public AdminPagePermissions Permissions { get; set; }
|
||||
public IList<AdminPageProperty> Properties { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public Type RepositoryProvider { get; set; }
|
||||
|
||||
@@ -18,5 +21,3 @@ public class AdminPage<TModel> : IAdminPageEntry {
|
||||
public bool ShowDeleteButton { get; set; } = true;
|
||||
public bool ShowUpdateButton { get; set; } = true;
|
||||
}
|
||||
|
||||
public interface IAdminPageEntry;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace HopFrame.Web.Admin.Models;
|
||||
|
||||
public class AdminPagePermissions {
|
||||
public sealed class AdminPagePermissions {
|
||||
public string View { get; set; }
|
||||
public string Create { get; set; }
|
||||
public string Update { get; set; }
|
||||
|
||||
@@ -2,16 +2,18 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace HopFrame.Web.Admin.Models;
|
||||
|
||||
public class AdminPageProperty {
|
||||
public sealed class AdminPageProperty {
|
||||
public string Name { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
|
||||
public bool DisplayInListing { get; set; } = true;
|
||||
public bool Sortable { get; set; } = true;
|
||||
public bool Editable { get; set; } = true;
|
||||
public bool EditDisplayValue { get; set; } = true;
|
||||
public bool Bold { get; set; }
|
||||
public bool Ignore { get; set; }
|
||||
[JsonIgnore]
|
||||
public Type Type { get; set; }
|
||||
}
|
||||
11
src/HopFrame.Web.Admin/Providers/IAdminPagesProvider.cs
Normal file
11
src/HopFrame.Web.Admin/Providers/IAdminPagesProvider.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web.Admin.Providers;
|
||||
|
||||
public interface IAdminPagesProvider {
|
||||
|
||||
internal void RegisterAdminPage(string url, AdminPage page);
|
||||
AdminPage LoadAdminPage(string url);
|
||||
IList<AdminPage> LoadRegisteredAdminPages();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web.Admin.Providers.Implementation;
|
||||
|
||||
public class AdminPagesProvider : IAdminPagesProvider {
|
||||
private readonly IDictionary<string, AdminPage> _pages = new Dictionary<string, AdminPage>();
|
||||
|
||||
public void RegisterAdminPage(string url, AdminPage page) {
|
||||
_pages.Add(url, page);
|
||||
}
|
||||
|
||||
public AdminPage LoadAdminPage(string url) {
|
||||
return _pages.TryGetValue(url, out var page) ? page : null;
|
||||
}
|
||||
|
||||
public IList<AdminPage> LoadRegisteredAdminPages() {
|
||||
return _pages.Values.ToList();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,29 @@
|
||||
using HopFrame.Web.Admin.Generators.Implementation;
|
||||
using HopFrame.Web.Admin.Providers;
|
||||
using HopFrame.Web.Admin.Providers.Implementation;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace HopFrame.Web.Admin;
|
||||
|
||||
public static class ServiceCollectionExtensions {
|
||||
|
||||
private static IAdminPagesProvider _provider;
|
||||
|
||||
public static IServiceCollection AddAdminContext<TContext>(this IServiceCollection services) where TContext : AdminPagesContext {
|
||||
services.AddSingleton(_ => {
|
||||
var provider = GetProvider();
|
||||
services.TryAddSingleton(provider);
|
||||
|
||||
var generator = new AdminContextGenerator();
|
||||
return generator.CompileContext<TContext>();
|
||||
});
|
||||
var context = generator.CompileContext<TContext>();
|
||||
AdminContextGenerator.RegisterPages(context, provider);
|
||||
services.AddSingleton(context);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IAdminPagesProvider GetProvider() {
|
||||
return _provider ??= new AdminPagesProvider();
|
||||
}
|
||||
|
||||
}
|
||||
55
src/HopFrame.Web/HopAdminContext.cs
Normal file
55
src/HopFrame.Web/HopAdminContext.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using HopFrame.Database.Models;
|
||||
using HopFrame.Security;
|
||||
using HopFrame.Web.Admin;
|
||||
using HopFrame.Web.Admin.Generators;
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace HopFrame.Web;
|
||||
|
||||
public class HopAdminContext : AdminPagesContext {
|
||||
|
||||
public AdminPage<User> Users { get; set; }
|
||||
public AdminPage<PermissionGroup> Groups { get; set; }
|
||||
|
||||
public override void OnModelCreating(IAdminContextGenerator generator) {
|
||||
generator.Page<User>()
|
||||
.Description("On this page you can manage all user accounts.")
|
||||
.ViewPermission(AdminPermissions.ViewUsers)
|
||||
.CreatePermission(AdminPermissions.AddUser)
|
||||
.UpdatePermission(AdminPermissions.EditUser)
|
||||
.DeletePermission(AdminPermissions.DeleteUser);
|
||||
|
||||
generator.Page<User>().Property(u => u.Password)
|
||||
.DisplayInListing(false)
|
||||
.DisplayValueWhileEditing(false);
|
||||
|
||||
generator.Page<User>().Property(u => u.CreatedAt)
|
||||
.Editable(false);
|
||||
|
||||
generator.Page<User>().Property(u => u.Permissions)
|
||||
.DisplayInListing(false);
|
||||
|
||||
generator.Page<User>().Property(u => u.Tokens)
|
||||
.Ignore();
|
||||
|
||||
|
||||
generator.Page<PermissionGroup>()
|
||||
.Description("On this page you can view, create, edit and delete permission groups.")
|
||||
.ViewPermission(AdminPermissions.ViewGroups)
|
||||
.CreatePermission(AdminPermissions.AddGroup)
|
||||
.UpdatePermission(AdminPermissions.EditGroup)
|
||||
.DeletePermission(AdminPermissions.DeleteGroup);
|
||||
|
||||
generator.Page<PermissionGroup>().Property(g => g.Name)
|
||||
.Prefix("group.");
|
||||
|
||||
generator.Page<PermissionGroup>().Property(g => g.IsDefaultGroup)
|
||||
.Sortable(false);
|
||||
|
||||
generator.Page<PermissionGroup>().Property(g => g.CreatedAt)
|
||||
.Editable(false);
|
||||
|
||||
generator.Page<PermissionGroup>().Property(g => g.Permissions)
|
||||
.DisplayInListing(false);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using BlazorStrap;
|
||||
using CurrieTechnologies.Razor.SweetAlert2;
|
||||
using HopFrame.Database;
|
||||
using HopFrame.Security.Authentication;
|
||||
using HopFrame.Web.Admin;
|
||||
using HopFrame.Web.Services;
|
||||
using HopFrame.Web.Services.Implementation;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@@ -15,6 +16,7 @@ public static class ServiceCollectionExtensions {
|
||||
services.AddHopFrameRepositories<TDbContext>();
|
||||
services.AddScoped<IAuthService, AuthService>();
|
||||
services.AddTransient<AuthMiddleware>();
|
||||
services.AddAdminContext<HopAdminContext>();
|
||||
|
||||
// Component library's
|
||||
services.AddSweetAlert2();
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
@page "/counter"
|
||||
@using System.Text.Json
|
||||
@using HopFrame.Web
|
||||
@using HopFrame.Web.Admin.Providers
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
@@ -9,12 +12,20 @@
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@inject IAdminPagesProvider Provider
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
private string[] permissions = ["web.counter"];
|
||||
|
||||
private void IncrementCount() {
|
||||
currentCount++;
|
||||
|
||||
string json = JsonSerializer.Serialize(Provider.LoadRegisteredAdminPages(), new JsonSerializerOptions {
|
||||
WriteIndented = true
|
||||
});
|
||||
|
||||
Console.WriteLine(json);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using HopFrame.Database.Models;
|
||||
using HopFrame.Web.Admin;
|
||||
using HopFrame.Web.Admin.Generators;
|
||||
using HopFrame.Web.Admin.Models;
|
||||
|
||||
namespace RestApiTest;
|
||||
|
||||
public class AdminContext : AdminPagesContext {
|
||||
|
||||
public AdminPage<User> Users { get; set; }
|
||||
public AdminPage<PermissionGroup> Groups { get; set; }
|
||||
|
||||
public override void OnModelCreating(IAdminContextGenerator generator) {
|
||||
|
||||
/*generator.Page<User>()
|
||||
.Title("Users")
|
||||
.Description("On this page you can manage all user accounts.")
|
||||
.UpdatePermission("update")
|
||||
.ViewPermission("view")
|
||||
.DeletePermission("delete")
|
||||
.CreatePermission("create")
|
||||
.DefaultSort(u => u.Id, ListSortDirection.Descending);*/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace RestApiTest.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("test")]
|
||||
public class TestController(ITokenContext userContext, DatabaseContext context, AdminContext adminContext) : ControllerBase {
|
||||
public class TestController(ITokenContext userContext, DatabaseContext context) : ControllerBase {
|
||||
|
||||
[HttpGet("permissions"), Authorized]
|
||||
public ActionResult<IList<Permission>> Permissions() {
|
||||
@@ -51,9 +51,4 @@ public class TestController(ITokenContext userContext, DatabaseContext context,
|
||||
return LogicResult<IList<Address>>.Ok(await context.Addresses.Include(e => e.Employee).ToListAsync());
|
||||
}
|
||||
|
||||
[HttpGet("adminContext")]
|
||||
public ActionResult<AdminContext> GetAdminContext() {
|
||||
return LogicResult<AdminContext>.Ok(adminContext);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using RestApiTest;
|
||||
using HopFrame.Api.Extensions;
|
||||
using HopFrame.Web.Admin;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -14,7 +13,6 @@ builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddDbContext<DatabaseContext>();
|
||||
builder.Services.AddAdminContext<AdminContext>();
|
||||
|
||||
builder.Services.AddSwaggerGen(c => {
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
|
||||
|
||||
Reference in New Issue
Block a user