api fixes
This commit is contained in:
@@ -1,41 +1,11 @@
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
using System.Reflection;
|
||||
using zero.Api.Controllers;
|
||||
using zero.Api.Filters;
|
||||
using zero.Api.Controllers;
|
||||
|
||||
namespace zero.Backoffice;
|
||||
|
||||
public class ZeroBackofficeControllerModelConvention : ZeroApiControllerModelConvention
|
||||
{
|
||||
readonly AttributeRouteModel AppAwareRouteModel;
|
||||
|
||||
readonly AttributeRouteModel AppUnawareRouteModel;
|
||||
|
||||
readonly Type BaseClass = typeof(ZeroBackofficeController);
|
||||
|
||||
readonly bool RuntimeIsAppAware = false;
|
||||
|
||||
|
||||
public ZeroBackofficeControllerModelConvention(string zeroPath, string backofficeApiPath = "backoffice", bool isAppAware = false) : base(zeroPath, backofficeApiPath, isAppAware)
|
||||
public ZeroBackofficeControllerModelConvention(string path, bool isAppAware = false) : base(path, isAppAware)
|
||||
{
|
||||
RuntimeIsAppAware = isAppAware;
|
||||
AppAwareRouteModel = BuildRouteModel(zeroPath, backofficeApiPath, true);
|
||||
AppUnawareRouteModel = BuildRouteModel(zeroPath, backofficeApiPath, false);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configure routing model for all backoffice controllers
|
||||
/// </summary>
|
||||
public override void Apply(ControllerModel controller)
|
||||
{
|
||||
bool hasAttributeRouteModels = controller.Selectors.Any(selector => selector.AttributeRouteModel != null);
|
||||
|
||||
if (controller.ControllerType.IsSubclassOf(BaseClass))
|
||||
{
|
||||
bool isAppAware = RuntimeIsAppAware && controller.ControllerType.GetCustomAttribute<ZeroSystemApiAttribute>() == null;
|
||||
|
||||
controller.Selectors[0].AttributeRouteModel = isAppAware ? AppAwareRouteModel : AppUnawareRouteModel;
|
||||
}
|
||||
BaseClassType = typeof(ZeroBackofficeController);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user