81 lines
2.5 KiB
C#
81 lines
2.5 KiB
C#
namespace Webzine.WebApplication.Extensions;
|
|
|
|
public static class RouteConfiguration
|
|
{
|
|
/// <summary>
|
|
/// Configure les routes de l'application.
|
|
/// </summary>
|
|
public static void MapCustomRoutes(this IEndpointRouteBuilder endpoints)
|
|
{
|
|
|
|
// ----------- RECHERCHE -----------
|
|
endpoints.MapControllerRoute(
|
|
name: "rechercheIndex",
|
|
pattern: "recherche",
|
|
defaults: new { controller = "Recherche", action = "Index" });
|
|
|
|
// ----------- ARTISTE -----------
|
|
// exemple : /artiste/boblechanteurtarpingénial
|
|
endpoints.MapControllerRoute(
|
|
name: "ArtisteIndex",
|
|
pattern: "artiste/{nom}",
|
|
defaults: new { controller = "Artiste", action = "Index" });
|
|
|
|
// ----------- TITRE -----------
|
|
// exemple : /titre/5
|
|
endpoints.MapControllerRoute(
|
|
name: "TitreDetails",
|
|
pattern: "titre/{id}",
|
|
defaults: new { controller = "Titre", action = "Details" });
|
|
|
|
// exemple : /titre/style/Rock
|
|
endpoints.MapControllerRoute(
|
|
name: "TitresParStyle",
|
|
pattern: "titres/style/{style}",
|
|
defaults: new { controller = "Titre", action = "Style" });
|
|
|
|
// --- ACTIONS POST (LIKE / COMMENT) ---
|
|
endpoints.MapControllerRoute(
|
|
name: "TitreLike",
|
|
pattern: "titre/like",
|
|
defaults: new { controller = "Titre", action = "Like" });
|
|
|
|
endpoints.MapControllerRoute(
|
|
name: "TitreComment",
|
|
pattern: "titre/comment",
|
|
defaults: new { controller = "Titre", action = "Comment" });
|
|
|
|
|
|
|
|
// ----------- ADMIN -----------
|
|
|
|
var adminRoutes = new Dictionary<string, string>
|
|
{
|
|
{ "artistes", "Artiste" },
|
|
{ "commentaires", "Commentaire" },
|
|
{ "styles", "Style" },
|
|
{ "titres", "Titre" }
|
|
};
|
|
|
|
foreach (var route in adminRoutes)
|
|
{
|
|
endpoints.MapControllerRoute(
|
|
name: $"Admin{route.Value}Index",
|
|
pattern: $"administration/{route.Key}",
|
|
defaults: new { area = "Administration", controller = route.Value, action = "Index" });
|
|
}
|
|
|
|
|
|
|
|
// --- AUTRE PROUTES ---
|
|
|
|
endpoints.MapControllerRoute(
|
|
name: "areas",
|
|
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
|
|
|
|
endpoints.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Accueil}/{action=Index}/{id?}");
|
|
}
|
|
}
|