include inactive resources for API; enum to strings in API

This commit is contained in:
2021-12-30 11:11:34 +01:00
parent 8f37744837
commit fbcc6dd9c2
5 changed files with 41 additions and 1 deletions
@@ -19,6 +19,7 @@ public class ZeroApiEntityStoreOperations<TModel, TStore>
{
Controller = controller;
Store = store;
Store.Config.IncludeInactive = true;
}
+15
View File
@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Text.Json;
namespace zero.Api;
public class ConfigureApiJsonOptions : IConfigureOptions<JsonOptions>
{
public void Configure(JsonOptions options)
{
// TODO this matches all serialization, not limited to API
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
}
}
+2
View File
@@ -26,6 +26,8 @@ public class ZeroApiPlugin : ZeroPlugin
services.AddTransient<IBackofficeApplicationResolverHandler, ApiApplicationResolverHandler>();
services.AddTransient<ApiUnhandledExceptionMiddleware>();
services.ConfigureOptions<ConfigureApiJsonOptions>();
ZeroModuleCollection modules = new();
modules.Add<Endpoints.Applications.ApplicationModule>();
@@ -71,6 +71,21 @@ public static class RavenQueryableExtensions
}
public static IQueryable<T> WhereIf<T>(this IQueryable<T> source, Expression<Func<T, bool>> predicate, bool condition, Expression<Func<T, bool>> elsePredicate = null)
{
if (!condition)
{
if (elsePredicate != null)
{
return source.Where(elsePredicate);
}
return source;
}
return source.Where(predicate);
}
public static IQueryable<T> SearchIf<T>(this IQueryable<T> source, Expression<Func<T, object>> fieldSelector, string searchTerms, string suffix = null, string prefix = null, SearchOperator @operator = SearchOperator.Or)
{
if (String.IsNullOrWhiteSpace(searchTerms))
+8 -1
View File
@@ -12,9 +12,11 @@ public abstract class EntityStore<T> : IEntityStore<T> where T : ZeroIdEntity, I
/// <inheritdoc />
public IZeroDocumentSession Session => Operations.Session;
/// <inheritdoc />
public StoreConfig Config => Operations.Config;
protected IZeroContext Context { get; private set; }
protected StoreConfig Config => Operations.Config;
protected IInterceptors Interceptors { get; private set; }
@@ -106,6 +108,11 @@ public interface IEntityStore<T> where T : ZeroIdEntity, ISupportsFlavors, ISupp
/// </summary>
IZeroDocumentSession Session { get; }
/// <summary>
/// Configure the store
/// </summary>
StoreConfig Config { get; }
/// <summary>
/// Get new instance of an entity (with an optional flavor)
/// </summary>