diff --git a/src/UserPointManagement.Model/Dtos/User/GetUserDto.cs b/src/UserPointManagement.Model/Dtos/User/GetUserDto.cs index f263408..b0c866c 100644 --- a/src/UserPointManagement.Model/Dtos/User/GetUserDto.cs +++ b/src/UserPointManagement.Model/Dtos/User/GetUserDto.cs @@ -2,5 +2,5 @@ public class GetUserDto : PageBase { - public string Keyword { get; set; } + public string? Keyword { get; set; } } \ No newline at end of file diff --git a/src/UserPointManagement.Web/Controllers/UserController.cs b/src/UserPointManagement.Web/Controllers/UserController.cs index 3d37dab..e6296f6 100644 --- a/src/UserPointManagement.Web/Controllers/UserController.cs +++ b/src/UserPointManagement.Web/Controllers/UserController.cs @@ -8,7 +8,7 @@ using UserPointManagement.Model.Entities; namespace UserPointManagement.Web.Controllers; [ApiController] -[Route("api/[controller]")] +[Route("[controller]")] public class UserController : ControllerBase { private readonly IUserService _userService; diff --git a/src/UserPointManagement.Web/MvcOptionsExtensions.cs b/src/UserPointManagement.Web/MvcOptionsExtensions.cs new file mode 100644 index 0000000..72e4d8e --- /dev/null +++ b/src/UserPointManagement.Web/MvcOptionsExtensions.cs @@ -0,0 +1,45 @@ +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.Routing; + +namespace UserPointManagement.Web; + +public static class MvcOptionsExtensions +{ + private static void UseGeneralRoutePrefix(this MvcOptions opts, IRouteTemplateProvider routeAttribute) + { + opts.Conventions.Add(new RoutePrefixConvention(routeAttribute)); + } + + public static void UseGeneralRoutePrefix(this MvcOptions opts, string + prefix) + { + opts.UseGeneralRoutePrefix(new RouteAttribute(prefix)); + } +} + +public class RoutePrefixConvention : IApplicationModelConvention +{ + private readonly AttributeRouteModel _routePrefix; + + public RoutePrefixConvention(IRouteTemplateProvider route) + { + _routePrefix = new AttributeRouteModel(route); + } + + public void Apply(ApplicationModel application) + { + foreach (var selector in application.Controllers.SelectMany(c => c.Selectors)) + { + if (selector.AttributeRouteModel != null) + { + selector.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel(_routePrefix, selector.AttributeRouteModel); + } + else + { + selector.AttributeRouteModel = _routePrefix; + } + } + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/Startup.cs b/src/UserPointManagement.Web/Startup.cs index c614071..6e09fd3 100644 --- a/src/UserPointManagement.Web/Startup.cs +++ b/src/UserPointManagement.Web/Startup.cs @@ -30,6 +30,7 @@ namespace UserPointManagement.Web { services.AddControllers(options => { + options.UseGeneralRoutePrefix("/api"); }); services.AddEndpointsApiExplorer(); services.AddSwaggerGen(options => @@ -92,7 +93,7 @@ namespace UserPointManagement.Web app.UseStaticFiles(); app.UseRouting(); - + app.UseEndpoints(endpoints => { endpoints.MapControllers();