diff --git a/zero.Api/Abstractions/PickerProvider.cs b/zero.Api/Abstractions/PickerProvider.cs deleted file mode 100644 index b87667c0..00000000 --- a/zero.Api/Abstractions/PickerProvider.cs +++ /dev/null @@ -1,108 +0,0 @@ -namespace zero.Api.Abstractions; - -public class PickerProvider : IPickerProvider where T : ZeroIdEntity, new() -{ - protected IStoreOperations Operations { get; set; } - - - public PickerProvider(IStoreOperations operations) - { - Operations = operations; - } - - - /// - public virtual async Task> GetPreviews(IEnumerable ids) - { - Dictionary result = await Operations.Load(ids); - return result.Select(x => - { - if (x.Value == null) - { - return GenerateNotFoundPreview(x.Key); - } - return ConvertToPreview(x.Value); - }).ToList(); - } - - - /// - public virtual async Task> PickFrom(int pageNumber, int pageSize = 50, ListQuery query = default) - { - Paged result = await Operations.Load(pageNumber, pageSize, q => q.Filter(query)); - return result.MapTo(ConvertToModel); - } - - - /// - /// Converts a source item to picker model which is output in the list picker - /// - protected virtual PickerModel ConvertToModel(T source) - { - PickerModel model = new() { Id = source.Id }; - - if (source is ZeroEntity) - { - model.Name = (source as ZeroEntity).Name; - model.IsActive = (source as ZeroEntity).IsActive; - } - - return model; - } - - - /// - /// Converts a source item to picker model which is output in the list picker. - /// Renders an error when the source is null. - /// - protected virtual PickerPreviewModel ConvertToPreview(T source) - { - PickerPreviewModel model = new() - { - Id = source.Id, - Icon = "fth-box" - }; - - if (source is ZeroEntity) - { - model.Name = (source as ZeroEntity).Name; - } - else - { - model.Name = "[object #" + source.Id + "]"; - } - - return model; - } - - - /// - /// Generates a preview which displays a not-found error - /// - protected virtual PickerPreviewModel GenerateNotFoundPreview(string id) - { - return new() - { - //HasError = true, - Icon = "fth-alert-circle color-red", - Id = id, - Name = "@errors.preview.notfound", - Text = "@errors.preview.notfound_text" - }; - } -} - - -public interface IPickerProvider where T : ZeroIdEntity, new() -{ - /// - /// Get previews which are displayed in the editor field - /// - Task> GetPreviews(IEnumerable ids); - - /// - /// Items to choose from when the picker is open. - /// The picker supports paging as well as filters. - /// - Task> PickFrom(int pageNumber, int pageSize = 50, ListQuery query = null); -} \ No newline at end of file diff --git a/zero.Api/Abstractions/ZeroApiController.cs b/zero.Api/Abstractions/ZeroApiController.cs index 47ca1424..44ef10d3 100644 --- a/zero.Api/Abstractions/ZeroApiController.cs +++ b/zero.Api/Abstractions/ZeroApiController.cs @@ -1,12 +1,11 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using zero.Api.Filters; namespace zero.Api.Abstractions; [ApiController] [ZeroAuthorize] -[DisableBrowserCache] +[DisableBrowserCacheFilter] [ApiMetadataFilter] [ApiResponseFilter] //[ServiceFilter(typeof(ModelStateValidationFilterAttribute))] diff --git a/zero.Api/Attributes/ZeroSystemApiAttribute.cs b/zero.Api/Attributes/ZeroSystemApiAttribute.cs new file mode 100644 index 00000000..cac98491 --- /dev/null +++ b/zero.Api/Attributes/ZeroSystemApiAttribute.cs @@ -0,0 +1,4 @@ +namespace zero.Api.Attributes; + +[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] +public class ZeroSystemApiAttribute : Attribute { } \ No newline at end of file diff --git a/zero.Api/Configuration/ApiConstants.cs b/zero.Api/Configuration/Constants.cs similarity index 100% rename from zero.Api/Configuration/ApiConstants.cs rename to zero.Api/Configuration/Constants.cs diff --git a/zero.Api/Filters/ActionFilters/ApiMetadataFilter.cs b/zero.Api/Filters/ApiMetadataFilter.cs similarity index 100% rename from zero.Api/Filters/ActionFilters/ApiMetadataFilter.cs rename to zero.Api/Filters/ApiMetadataFilter.cs diff --git a/zero.Api/Filters/ResultFilters/ApiResponseFilter.cs b/zero.Api/Filters/ApiResponseFilter.cs similarity index 100% rename from zero.Api/Filters/ResultFilters/ApiResponseFilter.cs rename to zero.Api/Filters/ApiResponseFilter.cs diff --git a/zero.Api/Filters/BackofficeFilterAttribute.cs b/zero.Api/Filters/BackofficeFilterAttribute.cs deleted file mode 100644 index 370701ad..00000000 --- a/zero.Api/Filters/BackofficeFilterAttribute.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Mvc.Filters; - -namespace zero.Api.Controllers; - -public class BackofficeFilterAttribute : IActionFilter -{ - const string SCOPE_KEY = "scope"; - - - public void OnActionExecuting(ActionExecutingContext context) - { - Type type = context.Controller.GetType(); - - if (typeof(ZeroApiController).IsAssignableFrom(type)) - { - if (context.HttpContext.Request.Query.TryGetValue(SCOPE_KEY, out var scope)) - { - //(context.Controller as ZeroBackofficeController).OnScopeChanged(scope.ToString()); - } - } - } - - public void OnActionExecuted(ActionExecutedContext context) - { - } -} \ No newline at end of file diff --git a/zero.Api/Filters/BackofficeJsonSerlializerSettings.cs b/zero.Api/Filters/BackofficeJsonSerlializerSettings.cs deleted file mode 100644 index 7fd6eb17..00000000 --- a/zero.Api/Filters/BackofficeJsonSerlializerSettings.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; - -namespace zero.Api; - -internal class BackofficeJsonSerlializerSettings : JsonSerializerSettings -{ - public BackofficeJsonSerlializerSettings() - { - Setup(this); - } - - - public static void Setup(JsonSerializerSettings settings) - { - settings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy())); - //settings.Converters.Add(new RefJsonConverter()); - //settings.ContractResolver = new ZeroJsonContractResolver(); - settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; - settings.TypeNameHandling = TypeNameHandling.Objects; - //settings.SerializationBinder = new ZeroInterfaceBinder(); - } -} \ No newline at end of file diff --git a/zero.Api/Filters/CanEditAttribute.cs b/zero.Api/Filters/CanEditAttribute.cs deleted file mode 100644 index 02173ec2..00000000 --- a/zero.Api/Filters/CanEditAttribute.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace zero.Api.Controllers; - -public class CanEditAttribute : TypeFilterAttribute -{ - public CanEditAttribute() : base(typeof(CanEditAttributeImpl)) { } - - - private class CanEditAttributeImpl : IAsyncResultFilter - { - //IToken token; - - - public CanEditAttributeImpl()//IToken token) - { - //this.token = token; - } - - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) - { - if (context.Result is JsonResult) - { - JsonResult result = context.Result as JsonResult; - - //if (result.Value is ObsoleteEditModel) - //{ - // ObsoleteEditModel model = result.Value as ObsoleteEditModel; - - // model.CanEdit = true; // TODO query authorize attrs to get permissions - //} - } - - await next(); - } - } -} \ No newline at end of file diff --git a/zero.Api/Filters/DisableBrowserCacheFilterAttribute.cs b/zero.Api/Filters/DisableBrowserCacheFilter.cs similarity index 92% rename from zero.Api/Filters/DisableBrowserCacheFilterAttribute.cs rename to zero.Api/Filters/DisableBrowserCacheFilter.cs index 206e8793..59d640f8 100644 --- a/zero.Api/Filters/DisableBrowserCacheFilterAttribute.cs +++ b/zero.Api/Filters/DisableBrowserCacheFilter.cs @@ -7,7 +7,7 @@ namespace zero.Api.Controllers; /// /// Ensures that the request is not cached by the browser /// -public class DisableBrowserCacheAttribute : ActionFilterAttribute +public class DisableBrowserCacheFilterAttribute : ActionFilterAttribute { public override void OnResultExecuting(ResultExecutingContext context) { diff --git a/zero.Api/Filters/ModelStateValidationFilterAttribute.cs b/zero.Api/Filters/ModelStateValidationFilterAttribute.cs deleted file mode 100644 index 210fb1f5..00000000 --- a/zero.Api/Filters/ModelStateValidationFilterAttribute.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; - -namespace zero.Api.Controllers; - -public class ModelStateValidationFilterAttribute : IActionFilter -{ - public void OnActionExecuting(ActionExecutingContext context) - { - if (!context.ModelState.IsValid) - { - context.Result = new BadRequestObjectResult(context.ModelState); - } - } - - public void OnActionExecuted(ActionExecutedContext context) - { - } -} \ No newline at end of file diff --git a/zero.Api/Filters/VerifyTokenAttribute.cs b/zero.Api/Filters/VerifyTokenAttribute.cs deleted file mode 100644 index ff18ac1c..00000000 --- a/zero.Api/Filters/VerifyTokenAttribute.cs +++ /dev/null @@ -1,56 +0,0 @@ -//using Microsoft.AspNetCore.Mvc; -//using Microsoft.AspNetCore.Mvc.Filters; -//using System; -//using System.Threading.Tasks; -//using zero.Core.Api; -//using zero.Web.Models; - -//namespace zero.Web.Controllers -//{ -// public class VerifyTokenAttribute : TypeFilterAttribute -// { -// public VerifyTokenAttribute(string key = "model") : base(typeof(VerifyTokenAttributeImpl)) -// { -// Arguments = new object[] { key }; -// } - - -// private class VerifyTokenAttributeImpl : IAsyncActionFilter -// { -// IToken token; -// string key; - - -// public VerifyTokenAttributeImpl(IToken token, string key) -// { -// this.token = token; -// this.key = key; -// } - - -// public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) -// { -// if (context.ActionArguments.ContainsKey(key)) -// { -// object argument = context.ActionArguments[key]; - -// if (argument is ObsoleteEditModel) -// { -// ObsoleteEditModel model = (argument as ObsoleteEditModel); -// string tokenId = model.Meta?.Token; - -// bool isVerified = await token.Verify(model.Id, tokenId); - -// if (!isVerified) -// { -// context.Result = new StatusCodeResult(409); -// return; -// } -// } -// } - -// await next(); -// } -// } -// } -//} diff --git a/zero.Api/Filters/ZeroBackofficeAttribute.cs b/zero.Api/Filters/ZeroBackofficeAttribute.cs deleted file mode 100644 index a7e4e9bd..00000000 --- a/zero.Api/Filters/ZeroBackofficeAttribute.cs +++ /dev/null @@ -1,60 +0,0 @@ -//using Microsoft.AspNetCore.Mvc; -//using Microsoft.AspNetCore.Mvc.Filters; -//using System; -//using System.Threading.Tasks; -//using zero.Core.Api; -//using zero.Core.Entities; -//using zero.Web.Models; - -//namespace zero.Web.Controllers -//{ -// public class ZeroBackofficeAttribute : TypeFilterAttribute -// { -// public bool IsTyped { get; set; } - - -// public ZeroBackofficeAttribute(bool isTyped = true) : base(typeof(ZeroBackofficeAttributeImpl)) -// { -// IsTyped = isTyped; -// } - - - -// private class ZeroBackofficeAttributeImpl : IAsyncResultFilter -// { -// IToken token; - - -// public ZeroBackofficeAttributeImpl(IToken token) -// { -// this.token = token; -// } - -// public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) -// { -// JsonResult result = context.Result as JsonResult; - -// if (result != null) -// { -// ZeroEntity model = result.Value as ZeroEntity; - -// if (model != null) -// { -// Type type = result.Value.GetType(); - -// EditModel editModel = new EditModel() -// { -// Entity = result.Value, -// Token = await token.Get(model), -// IsAppAware = typeof(IAppAwareEntity).IsAssignableFrom(type), -// CanBeShared = typeof(IAppAwareShareableEntity).IsAssignableFrom(type), -// CanDelete = false, // TODO -// }; -// } -// } - -// await next(); -// } -// } -// } -//} diff --git a/zero.Api/Filters/ZeroSystemApiAttribute.cs b/zero.Api/Filters/ZeroSystemApiAttribute.cs deleted file mode 100644 index e90da101..00000000 --- a/zero.Api/Filters/ZeroSystemApiAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace zero.Api.Filters; - -[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] -public class ZeroSystemApiAttribute : Attribute -{ - public ZeroSystemApiAttribute() : base() - { - - } -} \ No newline at end of file diff --git a/zero.Api/Usings.cs b/zero.Api/Usings.cs index 13a7eeaf..24620c38 100644 --- a/zero.Api/Usings.cs +++ b/zero.Api/Usings.cs @@ -30,5 +30,6 @@ global using zero.Api.Controllers; global using zero.Api.Models; global using zero.Api.Endpoints; global using zero.Api.Abstractions; +global using zero.Api.Attributes; global using zero.Api.Extensions; global using zero.Api.Filters; \ No newline at end of file diff --git a/zero.Backoffice/Abstractions/ZeroBackofficeController.cs b/zero.Backoffice/Abstractions/ZeroBackofficeController.cs index 41355928..9c577422 100644 --- a/zero.Backoffice/Abstractions/ZeroBackofficeController.cs +++ b/zero.Backoffice/Abstractions/ZeroBackofficeController.cs @@ -6,7 +6,7 @@ namespace zero.Backoffice.Abstractions; [ApiController] [ZeroAuthorize] -[DisableBrowserCache] +[DisableBrowserCacheFilter] //[ServiceFilter(typeof(ModelStateValidationFilterAttribute))] //[ServiceFilter(typeof(BackofficeFilterAttribute))] public abstract class ZeroBackofficeController : ControllerBase diff --git a/zero.Backoffice/Controllers/ZeroIndexController.cs b/zero.Backoffice/Controllers/ZeroIndexController.cs index 077b0a74..b61173e6 100644 --- a/zero.Backoffice/Controllers/ZeroIndexController.cs +++ b/zero.Backoffice/Controllers/ZeroIndexController.cs @@ -6,7 +6,7 @@ using zero.Backoffice.Services; namespace zero.Backoffice.Controllers; [ZeroAuthorize(false)] -[DisableBrowserCache] +[DisableBrowserCacheFilter] public class ZeroIndexController : Controller { IZeroVue ZeroVue { get; set; } diff --git a/zero.Api/Endpoints/Cultures/_todo_CulturesController.cs b/zero.Backoffice/Endpoints/_todo_CulturesController.cs similarity index 100% rename from zero.Api/Endpoints/Cultures/_todo_CulturesController.cs rename to zero.Backoffice/Endpoints/_todo_CulturesController.cs diff --git a/zero.Backoffice/Usings.cs b/zero.Backoffice/Usings.cs index 244aece1..90f9abd4 100644 --- a/zero.Backoffice/Usings.cs +++ b/zero.Backoffice/Usings.cs @@ -26,4 +26,6 @@ global using zero.Backoffice.Abstractions; global using zero.Backoffice.Configuration; global using zero.Backoffice.Controllers; global using zero.Backoffice.UIComposition; -global using zero.Backoffice.DevServer; \ No newline at end of file +global using zero.Backoffice.DevServer; + +global using zero.Api.Attributes; \ No newline at end of file diff --git a/zero.Core/Architecture/ZeroModuleCollection.cs b/zero.Core/Architecture/ZeroModuleCollection.cs index 8b3f1272..11145c16 100644 --- a/zero.Core/Architecture/ZeroModuleCollection.cs +++ b/zero.Core/Architecture/ZeroModuleCollection.cs @@ -48,7 +48,6 @@ public class ZeroModuleCollection : ZeroModule { foreach (var module in _modules.OrderBy(x => x.Value.Order)) { - Console.WriteLine(module.Key.ToString()); module.Value.ConfigureServices(services, configuration); } }