Files
mixtape/zero.Core/Routing/Entities/Route.cs
T

79 lines
1.8 KiB
C#
Raw Normal View History

2021-10-06 14:55:50 +02:00
using System;
using System.Collections.Generic;
2020-10-12 12:00:30 +02:00
using zero.Core.Attributes;
using zero.Core.Entities;
namespace zero.Core.Routing
{
[Collection("Routes")]
2021-05-04 17:23:52 +02:00
public class Route : ZeroIdEntity
2020-10-12 12:00:30 +02:00
{
2021-10-05 15:50:12 +02:00
public Route() { }
public Route(string providerAlias)
{
ProviderAlias = providerAlias;
}
2021-10-06 14:55:50 +02:00
public Route(string id, string url, string providerAlias)
{
Id = id;
Url = url;
ProviderAlias = providerAlias;
}
2021-11-05 13:46:07 +01:00
/// <summary>
/// Id of the referenced entity
/// </summary>
public string ReferenceId { get; set; }
2021-05-04 17:23:52 +02:00
/// <summary>
/// Generated URL based on the URL provider
/// </summary>
2020-10-12 12:00:30 +02:00
public string Url { get; set; }
2021-05-04 17:23:52 +02:00
/// <summary>
/// Alias of the URL provider which generated this route
/// </summary>
2020-10-21 14:11:58 +02:00
public string ProviderAlias { get; set; }
2021-05-04 17:23:52 +02:00
/// <summary>
/// Enable this property so all routes are catched which start with this Url
/// </summary>
2020-10-21 14:11:58 +02:00
public bool AllowSuffix { get; set; }
2021-05-04 17:23:52 +02:00
/// <summary>
/// Additional parameters
/// </summary>
public Dictionary<string, object> Params { get; set; } = new();
2020-10-12 12:00:30 +02:00
2021-05-04 17:23:52 +02:00
/// <summary>
/// Route dependencies can be used for cache busting
/// </summary>
public List<string> Dependencies { get; set; } = new();
2020-10-12 12:00:30 +02:00
2021-11-08 15:49:36 +01:00
/// <summary>
/// Update an existing route with regenerated data
/// </summary>
public virtual Route Update(Route newRoute)
2020-10-12 12:00:30 +02:00
{
2021-11-08 15:49:36 +01:00
ReferenceId = newRoute.ReferenceId;
Url = newRoute.Url;
AllowSuffix = newRoute.AllowSuffix;
Params = newRoute.Params;
Dependencies = newRoute.Dependencies;
return this;
}
/// <summary>
/// Create a new route
/// </summary>
public static Route Create(string id, string providerAlias)
{
return new(providerAlias) { Id = id };
2020-10-12 12:00:30 +02:00
}
}
}