Files
mixtape/zero.Backoffice/ZeroBackofficeControllerModelConvention.cs
T

29 lines
945 B
C#
Raw Normal View History

2021-12-13 14:28:25 +01:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using System.Text;
using zero.Api.Controllers;
2021-11-23 15:43:21 +01:00
2021-11-30 15:35:50 +01:00
namespace zero.Backoffice;
2021-11-23 15:43:21 +01:00
2021-12-03 14:45:49 +01:00
public class ZeroBackofficeControllerModelConvention : ZeroApiControllerModelConvention
2021-11-23 15:43:21 +01:00
{
2021-12-13 12:21:15 +01:00
public ZeroBackofficeControllerModelConvention(string path, bool isAppAware = false) : base(path, isAppAware)
2021-11-23 15:43:21 +01:00
{
2021-12-13 12:21:15 +01:00
BaseClassType = typeof(ZeroBackofficeController);
2021-11-23 15:43:21 +01:00
}
2021-12-13 14:28:25 +01:00
protected override AttributeRouteModel BuildRouteModel(string pathSegment, bool appAware = false)
{
StringBuilder path = new();
path.Append(pathSegment.EnsureSurroundedWith('/'));
path.Append("{zero_app_key}/");
// TODO add route constraint which only allows registered app-ids
// see https://nemi-chand.github.io/creating-custom-routing-constraint-in-aspnet-core-mvc/
path.Append("backoffice/[controller]");
return new AttributeRouteModel(new RouteAttribute(path.ToString()));
}
2021-11-23 15:43:21 +01:00
}