namespace MyOffice.Web; public partial class Program { private static void MapRoutes(WebApplication app) { MapRoute(app, Routes.GlobalCurrencies, "General", "GetGlobalCurrencies", HttpMethod.Get); // Settings Currency MapRoute(app, Routes.SettingsCurrencies, "Currency", "Get", HttpMethod.Get); MapRoute(app, Routes.SettingsCurrencies, "Currency", "Add", HttpMethod.Post); MapRoute(app, Routes.SettingsCurrency, "Currency", "Update", HttpMethod.Put); MapRoute(app, Routes.SettingsCurrency, "Currency", "Delete", HttpMethod.Delete); MapRoute(app, Routes.SettingsCurrencyRate, "Currency", "AddRate", HttpMethod.Post); } private static void MapRoute( WebApplication app, string route, string controller, string action, params HttpMethod[] methods ) { object? constraints = null; if (methods?.Any() == true) { constraints = new { httpMethod = new Microsoft.AspNetCore.Routing.Constraints.HttpMethodRouteConstraint(methods.Select(x => x.ToString()).ToArray()) }; } app.MapControllerRoute( name: $"{controller}_{action}", pattern: route, defaults: new { controller, action, }, constraints: constraints ); } } public static class Routes { public static readonly string GlobalCurrencies = "api/general/currencies"; public static readonly string SettingsCurrencies = "api/settings/currencies"; public static readonly string SettingsCurrency = "api/settings/currencies/{id}"; public static readonly string SettingsCurrencyRate = "api/settings/currencies/{id}/rate"; }