From b7eb0f9a68c4ff31c1017ebc7c7549dafc74df99 Mon Sep 17 00:00:00 2001 From: xiang <27800734@qq.com> Date: Sun, 4 May 2025 22:11:28 +0800 Subject: [PATCH] 1 --- .gitignore | 1 - Yes.Blog/DependencyInjection.cs | 30 ++++++++++- .../Endpoints/Admins/AdminEndpointScheme.cs | 6 ++- .../Admins/Articles/ArticleEndpointScheme.cs | 10 ++++ .../Admins/Articles/CreateArticleEndpoint.cs | 7 +-- .../Admins/Articles/DeleteArticleEndpoint.cs | 10 ++-- .../Admins/Articles/GetArticleEndpoint.cs | 6 +-- .../Admins/Articles/GetArticlesEndpoint.cs | 6 +-- .../Articles/GetLatestArticlesEndpoint.cs | 8 ++- .../Admins/Articles/UpdateArticleEndpoint.cs | 2 +- .../Admins/Auths/AuthEndpointScheme.cs | 10 ++++ .../Admins/Auths/UserLoginEndpoint.cs | 2 +- .../Admins/Auths/UserLogoutEndpoint.cs | 4 +- .../Categories/CategoryEndpointScheme.cs | 10 ++++ .../Categories/CreateCategoryEndpoint.cs | 6 +-- .../Categories/DeleteCategoryEndpoint.cs | 2 +- .../Categories/GetCategoriesEndpoint.cs | 6 +-- .../Admins/Categories/GetCategoryEndpoint.cs | 6 +-- .../Categories/UpdateCategoryEndpoint.cs | 6 +-- .../Admins/Comments/CommentEndpointScheme.cs | 10 ++++ .../Admins/Comments/DeleteCommentEndpoint.cs | 6 +-- .../Admins/Comments/GetCommentsEndpoint.cs | 2 +- .../Comments/GetLatestCommentsEndpoint.cs | 4 +- .../Admins/Comments/UpdateCommentEndpoint.cs | 2 +- .../ConfigurationEndpointScheme.cs | 10 ++++ .../GetConfigurationEndpoint.cs | 2 +- .../UpdateConfigurationEndpoint.cs | 2 +- .../Admins/Installs/IndexEndpoint.cs | 50 ----------------- .../Admins/Pages/CreatePageEndpoint.cs | 2 +- .../Admins/Pages/DeletePageEndpoint.cs | 2 +- .../Endpoints/Admins/Pages/GetPageEndpoint.cs | 2 +- .../Admins/Pages/GetPagesEndpoint.cs | 6 +-- .../Admins/Pages/PageEndpointScheme.cs | 10 ++++ .../Admins/Pages/UpdatePageEndpoint.cs | 2 +- .../Admins/Statistics/GetStatsEndpoint.cs | 4 +- .../Admins/Statistics/StatEndpointScheme.cs | 10 ++++ .../Admins/Storages/GenerateTokenEndpoint.cs | 8 ++- .../Admins/Storages/StorageEndpointScheme.cs | 10 ++++ .../Admins/Storages/UploadFileEndpoint.cs | 4 +- .../Endpoints/Admins/Tags/GetTagEndpoint.cs | 2 +- .../Endpoints/Admins/Tags/GetTagsEndpoint.cs | 2 +- .../Admins/Tags/TagEndpointScheme.cs | 10 ++++ .../Admins/Tags/UpdateTagEndpoint.cs | 6 +-- .../Admins/Themes/GetThemesEndpoint.cs | 6 +-- .../Admins/Themes/ThemeEndpointScheme.cs | 10 ++++ .../Admins/Themes/UpdateThemeEndpoint.cs | 7 +-- .../Admins/Users/CreateUserEndpoint.cs | 6 +-- .../Admins/Users/DeleteUserEndpoint.cs | 2 +- .../Admins/Users/GetProfileEndpoint.cs | 6 +-- .../Endpoints/Admins/Users/GetUserEndpoint.cs | 2 +- .../Admins/Users/GetUsersEndpoint.cs | 2 +- .../Admins/Users/UpdatePasswordEndpoint.cs | 2 +- .../Admins/Users/UpdateProfileEndpoint.cs | 2 +- .../Admins/Users/UpdateUserEndpoint.cs | 2 +- .../Admins/Users/UserEndpointScheme.cs | 10 ++++ .../Endpoints/Blogs/BlogEndpointScheme.cs | 8 ++- Yes.Blog/Endpoints/Blogs/InstallEndpoint.cs | 53 +++++++++++++++++++ Yes.Blog/Endpoints/IEndpoint.cs | 7 ++- .../Migrators/MigratorEndpointScheme.cs | 7 ++- Yes.Blog/GlobalUsings.cs | 10 ++-- Yes.Blog/Program.cs | 11 +++- Yes.Blog/Yes.Blog.csproj | 6 +++ Yes.Domain/GlobalUsings.cs | 2 +- Yes.Domain/Logs/LogEntity.cs | 25 +++++++++ .../AuthenticationExtensions.cs | 7 +++ Yes.Infrastructure/GlobalUsings.cs | 16 +++--- .../ViewEngine/BlogResultExtensions.cs | 4 +- .../ViewEngine/BlogViewResult.cs | 2 +- Yes.Infrastructure/Yes.Infrastructure.csproj | 1 + 69 files changed, 344 insertions(+), 178 deletions(-) create mode 100644 Yes.Blog/Endpoints/Admins/Articles/ArticleEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Auths/AuthEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Categories/CategoryEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Comments/CommentEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Configurations/ConfigurationEndpointScheme.cs delete mode 100644 Yes.Blog/Endpoints/Admins/Installs/IndexEndpoint.cs create mode 100644 Yes.Blog/Endpoints/Admins/Pages/PageEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Statistics/StatEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Storages/StorageEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Tags/TagEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Themes/ThemeEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Admins/Users/UserEndpointScheme.cs create mode 100644 Yes.Blog/Endpoints/Blogs/InstallEndpoint.cs create mode 100644 Yes.Domain/Logs/LogEntity.cs diff --git a/.gitignore b/.gitignore index 85a35ab..491d559 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ bld/ [Oo]bj/ [Oo]ut/ [Ll]og/ -[Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/Yes.Blog/DependencyInjection.cs b/Yes.Blog/DependencyInjection.cs index d0c0804..bdaba09 100644 --- a/Yes.Blog/DependencyInjection.cs +++ b/Yes.Blog/DependencyInjection.cs @@ -1,4 +1,6 @@ -namespace Yes.Blog +using Microsoft.AspNetCore.Http; + +namespace Yes.Blog { public static class DependencyInjection { @@ -26,6 +28,27 @@ services.AddUserAuthentication(); + services.AddAuthorization(); + + builder.Services.AddEndpointsApiExplorer(); + + builder.Services.AddOpenApi(options => + { + options.AddDocumentTransformer((document, context, cancellationToken) => + { + document.Info = new() + { + Title = "API", + Version = "V1", + Description = "" + }; + + + return Task.CompletedTask; + }); + + }); + return services; } @@ -202,10 +225,13 @@ var endpoints = app.Services.GetRequiredService>().OrderByDescending(x => x.Priority); foreach (var route in endpoints) { - var routeGroup = app.MapGroup($"/{route.SchemeName}"); + var routeGroup = app.MapGroup($"/{route.Prefix}").WithTags(route.Tags); route.Map(routeGroup); } + + + return app; } diff --git a/Yes.Blog/Endpoints/Admins/AdminEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/AdminEndpointScheme.cs index a3a73ad..41c4269 100644 --- a/Yes.Blog/Endpoints/Admins/AdminEndpointScheme.cs +++ b/Yes.Blog/Endpoints/Admins/AdminEndpointScheme.cs @@ -3,6 +3,8 @@ public class AdminEndpointScheme { public int Priority { get; set; } = 3; - public string SchemeName { get; set; } = "admin/api"; - } + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Blog" }; + } } diff --git a/Yes.Blog/Endpoints/Admins/Articles/ArticleEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Articles/ArticleEndpointScheme.cs new file mode 100644 index 0000000..047bc52 --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Articles/ArticleEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Articles +{ + public class ArticleEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Articles" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Articles/CreateArticleEndpoint.cs b/Yes.Blog/Endpoints/Admins/Articles/CreateArticleEndpoint.cs index bf905bc..585e537 100644 --- a/Yes.Blog/Endpoints/Admins/Articles/CreateArticleEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Articles/CreateArticleEndpoint.cs @@ -1,10 +1,11 @@ namespace Yes.Blog.Endpoints.Admins.Articles { - public class CreateArticleEndpoint : AdminEndpointScheme, IEndpoint + public class CreateArticleEndpoint : ArticleEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPost("/articles", Handle).WithRequestValidation(); - public record Request( + + internal record Request( int CategoryId, string Title, string? Slug, @@ -15,7 +16,7 @@ bool IsDraft ); - public class RequestValidator : AbstractValidator + internal class RequestValidator : AbstractValidator { public RequestValidator() { diff --git a/Yes.Blog/Endpoints/Admins/Articles/DeleteArticleEndpoint.cs b/Yes.Blog/Endpoints/Admins/Articles/DeleteArticleEndpoint.cs index 7bdef40..94af1bb 100644 --- a/Yes.Blog/Endpoints/Admins/Articles/DeleteArticleEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Articles/DeleteArticleEndpoint.cs @@ -1,14 +1,10 @@ - - - - -namespace Yes.Blog.Endpoints.Admins.Articles +namespace Yes.Blog.Endpoints.Admins.Articles { - public class DeleteArticleEndpoint : AdminEndpointScheme, IEndpoint + public class DeleteArticleEndpoint : ArticleEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapDelete("/articles", Handle); - public record Request(int Id); + internal record Request(int Id); diff --git a/Yes.Blog/Endpoints/Admins/Articles/GetArticleEndpoint.cs b/Yes.Blog/Endpoints/Admins/Articles/GetArticleEndpoint.cs index bd0898d..cd65ffa 100644 --- a/Yes.Blog/Endpoints/Admins/Articles/GetArticleEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Articles/GetArticleEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Articles +namespace Yes.Blog.Endpoints.Admins.Articles { - public class GetArticleEndpoint : AdminEndpointScheme, IEndpoint + public class GetArticleEndpoint : ArticleEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/articles/{id}", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Articles/GetArticlesEndpoint.cs b/Yes.Blog/Endpoints/Admins/Articles/GetArticlesEndpoint.cs index 38952c9..0b463a8 100644 --- a/Yes.Blog/Endpoints/Admins/Articles/GetArticlesEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Articles/GetArticlesEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Articles +namespace Yes.Blog.Endpoints.Admins.Articles { - public class GetArticlesEndpoint : AdminEndpointScheme, IEndpoint + public class GetArticlesEndpoint : ArticleEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/articles", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Articles/GetLatestArticlesEndpoint.cs b/Yes.Blog/Endpoints/Admins/Articles/GetLatestArticlesEndpoint.cs index 763928d..1e29801 100644 --- a/Yes.Blog/Endpoints/Admins/Articles/GetLatestArticlesEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Articles/GetLatestArticlesEndpoint.cs @@ -1,10 +1,8 @@ - - -namespace Yes.Blog.Endpoints.Admins.Articles +namespace Yes.Blog.Endpoints.Admins.Articles { - public class GetLatestArticlesEndpoint : AdminEndpointScheme, IEndpoint + public class GetLatestArticlesEndpoint : ArticleEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapGet("/articles/Latest", Handle); + public void Map(IEndpointRouteBuilder app) => app.MapGet("/articles/latest", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Articles/UpdateArticleEndpoint.cs b/Yes.Blog/Endpoints/Admins/Articles/UpdateArticleEndpoint.cs index 4281f1c..54a1fee 100644 --- a/Yes.Blog/Endpoints/Admins/Articles/UpdateArticleEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Articles/UpdateArticleEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Articles { - public class UpdateArticleEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateArticleEndpoint : ArticleEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/articles", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Auths/AuthEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Auths/AuthEndpointScheme.cs new file mode 100644 index 0000000..e90e0bd --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Auths/AuthEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Auths +{ + public class AuthEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Auths" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Auths/UserLoginEndpoint.cs b/Yes.Blog/Endpoints/Admins/Auths/UserLoginEndpoint.cs index 9d242b8..0b7f454 100644 --- a/Yes.Blog/Endpoints/Admins/Auths/UserLoginEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Auths/UserLoginEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Auths { - public class UserLoginEndpoint : AdminEndpointScheme, IEndpoint + public class UserLoginEndpoint : AuthEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPost("/login", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Auths/UserLogoutEndpoint.cs b/Yes.Blog/Endpoints/Admins/Auths/UserLogoutEndpoint.cs index 2493bcc..19e7ab0 100644 --- a/Yes.Blog/Endpoints/Admins/Auths/UserLogoutEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Auths/UserLogoutEndpoint.cs @@ -1,9 +1,9 @@ namespace Yes.Blog.Endpoints.Admins.Auths { - public class UserLogoutEndpoint : AdminEndpointScheme, IEndpoint + public class UserLogoutEndpoint : AuthEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapPost("/Logout", Handle); + public void Map(IEndpointRouteBuilder app) => app.MapPost("/logout", Handle); private async Task Handle(IMediator mediator, IMapper mapper, HttpContext context, CancellationToken cancellationToken) diff --git a/Yes.Blog/Endpoints/Admins/Categories/CategoryEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Categories/CategoryEndpointScheme.cs new file mode 100644 index 0000000..0fda63c --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Categories/CategoryEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Categories +{ + public class CategoryEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Categories" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Categories/CreateCategoryEndpoint.cs b/Yes.Blog/Endpoints/Admins/Categories/CreateCategoryEndpoint.cs index ba84b8b..a00e09f 100644 --- a/Yes.Blog/Endpoints/Admins/Categories/CreateCategoryEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Categories/CreateCategoryEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Categories +namespace Yes.Blog.Endpoints.Admins.Categories { - public class CreateCategoryEndpoint : AdminEndpointScheme, IEndpoint + public class CreateCategoryEndpoint : CategoryEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPost("/categories", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Categories/DeleteCategoryEndpoint.cs b/Yes.Blog/Endpoints/Admins/Categories/DeleteCategoryEndpoint.cs index a098981..8ed6460 100644 --- a/Yes.Blog/Endpoints/Admins/Categories/DeleteCategoryEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Categories/DeleteCategoryEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Categories { - public class DeleteCategoryEndpoint : AdminEndpointScheme, IEndpoint + public class DeleteCategoryEndpoint : CategoryEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapDelete("/categories", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Categories/GetCategoriesEndpoint.cs b/Yes.Blog/Endpoints/Admins/Categories/GetCategoriesEndpoint.cs index 36d2250..6f78b8c 100644 --- a/Yes.Blog/Endpoints/Admins/Categories/GetCategoriesEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Categories/GetCategoriesEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Categories +namespace Yes.Blog.Endpoints.Admins.Categories { - public class GetCategoriesEndpoint : AdminEndpointScheme, IEndpoint + public class GetCategoriesEndpoint : CategoryEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/categories", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Categories/GetCategoryEndpoint.cs b/Yes.Blog/Endpoints/Admins/Categories/GetCategoryEndpoint.cs index 4ad6ccb..602d1d6 100644 --- a/Yes.Blog/Endpoints/Admins/Categories/GetCategoryEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Categories/GetCategoryEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Categories +namespace Yes.Blog.Endpoints.Admins.Categories { - public class GetCategoryEndpoint : AdminEndpointScheme, IEndpoint + public class GetCategoryEndpoint : CategoryEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/categories/{id}", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Categories/UpdateCategoryEndpoint.cs b/Yes.Blog/Endpoints/Admins/Categories/UpdateCategoryEndpoint.cs index f2e932f..20a9933 100644 --- a/Yes.Blog/Endpoints/Admins/Categories/UpdateCategoryEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Categories/UpdateCategoryEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Categories +namespace Yes.Blog.Endpoints.Admins.Categories { - public class UpdateCategoryEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateCategoryEndpoint : CategoryEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/categories", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Comments/CommentEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Comments/CommentEndpointScheme.cs new file mode 100644 index 0000000..d54da0e --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Comments/CommentEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Comments +{ + public class CommentEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Comments" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Comments/DeleteCommentEndpoint.cs b/Yes.Blog/Endpoints/Admins/Comments/DeleteCommentEndpoint.cs index 3426b3e..effeebf 100644 --- a/Yes.Blog/Endpoints/Admins/Comments/DeleteCommentEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Comments/DeleteCommentEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Comments +namespace Yes.Blog.Endpoints.Admins.Comments { - public class DeleteCommentEndpoint : AdminEndpointScheme, IEndpoint + public class DeleteCommentEndpoint : CommentEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapDelete("/comments", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Comments/GetCommentsEndpoint.cs b/Yes.Blog/Endpoints/Admins/Comments/GetCommentsEndpoint.cs index acc7ae0..aaff45d 100644 --- a/Yes.Blog/Endpoints/Admins/Comments/GetCommentsEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Comments/GetCommentsEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Comments { - public class GetCommentsEndpoint : AdminEndpointScheme, IEndpoint + public class GetCommentsEndpoint : CommentEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/comments", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Comments/GetLatestCommentsEndpoint.cs b/Yes.Blog/Endpoints/Admins/Comments/GetLatestCommentsEndpoint.cs index 585ade8..7af8521 100644 --- a/Yes.Blog/Endpoints/Admins/Comments/GetLatestCommentsEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Comments/GetLatestCommentsEndpoint.cs @@ -1,8 +1,8 @@ namespace Yes.Blog.Endpoints.Admins.Comments { - public class GetLatestCommentsEndpoint : AdminEndpointScheme, IEndpoint + public class GetLatestCommentsEndpoint : CommentEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapGet("/comments/Latest", Handle); + public void Map(IEndpointRouteBuilder app) => app.MapGet("/comments/latest", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Comments/UpdateCommentEndpoint.cs b/Yes.Blog/Endpoints/Admins/Comments/UpdateCommentEndpoint.cs index a4a7a66..c5148b5 100644 --- a/Yes.Blog/Endpoints/Admins/Comments/UpdateCommentEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Comments/UpdateCommentEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Comments { - public class UpdateCommentEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateCommentEndpoint : CommentEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/comments", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Configurations/ConfigurationEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Configurations/ConfigurationEndpointScheme.cs new file mode 100644 index 0000000..af8bc23 --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Configurations/ConfigurationEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Configurations +{ + public class ConfigurationEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Configurations" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs b/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs index a4d87cc..9cbf9a1 100644 --- a/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Configurations/GetConfigurationEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Configurations { - public class GetConfigurationEndpoint : AdminEndpointScheme, IEndpoint + public class GetConfigurationEndpoint : ConfigurationEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/configuration", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Configurations/UpdateConfigurationEndpoint.cs b/Yes.Blog/Endpoints/Admins/Configurations/UpdateConfigurationEndpoint.cs index a1b3ddd..9cda1ff 100644 --- a/Yes.Blog/Endpoints/Admins/Configurations/UpdateConfigurationEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Configurations/UpdateConfigurationEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Configurations { - public class UpdateConfigurationEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateConfigurationEndpoint : ConfigurationEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/configuration", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Installs/IndexEndpoint.cs b/Yes.Blog/Endpoints/Admins/Installs/IndexEndpoint.cs deleted file mode 100644 index bb6290a..0000000 --- a/Yes.Blog/Endpoints/Admins/Installs/IndexEndpoint.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace Yes.Blog.Endpoints.Admins.Installs -{ - public class IndexEndpoint : AdminEndpointScheme, IEndpoint - { - public void Map(IEndpointRouteBuilder app) => app.MapPost("install", Handle).WithRequestValidation(); - - public record Request( - string DatabaseType, - string DatabaseServer, - string DatabaseVersion, - string DatabaseUser, - string DatabasePassword, - string DatabaseName, - bool UseDefaultAdmin - ); - - - public class RequestValidator : AbstractValidator - { - public RequestValidator() - { - RuleFor(x => x.DatabaseName).NotEmpty().WithMessage("数据库名不能为空!"); - RuleFor(x => x.DatabaseServer).NotEmpty().WithMessage("数据库地址不能为空!"); - RuleFor(x => x.DatabaseUser).NotEmpty().WithMessage("数据库用户不能为空!"); - RuleFor(x => x.DatabasePassword).NotEmpty().WithMessage("数据库密码不能为空!"); - - } - } - - private async Task Handle( - [FromBody] Request request, - IMediator mediator, - IMapper mapper, - CancellationToken cancellationToken) - { - var command = mapper.Map(request); - var response = await mediator.Send(command, cancellationToken); - - if (response.Success) - { - return Result.Ok(); - } - else - { - return Result.Error(response.ErrorMessage); - } - } - - } -} diff --git a/Yes.Blog/Endpoints/Admins/Pages/CreatePageEndpoint.cs b/Yes.Blog/Endpoints/Admins/Pages/CreatePageEndpoint.cs index 67a477e..c5a16c1 100644 --- a/Yes.Blog/Endpoints/Admins/Pages/CreatePageEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Pages/CreatePageEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Pages { - public class CreatePageEndpoint : AdminEndpointScheme, IEndpoint + public class CreatePageEndpoint : PageEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPost("/pages", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Pages/DeletePageEndpoint.cs b/Yes.Blog/Endpoints/Admins/Pages/DeletePageEndpoint.cs index a827dee..41fd9d1 100644 --- a/Yes.Blog/Endpoints/Admins/Pages/DeletePageEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Pages/DeletePageEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Pages { - public class DeletePageEndpoint : AdminEndpointScheme, IEndpoint + public class DeletePageEndpoint : PageEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapDelete("/pages", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Pages/GetPageEndpoint.cs b/Yes.Blog/Endpoints/Admins/Pages/GetPageEndpoint.cs index 448791f..d5b1f16 100644 --- a/Yes.Blog/Endpoints/Admins/Pages/GetPageEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Pages/GetPageEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Pages { - public class GetPageEndpoint : AdminEndpointScheme, IEndpoint + public class GetPageEndpoint : PageEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/pages/{id}", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Pages/GetPagesEndpoint.cs b/Yes.Blog/Endpoints/Admins/Pages/GetPagesEndpoint.cs index d4f2a50..c17103f 100644 --- a/Yes.Blog/Endpoints/Admins/Pages/GetPagesEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Pages/GetPagesEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Pages +namespace Yes.Blog.Endpoints.Admins.Pages { - public class GetPagesEndpoint : AdminEndpointScheme, IEndpoint + public class GetPagesEndpoint : PageEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/pages", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Pages/PageEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Pages/PageEndpointScheme.cs new file mode 100644 index 0000000..9bc5e07 --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Pages/PageEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Pages +{ + public class PageEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Pages" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Pages/UpdatePageEndpoint.cs b/Yes.Blog/Endpoints/Admins/Pages/UpdatePageEndpoint.cs index 7216af1..9d013c8 100644 --- a/Yes.Blog/Endpoints/Admins/Pages/UpdatePageEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Pages/UpdatePageEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Pages { - public class UpdatePageEndpoint : AdminEndpointScheme, IEndpoint + public class UpdatePageEndpoint : PageEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/pages", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Statistics/GetStatsEndpoint.cs b/Yes.Blog/Endpoints/Admins/Statistics/GetStatsEndpoint.cs index b88f7e4..3c9374e 100644 --- a/Yes.Blog/Endpoints/Admins/Statistics/GetStatsEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Statistics/GetStatsEndpoint.cs @@ -1,8 +1,8 @@ namespace Yes.Blog.Endpoints.Admins.Statistics { - public class GetStatsEndpoint : AdminEndpointScheme, IEndpoint + public class GetStatsEndpoint : StatEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapGet("/Stats", Handle); + public void Map(IEndpointRouteBuilder app) => app.MapGet("/stats", Handle); private async Task Handle(IMediator mediator, IMapper mapper, CancellationToken cancellationToken) diff --git a/Yes.Blog/Endpoints/Admins/Statistics/StatEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Statistics/StatEndpointScheme.cs new file mode 100644 index 0000000..e535a71 --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Statistics/StatEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Statistics +{ + public class StatEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Statistics" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Storages/GenerateTokenEndpoint.cs b/Yes.Blog/Endpoints/Admins/Storages/GenerateTokenEndpoint.cs index 6190ee2..70372b7 100644 --- a/Yes.Blog/Endpoints/Admins/Storages/GenerateTokenEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Storages/GenerateTokenEndpoint.cs @@ -1,10 +1,8 @@ - - -namespace Yes.Blog.Endpoints.Admins.Storages +namespace Yes.Blog.Endpoints.Admins.Storages { - public class GenerateTokenEndpoint : AdminEndpointScheme, IEndpoint + public class GenerateTokenEndpoint : StorageEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapPost("/Storages/token", Handle); + public void Map(IEndpointRouteBuilder app) => app.MapPost("/storages/token", Handle); private async Task Handle( IMediator mediator, diff --git a/Yes.Blog/Endpoints/Admins/Storages/StorageEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Storages/StorageEndpointScheme.cs new file mode 100644 index 0000000..c652bfb --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Storages/StorageEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Storages +{ + public class StorageEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Storages" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Storages/UploadFileEndpoint.cs b/Yes.Blog/Endpoints/Admins/Storages/UploadFileEndpoint.cs index fe01820..e97ab54 100644 --- a/Yes.Blog/Endpoints/Admins/Storages/UploadFileEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Storages/UploadFileEndpoint.cs @@ -1,8 +1,8 @@ namespace Yes.Blog.Endpoints.Admins.Storages { - public class UploadFileEndpoint : AdminEndpointScheme, IEndpoint + public class UploadFileEndpoint : StorageEndpointScheme, IEndpoint { - public void Map(IEndpointRouteBuilder app) => app.MapPost("/Storages/upload", Handle).DisableAntiforgery(); + public void Map(IEndpointRouteBuilder app) => app.MapPost("/storages/upload", Handle).DisableAntiforgery(); public record Request( IFormFile File ); diff --git a/Yes.Blog/Endpoints/Admins/Tags/GetTagEndpoint.cs b/Yes.Blog/Endpoints/Admins/Tags/GetTagEndpoint.cs index 0d70b7b..1a4ce3a 100644 --- a/Yes.Blog/Endpoints/Admins/Tags/GetTagEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Tags/GetTagEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Tags { - public class GetTagEndpoint : AdminEndpointScheme, IEndpoint + public class GetTagEndpoint : TagEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/tags/{id}", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Tags/GetTagsEndpoint.cs b/Yes.Blog/Endpoints/Admins/Tags/GetTagsEndpoint.cs index 98bf3b5..2602f33 100644 --- a/Yes.Blog/Endpoints/Admins/Tags/GetTagsEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Tags/GetTagsEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Tags { - public class GetTagsEndpoint : AdminEndpointScheme, IEndpoint + public class GetTagsEndpoint : TagEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/tags", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Tags/TagEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Tags/TagEndpointScheme.cs new file mode 100644 index 0000000..08323d1 --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Tags/TagEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Tags +{ + public class TagEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Tags" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Tags/UpdateTagEndpoint.cs b/Yes.Blog/Endpoints/Admins/Tags/UpdateTagEndpoint.cs index c58abbd..00a21ab 100644 --- a/Yes.Blog/Endpoints/Admins/Tags/UpdateTagEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Tags/UpdateTagEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Tags +namespace Yes.Blog.Endpoints.Admins.Tags { - public class UpdateTagEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateTagEndpoint : TagEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/tags", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Themes/GetThemesEndpoint.cs b/Yes.Blog/Endpoints/Admins/Themes/GetThemesEndpoint.cs index e586c23..85f9538 100644 --- a/Yes.Blog/Endpoints/Admins/Themes/GetThemesEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Themes/GetThemesEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Themes +namespace Yes.Blog.Endpoints.Admins.Themes { - public class GetThemesEndpoint : AdminEndpointScheme, IEndpoint + public class GetThemesEndpoint : ThemeEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/themes", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Themes/ThemeEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Themes/ThemeEndpointScheme.cs new file mode 100644 index 0000000..f9b4647 --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Themes/ThemeEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Themes +{ + public class ThemeEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Themes" }; + } +} diff --git a/Yes.Blog/Endpoints/Admins/Themes/UpdateThemeEndpoint.cs b/Yes.Blog/Endpoints/Admins/Themes/UpdateThemeEndpoint.cs index 181dea3..9b1f1bf 100644 --- a/Yes.Blog/Endpoints/Admins/Themes/UpdateThemeEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Themes/UpdateThemeEndpoint.cs @@ -1,14 +1,15 @@ namespace Yes.Blog.Endpoints.Admins.Themes { - public class UpdateThemeEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateThemeEndpoint : ThemeEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/themes", Handle).WithRequestValidation(); - public record Request( + [Scalar.AspNetCore.ExcludeFromApiReference] + internal record Request( string Theme ); - public class RequestValidator : AbstractValidator + internal class RequestValidator : AbstractValidator { public RequestValidator() { diff --git a/Yes.Blog/Endpoints/Admins/Users/CreateUserEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/CreateUserEndpoint.cs index ae021c4..bc1c27b 100644 --- a/Yes.Blog/Endpoints/Admins/Users/CreateUserEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/CreateUserEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Users +namespace Yes.Blog.Endpoints.Admins.Users { - public class CreateUserEndpoint : AdminEndpointScheme, IEndpoint + public class CreateUserEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPost("/users", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Users/DeleteUserEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/DeleteUserEndpoint.cs index 80e4d49..84cfa3b 100644 --- a/Yes.Blog/Endpoints/Admins/Users/DeleteUserEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/DeleteUserEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Users { - public class DeleteUserEndpoint : AdminEndpointScheme, IEndpoint + public class DeleteUserEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapDelete("/users", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Users/GetProfileEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/GetProfileEndpoint.cs index 50510df..10a680f 100644 --- a/Yes.Blog/Endpoints/Admins/Users/GetProfileEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/GetProfileEndpoint.cs @@ -1,8 +1,6 @@ - - -namespace Yes.Blog.Endpoints.Admins.Users +namespace Yes.Blog.Endpoints.Admins.Users { - public class GetProfileEndpoint : AdminEndpointScheme, IEndpoint + public class GetProfileEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/users/profile", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Users/GetUserEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/GetUserEndpoint.cs index 3c78d17..f3f60c3 100644 --- a/Yes.Blog/Endpoints/Admins/Users/GetUserEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/GetUserEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Users { - public class GetUserEndpoint : AdminEndpointScheme, IEndpoint + public class GetUserEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/users/{id}", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Users/GetUsersEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/GetUsersEndpoint.cs index 62f5a37..6596afa 100644 --- a/Yes.Blog/Endpoints/Admins/Users/GetUsersEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/GetUsersEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Users { - public class GetUsersEndpoint : AdminEndpointScheme, IEndpoint + public class GetUsersEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapGet("/users", Handle); diff --git a/Yes.Blog/Endpoints/Admins/Users/UpdatePasswordEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/UpdatePasswordEndpoint.cs index 8c4975f..e2b41c5 100644 --- a/Yes.Blog/Endpoints/Admins/Users/UpdatePasswordEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/UpdatePasswordEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Users { - public class UpdatePasswordEndpoint : AdminEndpointScheme, IEndpoint + public class UpdatePasswordEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/users/Password", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Users/UpdateProfileEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/UpdateProfileEndpoint.cs index cb6e8f9..e23adad 100644 --- a/Yes.Blog/Endpoints/Admins/Users/UpdateProfileEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/UpdateProfileEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Users { - public class UpdateProfileEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateProfileEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/users/profile", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Users/UpdateUserEndpoint.cs b/Yes.Blog/Endpoints/Admins/Users/UpdateUserEndpoint.cs index 2045563..b14c1be 100644 --- a/Yes.Blog/Endpoints/Admins/Users/UpdateUserEndpoint.cs +++ b/Yes.Blog/Endpoints/Admins/Users/UpdateUserEndpoint.cs @@ -1,6 +1,6 @@ namespace Yes.Blog.Endpoints.Admins.Users { - public class UpdateUserEndpoint : AdminEndpointScheme, IEndpoint + public class UpdateUserEndpoint : UserEndpointScheme, IEndpoint { public void Map(IEndpointRouteBuilder app) => app.MapPut("/users", Handle).WithRequestValidation(); diff --git a/Yes.Blog/Endpoints/Admins/Users/UserEndpointScheme.cs b/Yes.Blog/Endpoints/Admins/Users/UserEndpointScheme.cs new file mode 100644 index 0000000..332937a --- /dev/null +++ b/Yes.Blog/Endpoints/Admins/Users/UserEndpointScheme.cs @@ -0,0 +1,10 @@ +namespace Yes.Blog.Endpoints.Admins.Users +{ + public class UserEndpointScheme + { + public int Priority { get; set; } = 3; + public string Prefix { get; set; } = "admin/api"; + + public string[] Tags { get; set; } = new[] { "Users" }; + } +} diff --git a/Yes.Blog/Endpoints/Blogs/BlogEndpointScheme.cs b/Yes.Blog/Endpoints/Blogs/BlogEndpointScheme.cs index 86653bf..ad28bb2 100644 --- a/Yes.Blog/Endpoints/Blogs/BlogEndpointScheme.cs +++ b/Yes.Blog/Endpoints/Blogs/BlogEndpointScheme.cs @@ -3,6 +3,10 @@ public class BlogEndpointScheme { public int Priority { get; set; } = 0; - public string SchemeName { get; set; } = ""; - } + + public string Prefix { get; set; } = ""; + + + public string[] Tags { get; set; } = new[] { "Blog" }; + } } diff --git a/Yes.Blog/Endpoints/Blogs/InstallEndpoint.cs b/Yes.Blog/Endpoints/Blogs/InstallEndpoint.cs new file mode 100644 index 0000000..f311eef --- /dev/null +++ b/Yes.Blog/Endpoints/Blogs/InstallEndpoint.cs @@ -0,0 +1,53 @@ +using Yes.Blog.Endpoints.Admins; + +namespace Yes.Blog.Endpoints.Blogs +{ + public class InstallEndpoint : BlogEndpointScheme, IEndpoint + { + public void Map(IEndpointRouteBuilder app) => app.MapPost("install", Handle).WithRequestValidation(); + + public record Request( + string DatabaseType, + string DatabaseServer, + string DatabaseVersion, + string DatabaseUser, + string DatabasePassword, + string DatabaseName, + bool UseDefaultAdmin + ); + + + public class RequestValidator : AbstractValidator + { + public RequestValidator() + { + RuleFor(x => x.DatabaseName).NotEmpty().WithMessage("数据库名不能为空!"); + RuleFor(x => x.DatabaseServer).NotEmpty().WithMessage("数据库地址不能为空!"); + RuleFor(x => x.DatabaseUser).NotEmpty().WithMessage("数据库用户不能为空!"); + RuleFor(x => x.DatabasePassword).NotEmpty().WithMessage("数据库密码不能为空!"); + + } + } + + + private async Task Handle( + [FromBody] Request request, + IMediator mediator, + IMapper mapper, + CancellationToken cancellationToken) + { + var command = mapper.Map(request); + var response = await mediator.Send(command, cancellationToken); + + if (response.Success) + { + return Result.Ok(); + } + else + { + return Result.Error(response.ErrorMessage); + } + } + + } +} diff --git a/Yes.Blog/Endpoints/IEndpoint.cs b/Yes.Blog/Endpoints/IEndpoint.cs index 270c9bb..a1ebef9 100644 --- a/Yes.Blog/Endpoints/IEndpoint.cs +++ b/Yes.Blog/Endpoints/IEndpoint.cs @@ -5,9 +5,12 @@ int Priority { get; } - string SchemeName { get; } + string Prefix { get; } void Map(IEndpointRouteBuilder app); - } + + string[] Tags { get; } + + } } diff --git a/Yes.Blog/Endpoints/Migrators/MigratorEndpointScheme.cs b/Yes.Blog/Endpoints/Migrators/MigratorEndpointScheme.cs index 901b932..7d26272 100644 --- a/Yes.Blog/Endpoints/Migrators/MigratorEndpointScheme.cs +++ b/Yes.Blog/Endpoints/Migrators/MigratorEndpointScheme.cs @@ -3,6 +3,9 @@ public class MigratorEndpointScheme { public int Priority { get; set; } = 99; - public string SchemeName { get; set; } = "Migrator"; - } + + public string Prefix { get; set; } = "migrator"; + + public string[] Tags { get; set; } = new[] { "Migrators" }; + } } diff --git a/Yes.Blog/GlobalUsings.cs b/Yes.Blog/GlobalUsings.cs index aff8550..901a74b 100644 --- a/Yes.Blog/GlobalUsings.cs +++ b/Yes.Blog/GlobalUsings.cs @@ -32,14 +32,14 @@ global using Yes.Blog.Endpoints; global using Yes.Domain.Blogs; global using Yes.Domain.Configurations; global using Yes.Domain.Core.Enums; +global using Yes.Domain.Core.Exceptions; +global using Yes.Domain.Core.Extensions; +global using Yes.Domain.Core.Helpers; global using Yes.Domain.Core.Ioc; global using Yes.Domain.Core.Models; global using Yes.Domain.Installs; -global using IResult = Yes.Domain.Core.Models.IResult; +global using Yes.Infrastructure; global using Yes.Infrastructure.Authorizations; global using Yes.Infrastructure.Middlewares; -global using Yes.Domain.Core.Extensions; -global using Yes.Domain.Core.Exceptions; global using Yes.Infrastructure.ViewEngine; -global using Yes.Domain.Core.Helpers; -global using Yes.Infrastructure; \ No newline at end of file +global using IResult = Yes.Domain.Core.Models.IResult; diff --git a/Yes.Blog/Program.cs b/Yes.Blog/Program.cs index bb0e02a..485b460 100644 --- a/Yes.Blog/Program.cs +++ b/Yes.Blog/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Models; +using Scalar.AspNetCore; + namespace Yes.Blog { public class Program @@ -10,8 +15,6 @@ namespace Yes.Blog builder.Services.RegisterApplicationModule(); builder.Services.RegisterDataModule(); - builder.Services.AddEndpointsApiExplorer(); - var app = builder.Build(); // Configure the HTTP request pipeline. @@ -20,8 +23,12 @@ namespace Yes.Blog app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); + + app.MapOpenApi(); + app.MapScalarApiReference(); } + app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/Yes.Blog/Yes.Blog.csproj b/Yes.Blog/Yes.Blog.csproj index 463eef8..6bedb1d 100644 --- a/Yes.Blog/Yes.Blog.csproj +++ b/Yes.Blog/Yes.Blog.csproj @@ -42,7 +42,9 @@ + + @@ -296,4 +298,8 @@ + + + + diff --git a/Yes.Domain/GlobalUsings.cs b/Yes.Domain/GlobalUsings.cs index 35d5710..5265781 100644 --- a/Yes.Domain/GlobalUsings.cs +++ b/Yes.Domain/GlobalUsings.cs @@ -7,6 +7,7 @@ global using System.Text; global using System.Text.RegularExpressions; global using Markdig; global using Microsoft.AspNetCore.Http; +global using Microsoft.EntityFrameworkCore; global using Yes.Domain.Articles; global using Yes.Domain.Categories; global using Yes.Domain.Core.Enums; @@ -15,4 +16,3 @@ global using Yes.Domain.Core.Extensions; global using Yes.Domain.Core.Ioc; global using Yes.Domain.Core.Models; global using Yes.Domain.Users; -global using Microsoft.EntityFrameworkCore; \ No newline at end of file diff --git a/Yes.Domain/Logs/LogEntity.cs b/Yes.Domain/Logs/LogEntity.cs new file mode 100644 index 0000000..7386804 --- /dev/null +++ b/Yes.Domain/Logs/LogEntity.cs @@ -0,0 +1,25 @@ +namespace Yes.Domain.Logs +{ + [Table("Log")] + public class LogEntity + { + [Key] + public int Id { get; set; } + + public int UserId { get; set; } + + public LogTypeEnum Type { get; set; } + + public int RelatedId { get; set; } + + public RelatedTypeEnum RelatedType { get; set; } + + public string Content { get; set; } + + public bool Success { get; set; } + + public string Ip { get; set; } + + public DateTime CreateDate { get; set; } + } +} diff --git a/Yes.Infrastructure/Authorizations/AuthenticationExtensions.cs b/Yes.Infrastructure/Authorizations/AuthenticationExtensions.cs index d039876..8931aa9 100644 --- a/Yes.Infrastructure/Authorizations/AuthenticationExtensions.cs +++ b/Yes.Infrastructure/Authorizations/AuthenticationExtensions.cs @@ -12,6 +12,13 @@ options.LogoutPath = "/admin/logout"; options.ExpireTimeSpan = TimeSpan.FromDays(3); options.SlidingExpiration = true; + + options.Events.OnRedirectToAccessDenied = + options.Events.OnRedirectToLogin = c => + { + c.Response.StatusCode = StatusCodes.Status401Unauthorized; + return Task.FromResult(Result.Error("请登录后操作!")); + }; }); return services; } diff --git a/Yes.Infrastructure/GlobalUsings.cs b/Yes.Infrastructure/GlobalUsings.cs index d8dce8d..9f97ad6 100644 --- a/Yes.Infrastructure/GlobalUsings.cs +++ b/Yes.Infrastructure/GlobalUsings.cs @@ -13,6 +13,7 @@ global using System.Text; global using System.Web; global using Dapper; global using FluentMigrator; +global using FluentMigrator.Runner; global using Fluid; global using Fluid.ViewEngine; global using Microsoft.AspNetCore.Authentication; @@ -34,13 +35,12 @@ global using Yes.Domain.Configurations; global using Yes.Domain.Core.Data; global using Yes.Domain.Core.Enums; global using Yes.Domain.Core.Exceptions; -global using Yes.Domain.Core.Ioc; -global using Yes.Domain.Users; -global using Yes.Infrastructure.Authorizations.Identity.Context; -global using Yes.Infrastructure.Authorizations.Identity.Authroizations; -global using Yes.Infrastructure.Authorizations.Identity; -global using Yes.Infrastructure.Data.DbContexts; global using Yes.Domain.Core.Extensions; -global using FluentMigrator.Runner; -global using Yes.Infrastructure.Migrator; +global using Yes.Domain.Core.Ioc; +global using Yes.Domain.Core.Models; +global using Yes.Domain.Users; +global using Yes.Infrastructure.Authorizations.Identity; +global using Yes.Infrastructure.Authorizations.Identity.Authroizations; +global using Yes.Infrastructure.Authorizations.Identity.Context; +global using Yes.Infrastructure.Data.DbContexts; global using Yes.Infrastructure.Migrator.Migrations; \ No newline at end of file diff --git a/Yes.Infrastructure/ViewEngine/BlogResultExtensions.cs b/Yes.Infrastructure/ViewEngine/BlogResultExtensions.cs index 5a29649..e29af15 100644 --- a/Yes.Infrastructure/ViewEngine/BlogResultExtensions.cs +++ b/Yes.Infrastructure/ViewEngine/BlogResultExtensions.cs @@ -2,12 +2,12 @@ { public static class BlogResultExtensions { - public static IResult BlogView(this IResultExtensions result, string theme, string viewName) + public static Microsoft.AspNetCore.Http.IResult BlogView(this IResultExtensions result, string theme, string viewName) { return new BlogViewResult(theme, viewName); } - public static IResult BlogView(this IResultExtensions result, string theme, string viewName, object model) + public static Microsoft.AspNetCore.Http.IResult BlogView(this IResultExtensions result, string theme, string viewName, object model) { return new BlogViewResult(theme, viewName, model); } diff --git a/Yes.Infrastructure/ViewEngine/BlogViewResult.cs b/Yes.Infrastructure/ViewEngine/BlogViewResult.cs index 406a429..1bf243c 100644 --- a/Yes.Infrastructure/ViewEngine/BlogViewResult.cs +++ b/Yes.Infrastructure/ViewEngine/BlogViewResult.cs @@ -1,6 +1,6 @@ namespace Yes.Infrastructure.ViewEngine { - public class BlogViewResult : IResult + public class BlogViewResult : Microsoft.AspNetCore.Http.IResult { private readonly string _theme; private readonly string _viewName; diff --git a/Yes.Infrastructure/Yes.Infrastructure.csproj b/Yes.Infrastructure/Yes.Infrastructure.csproj index 22d972e..89513ce 100644 --- a/Yes.Infrastructure/Yes.Infrastructure.csproj +++ b/Yes.Infrastructure/Yes.Infrastructure.csproj @@ -12,6 +12,7 @@ +