Added policy validation, ordering and virtual listing properties
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace HopFrame.Core.Services;
|
||||
|
||||
public interface IContextExplorer {
|
||||
public IEnumerable<string> GetTableNames();
|
||||
public IEnumerable<TableConfig> GetTables();
|
||||
public TableConfig? GetTable(string tableDisplayName);
|
||||
public TableConfig? GetTable(Type tableEntity);
|
||||
public ITableManager? GetTableManager(string tablePropertyName);
|
||||
|
||||
@@ -12,5 +12,5 @@ public interface ITableManager {
|
||||
public Task AddItem(object item);
|
||||
public Task RevertChanges(object item);
|
||||
|
||||
public string DisplayProperty(object? item, PropertyInfo info, TableConfig? tableConfig);
|
||||
public string DisplayProperty(object? item, PropertyConfig prop, TableConfig? tableConfig);
|
||||
}
|
||||
@@ -5,11 +5,11 @@ using Microsoft.Extensions.Logging;
|
||||
namespace HopFrame.Core.Services.Implementations;
|
||||
|
||||
internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider provider, ILogger<ContextExplorer> logger) : IContextExplorer {
|
||||
public IEnumerable<string> GetTableNames() {
|
||||
public IEnumerable<TableConfig> GetTables() {
|
||||
foreach (var context in config.Contexts) {
|
||||
foreach (var table in context.Tables) {
|
||||
if (table.Ignored) continue;
|
||||
yield return table.DisplayName;
|
||||
yield return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider pr
|
||||
|
||||
foreach (var key in entity.GetForeignKeys()) {
|
||||
var propConfig = table.Properties
|
||||
.Where(prop => !prop.IsListingProperty)
|
||||
.SingleOrDefault(prop => prop.Info == key.DependentToPrincipal?.PropertyInfo);
|
||||
if (propConfig is null) continue;
|
||||
propConfig.IsRelation = true;
|
||||
@@ -67,6 +68,7 @@ internal sealed class ContextExplorer(HopFrameConfig config, IServiceProvider pr
|
||||
|
||||
foreach (var property in entity.GetProperties()) {
|
||||
var propConfig = table.Properties
|
||||
.Where(prop => !prop.IsListingProperty)
|
||||
.SingleOrDefault(prop => prop.Info == property.PropertyInfo);
|
||||
if (propConfig is null) continue;
|
||||
propConfig.IsRequired = !property.IsNullable;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace HopFrame.Core.Services.Implementations;
|
||||
|
||||
internal sealed class DefaultAuthHandler : IHopFrameAuthHandler {
|
||||
public Task<bool> IsAuthenticatedAsync(string? policy) {
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
public Task<string> GetCurrentUserDisplayNameAsync() {
|
||||
return Task.FromResult(string.Empty);
|
||||
}
|
||||
}
|
||||
@@ -67,10 +67,11 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
|
||||
return false;
|
||||
}
|
||||
|
||||
public string DisplayProperty(object? item, PropertyInfo info, TableConfig? tableConfig) {
|
||||
public string DisplayProperty(object? item, PropertyConfig prop, TableConfig? tableConfig) {
|
||||
if (item is null) return string.Empty;
|
||||
var prop = tableConfig?.Properties.Find(prop => prop.Info.Name == info.Name);
|
||||
if (prop is null) return item.ToString() ?? string.Empty;
|
||||
|
||||
if (prop.IsListingProperty)
|
||||
return prop.Formatter!.Invoke(item);
|
||||
|
||||
var propValue = prop.Info.GetValue(item);
|
||||
if (propValue is null)
|
||||
@@ -83,14 +84,17 @@ internal sealed class TableManager<TModel>(DbContext context, TableConfig config
|
||||
if (prop.DisplayedProperty is null) {
|
||||
var key = prop.Info.PropertyType
|
||||
.GetProperties()
|
||||
.Where(p => p.GetCustomAttributes(true).Any(a => a is KeyAttribute))
|
||||
.FirstOrDefault();
|
||||
.FirstOrDefault(p => p.GetCustomAttributes(true).Any(a => a is KeyAttribute));
|
||||
|
||||
return key?.GetValue(propValue)?.ToString() ?? propValue.ToString() ?? string.Empty;
|
||||
}
|
||||
|
||||
var innerConfig = explorer.GetTable(propValue.GetType());
|
||||
return DisplayProperty(propValue, prop.DisplayedProperty, innerConfig);
|
||||
var innerProp = innerConfig!.Properties
|
||||
.SingleOrDefault(p => p.Info == prop.DisplayedProperty && !p.IsListingProperty);
|
||||
|
||||
if (innerProp is null) return propValue.ToString() ?? string.Empty;
|
||||
return DisplayProperty(propValue, innerProp, innerConfig);
|
||||
}
|
||||
|
||||
private IQueryable<TModel> IncludeForgeinKeys(IQueryable<TModel> query) {
|
||||
|
||||
Reference in New Issue
Block a user