diff --git a/src/UserPointManagement.Web/Controllers/UserController.cs b/src/UserPointManagement.Web/Controllers/UserController.cs new file mode 100644 index 0000000..3d37dab --- /dev/null +++ b/src/UserPointManagement.Web/Controllers/UserController.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using UserPointManagement.Application.Services; +using UserPointManagement.Model; +using UserPointManagement.Model.Dtos.User; +using UserPointManagement.Model.Entities; + +namespace UserPointManagement.Web.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class UserController : ControllerBase +{ + private readonly IUserService _userService; + + public UserController(IUserService userService) + { + _userService = userService; + } + + /// + /// 获取用户 + /// + /// + /// + [HttpGet] + public async Task> GetUsers([FromQuery]GetUserDto req) + { + return await _userService.GetUsers(req).ConfigureAwait(false); + } +} \ No newline at end of file diff --git a/src/UserPointManagement.Web/Startup.cs b/src/UserPointManagement.Web/Startup.cs index 4271cda..c614071 100644 --- a/src/UserPointManagement.Web/Startup.cs +++ b/src/UserPointManagement.Web/Startup.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Linq; using System.Net.Http; using AntDesign.ProLayout; using Microsoft.AspNetCore.Builder; @@ -26,6 +28,19 @@ namespace UserPointManagement.Web // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddControllers(options => + { + }); + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(options => + { + Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.xml").ToList().ForEach(file => + { + options.IncludeXmlComments(file, true); + }); + }); + services.AddRouting(options => options.LowercaseUrls = true); + services.AddRazorPages(); services.AddServerSideBlazor(); services.AddAntDesign(); @@ -46,6 +61,7 @@ namespace UserPointManagement.Web AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -54,6 +70,16 @@ namespace UserPointManagement.Web if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); + app.UseSwagger(o => + { + // o.RouteTemplate = $"/api/swagger/{{documentName}}/swagger.json"; + }); + app.UseSwaggerUI(c => + { + // c.RoutePrefix = $"/api/swagger"; + // c.SwaggerEndpoint($"/api/swagger/v1/swagger.json", + // "UserPointManagement.Api API V1"); + }); } else { @@ -66,9 +92,10 @@ namespace UserPointManagement.Web app.UseStaticFiles(); app.UseRouting(); - + app.UseEndpoints(endpoints => { + endpoints.MapControllers(); endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/_Host"); }); diff --git a/src/UserPointManagement.Web/UserPointManagement.Web.csproj b/src/UserPointManagement.Web/UserPointManagement.Web.csproj index 92e8682..4b31866 100644 --- a/src/UserPointManagement.Web/UserPointManagement.Web.csproj +++ b/src/UserPointManagement.Web/UserPointManagement.Web.csproj @@ -9,6 +9,7 @@ +