diff --git a/Tiobon.Core.Api/Controllers/BlogController.cs b/Tiobon.Core.Api/Controllers/BlogController.cs
deleted file mode 100644
index 5f9515d0..00000000
--- a/Tiobon.Core.Api/Controllers/BlogController.cs
+++ /dev/null
@@ -1,267 +0,0 @@
-using Serilog;
-using StackExchange.Profiling;
-using static Tiobon.Core.Extensions.CustomApiVersion;
-
-namespace Tiobon.Core.Controllers;
-
-///
-/// 博客管理
-///
-[Produces("application/json")]
-[Route("api/Tiobon"), ApiExplorerSettings(GroupName = Grouping.GroupName_Other)]
-public class TiobonController : BaseApiController
-{
- public ITiobonArticleServices _TiobonArticleServices { get; set; }
- private readonly ILogger _logger;
-
- ///
- /// 构造函数
- ///
- ///
- ///
- public TiobonController(ILogger logger)
- {
- _logger = logger;
- }
-
-
- ///
- /// 获取博客列表【无权限】
- ///
- ///
- ///
- ///
- ///
- ///
- [HttpGet]
- public async Task>> Get(int id, int page = 1, string bcategory = "技术博文", string key = "")
- {
- int intPageSize = 6;
- if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
- {
- key = "";
- }
-
- Expression> whereExpression = a => (a.bcategory == bcategory && a.IsDeleted == false) && ((a.btitle != null && a.btitle.Contains(key)) || (a.bcontent != null && a.bcontent.Contains(key)));
-
- var pageModelTiobon = await _TiobonArticleServices.QueryPage(whereExpression, page, intPageSize, " bID desc ");
-
- using (MiniProfiler.Current.Step("获取成功后,开始处理最终数据"))
- {
- foreach (var item in pageModelTiobon.data)
- {
- if (!string.IsNullOrEmpty(item.bcontent))
- {
- item.bRemark = (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Length >= 200 ? (HtmlHelper.ReplaceHtmlTag(item.bcontent)).Substring(0, 200) : (HtmlHelper.ReplaceHtmlTag(item.bcontent));
- int totalLength = 500;
- if (item.bcontent.Length > totalLength)
- {
- item.bcontent = item.bcontent.Substring(0, totalLength);
- }
- }
- }
- }
-
- return SuccessPage(pageModelTiobon);
- }
-
-
- ///
- /// 获取博客详情
- ///
- ///
- ///
- [HttpGet("{id}")]
- //[Authorize(Policy = "Scope_TiobonModule_Policy")]
- [Authorize]
- public async Task> Get(long id)
- {
- return Success(await _TiobonArticleServices.GetTiobonDetails(id));
- }
-
-
- ///
- /// 获取详情【无权限】
- ///
- ///
- ///
- [HttpGet]
- [Route("DetailNuxtNoPer")]
- public async Task> DetailNuxtNoPer(long id)
- {
- _logger.LogInformation("xxxxxxxxxxxxxxxxxxx");
- Log.Information("yyyyyyyyyyyyyyyyy");
- return Success(await _TiobonArticleServices.GetTiobonDetails(id));
- }
-
- [HttpGet]
- [Route("GoUrl")]
- public async Task GoUrl(long id = 0)
- {
- var response = await _TiobonArticleServices.QueryById(id);
- if (response != null && response.bsubmitter.IsNotEmptyOrNull())
- {
- string Url = @"^http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$";
- if (Regex.IsMatch(response.bsubmitter, Url))
- {
- response.btraffic += 1;
- await _TiobonArticleServices.Update(response);
- return Redirect(response.bsubmitter);
- }
-
- }
-
- return Ok();
- }
-
- [HttpGet]
- [Route("GetTiobonsByTypesForMVP")]
- public async Task>> GetTiobonsByTypesForMVP(string types = "", int id = 0)
- {
- if (types.IsNotEmptyOrNull())
- {
- var Tiobons = await _TiobonArticleServices.Query(d => d.bcategory != null && types.Contains(d.bcategory) && d.IsDeleted == false, d => d.bID, false);
- return Success(Tiobons);
- }
- return Success(new List() { });
- }
-
- [HttpGet]
- [Route("GetTiobonByIdForMVP")]
- public async Task> GetTiobonByIdForMVP(long id = 0)
- {
- if (id > 0)
- {
- return Success(await _TiobonArticleServices.QueryById(id));
- }
- return Success(new TiobonArticle());
- }
-
- ///
- /// 获取博客测试信息 v2版本
- ///
- ///
- [HttpGet]
- ////MVC自带特性 对 api 进行组管理
- //[ApiExplorerSettings(GroupName = "v2")]
- ////路径 如果以 / 开头,表示绝对路径,反之相对 controller 的想u地路径
- //[Route("/api/v2/Tiobon/Tiobontest")]
- //和上边的版本控制以及路由地址都是一样的
-
- [CustomRoute(ApiVersions.V2, "Tiobontest")]
- public ServiceResult V2_Tiobontest()
- {
- return Success("我是第二版的博客信息");
- }
-
- ///
- /// 添加博客【无权限】
- ///
- ///
- ///
- [HttpPost]
- //[Authorize(Policy = "Scope_TiobonModule_Policy")]
- [Authorize]
- public async Task> Post([FromBody] TiobonArticle TiobonArticle)
- {
- if (TiobonArticle.btitle.Length > 5 && TiobonArticle.bcontent.Length > 50)
- {
-
- TiobonArticle.bCreateTime = DateTime.Now;
- TiobonArticle.bUpdateTime = DateTime.Now;
- TiobonArticle.IsDeleted = false;
- TiobonArticle.bcategory = "技术博文";
- var id = (await _TiobonArticleServices.Add(TiobonArticle));
- return id > 0 ? Success(id.ObjToString()) : Failed("添加失败");
- }
- else
- {
- return Failed("文章标题不能少于5个字符,内容不能少于50个字符!");
- }
- }
-
-
- ///
- ///
- ///
- ///
- ///
- [HttpPost]
- [Route("AddForMVP")]
- [Authorize(Permissions.Name)]
- public async Task> AddForMVP([FromBody] TiobonArticle TiobonArticle)
- {
- TiobonArticle.bCreateTime = DateTime.Now;
- TiobonArticle.bUpdateTime = DateTime.Now;
- TiobonArticle.IsDeleted = false;
- var id = (await _TiobonArticleServices.Add(TiobonArticle));
- return id > 0 ? Success(id.ObjToString()) : Failed("添加失败");
- }
- ///
- /// 更新博客信息
- ///
- ///
- ///
- // PUT: api/User/5
- [HttpPut]
- [Route("Update")]
- [Authorize(Permissions.Name)]
- public async Task> Put([FromBody] TiobonArticle TiobonArticle)
- {
- if (TiobonArticle != null && TiobonArticle.bID > 0)
- {
- var model = await _TiobonArticleServices.QueryById(TiobonArticle.bID);
-
- if (model != null)
- {
- model.btitle = TiobonArticle.btitle;
- model.bcategory = TiobonArticle.bcategory;
- model.bsubmitter = TiobonArticle.bsubmitter;
- model.bcontent = TiobonArticle.bcontent;
- model.btraffic = TiobonArticle.btraffic;
-
- if (await _TiobonArticleServices.Update(model))
- {
- return Success(TiobonArticle?.bID.ObjToString());
- }
- }
- }
- return Failed("更新失败");
- }
-
-
-
- ///
- /// 删除博客
- ///
- ///
- ///
- [HttpDelete]
- [Authorize(Permissions.Name)]
- [Route("Delete")]
- public async Task> Delete(long id)
- {
- if (id > 0)
- {
- var TiobonArticle = await _TiobonArticleServices.QueryById(id);
- if (TiobonArticle == null)
- {
- return Failed("查询无数据");
- }
- TiobonArticle.IsDeleted = true;
- return await _TiobonArticleServices.Update(TiobonArticle) ? Success(TiobonArticle?.bID.ObjToString(), "删除成功") : Failed("删除失败");
- }
- return Failed("入参无效");
- }
- ///
- /// apache jemeter 压力测试
- /// 更新接口
- ///
- ///
- [HttpGet]
- [Route("ApacheTestUpdate")]
- public async Task> ApacheTestUpdate()
- {
- return Success(await _TiobonArticleServices.Update(new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}", bID = 1 }), "更新成功");
- }
-}
\ No newline at end of file
diff --git a/Tiobon.Core.Api/Controllers/CommonController.cs b/Tiobon.Core.Api/Controllers/CommonController.cs
index 66c4369e..e509d756 100644
--- a/Tiobon.Core.Api/Controllers/CommonController.cs
+++ b/Tiobon.Core.Api/Controllers/CommonController.cs
@@ -14,7 +14,6 @@ namespace Tiobon.Core.Controllers;
[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_System)]
public class CommonController : BaseApiController
{
- private readonly ILogger _logger;
private readonly ICommonServices _commonServices;
private readonly IHttpPollyHelper _httpPollyHelper;
@@ -24,13 +23,12 @@ public class CommonController : BaseApiController
///
///
///
- public CommonController(ILogger logger,
+ public CommonController(
ICommonServices commonServices,
IHttpPollyHelper httpPollyHelper)
{
_commonServices = commonServices;
_httpPollyHelper = httpPollyHelper;
- _logger = logger;
}
#region 获取菜单
diff --git a/Tiobon.Core.Api/Controllers/FileController.cs b/Tiobon.Core.Api/Controllers/FileController.cs
index f61c7d1b..a492f523 100644
--- a/Tiobon.Core.Api/Controllers/FileController.cs
+++ b/Tiobon.Core.Api/Controllers/FileController.cs
@@ -11,8 +11,6 @@ namespace Tiobon.Core.Controllers;
[Route("api/File"), ApiExplorerSettings(GroupName = Grouping.GroupName_System)]
public class FileController : BaseApiController
{
- public ITiobonArticleServices _TiobonArticleServices { get; set; }
- private readonly ILogger _logger;
///
/// 配置信息
///
@@ -22,14 +20,12 @@ public class FileController : BaseApiController
///
/// 构造函数
- ///
- ///
+ ///
///
///
///
- public FileController(ILogger logger, IConfiguration configuration, IWebHostEnvironment hostingEnvironment, IGhre_AttachmentServices ghre_AttachmentServices)
+ public FileController(IConfiguration configuration, IWebHostEnvironment hostingEnvironment, IGhre_AttachmentServices ghre_AttachmentServices)
{
- _logger = logger;
_configuration = configuration;
_hostingEnvironment = hostingEnvironment;
_ghre_AttachmentServices = ghre_AttachmentServices;
diff --git a/Tiobon.Core.Api/Filter/UseServiceDIAttribute.cs b/Tiobon.Core.Api/Filter/UseServiceDIAttribute.cs
index ff57d734..ccae8214 100644
--- a/Tiobon.Core.Api/Filter/UseServiceDIAttribute.cs
+++ b/Tiobon.Core.Api/Filter/UseServiceDIAttribute.cs
@@ -6,20 +6,17 @@ public class UseServiceDIAttribute : ActionFilterAttribute
{
protected readonly ILogger _logger;
- private readonly ITiobonArticleServices _TiobonArticleServices;
private readonly string _name;
- public UseServiceDIAttribute(ILogger logger, ITiobonArticleServices TiobonArticleServices, string Name = "")
+ public UseServiceDIAttribute(ILogger logger, string Name = "")
{
_logger = logger;
- _TiobonArticleServices = TiobonArticleServices;
_name = Name;
}
public override void OnActionExecuted(ActionExecutedContext context)
{
- var dd = _TiobonArticleServices.Query().Result;
_logger.LogInformation("测试自定义服务特性");
Console.WriteLine(_name);
base.OnActionExecuted(context);
diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml
index ca2afb6d..9fc6f950 100644
--- a/Tiobon.Core.Api/Tiobon.Core.xml
+++ b/Tiobon.Core.Api/Tiobon.Core.xml
@@ -156,89 +156,12 @@
-
-
- 博客管理
-
-
-
-
- 构造函数
-
-
-
-
-
-
- 获取博客列表【无权限】
-
-
-
-
-
-
-
-
-
- 获取博客详情
-
-
-
-
-
-
- 获取详情【无权限】
-
-
-
-
-
-
- 获取博客测试信息 v2版本
-
-
-
-
-
- 添加博客【无权限】
-
-
-
-
-
-
-
-
-
-
-
-
-
- 更新博客信息
-
-
-
-
-
-
- 删除博客
-
-
-
-
-
-
- apache jemeter 压力测试
- 更新接口
-
-
-
公共服务
-
+
构造函数
@@ -457,11 +380,10 @@
配置信息
-
+
构造函数
-
-
+
diff --git a/Tiobon.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs b/Tiobon.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs
index b2969c4e..d2acc6b8 100644
--- a/Tiobon.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs
+++ b/Tiobon.Core.Extensions/EventHandling/BlogQueryIntegrationEventHandler.cs
@@ -1,20 +1,16 @@
using Microsoft.Extensions.Logging;
using Tiobon.Core.Common;
using Tiobon.Core.EventBus.EventHandling;
-using Tiobon.Core.IServices;
namespace Tiobon.Core.EventBus;
public class TiobonQueryIntegrationEventHandler : IIntegrationEventHandler
{
- private readonly ITiobonArticleServices _TiobonArticleServices;
private readonly ILogger _logger;
public TiobonQueryIntegrationEventHandler(
- ITiobonArticleServices TiobonArticleServices,
ILogger logger)
{
- _TiobonArticleServices = TiobonArticleServices;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@@ -24,7 +20,6 @@ public class TiobonQueryIntegrationEventHandler : IIntegrationEventHandler
-{
- Task> GetTiobons();
- Task GetTiobonDetails(long id);
-
-}
diff --git a/Tiobon.Core.Services/BlogArticleServices.cs b/Tiobon.Core.Services/BlogArticleServices.cs
deleted file mode 100644
index 15ba5620..00000000
--- a/Tiobon.Core.Services/BlogArticleServices.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-namespace Tiobon.Core.Services;
-
-public class TiobonArticleServices : BaseServices, ITiobonArticleServices
-{
- AutoMapper.IMapper _mapper;
- public TiobonArticleServices(AutoMapper.IMapper mapper)
- {
- this._mapper = mapper;
- }
- ///
- /// 获取视图博客详情信息
- ///
- ///
- ///
- public async Task GetTiobonDetails(long id)
- {
- // 此处想获取上一条下一条数据,因此将全部数据list出来,有好的想法请提出
- //var Tiobonlist = await base.Query(a => a.IsDeleted==false, a => a.bID);
- var TiobonArticle = (await base.Query(a => a.bID == id && a.bcategory == "技术博文")).FirstOrDefault();
-
- TiobonViewModels models = null;
-
- if (TiobonArticle != null)
- {
- models = _mapper.Map(TiobonArticle);
-
- //要取下一篇和上一篇,以当前id开始,按id排序后top(2),而不用取出所有记录
- //这样在记录很多的时候也不会有多大影响
- var nextTiobons = await base.Query(a => a.bID >= id && a.IsDeleted == false && a.bcategory == "技术博文", 2, "bID");
- if (nextTiobons.Count == 2)
- {
- models.next = nextTiobons[1].btitle;
- models.nextID = nextTiobons[1].bID;
- }
- var prevTiobons = await base.Query(a => a.bID <= id && a.IsDeleted == false && a.bcategory == "技术博文", 2, "bID desc");
- if (prevTiobons.Count == 2)
- {
- models.previous = prevTiobons[1].btitle;
- models.previousID = prevTiobons[1].bID;
- }
-
- TiobonArticle.btraffic += 1;
- await base.Update(TiobonArticle, new List { "btraffic" });
- }
-
- return models;
-
- }
-
-
- ///
- /// 获取博客列表
- ///
- ///
- [Caching(AbsoluteExpiration = 10)]
- public async Task> GetTiobons()
- {
- var Tiobonlist = await base.Query(a => a.bID > 0, a => a.bID);
-
- return Tiobonlist;
-
- }
-}
diff --git a/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs b/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs
deleted file mode 100644
index b2154b59..00000000
--- a/Tiobon.Core.Tests/Controller_Test/BlogController_Should.cs
+++ /dev/null
@@ -1,179 +0,0 @@
-using Autofac;
-using Tiobon.Core.Controllers;
-using Tiobon.Core.IServices;
-using Tiobon.Core.Model;
-using Tiobon.Core.Model.Models;
-using Tiobon.Core.Model.ViewModels;
-using Microsoft.Extensions.Logging;
-using Moq;
-using System;
-using System.Collections.Generic;
-using Xunit;
-
-namespace Tiobon.Core.Tests
-{
- public class TiobonController_Should
- {
- Mock mockTiobonSev = new Mock();
- Mock> mockLogger = new Mock>();
- TiobonController TiobonController;
-
- private ITiobonArticleServices TiobonArticleServices;
- DI_Test dI_Test = new DI_Test();
-
-
-
- public TiobonController_Should()
- {
- mockTiobonSev.Setup(r => r.Query());
-
- var container = dI_Test.DICollections();
- TiobonArticleServices = container.Resolve();
- TiobonController = new TiobonController(mockLogger.Object);
- TiobonController._TiobonArticleServices = TiobonArticleServices;
- }
-
- [Fact]
- public void TestEntity()
- {
- TiobonArticle TiobonArticle = new TiobonArticle();
-
- Assert.True(TiobonArticle.bID >= 0);
- }
-
- [Fact]
- public async void Get_Tiobon_Page_Test()
- {
- ServiceResult> Tiobons = await TiobonController.Get(1, 1, "技术博文", "");
- Assert.NotNull(Tiobons);
- Assert.NotNull(Tiobons.Data);
- Assert.True(Tiobons.Data.dataCount >= 0);
- }
-
- [Fact]
- public async void Get_Tiobon_Test()
- {
- ServiceResult TiobonVo = await TiobonController.Get(1.ObjToLong());
-
- Assert.NotNull(TiobonVo);
- }
-
- [Fact]
- public async void Get_Tiobon_For_Nuxt_Test()
- {
- ServiceResult TiobonVo = await TiobonController.DetailNuxtNoPer(1);
-
- Assert.NotNull(TiobonVo);
- }
-
- [Fact]
- public async void Get_Go_Url_Test()
- {
- object urlAction = await TiobonController.GoUrl(1);
-
- Assert.NotNull(urlAction);
- }
-
- [Fact]
- public async void Get_Tiobon_By_Type_For_MVP_Test()
- {
- ServiceResult> Tiobons = await TiobonController.GetTiobonsByTypesForMVP("技术博文");
-
- Assert.NotNull(Tiobons);
- Assert.True(Tiobons.Success);
- Assert.NotNull(Tiobons.Data);
- Assert.True(Tiobons.Data.Count >= 0);
- }
-
- [Fact]
- public async void Get_Tiobon_By_Id_For_MVP_Test()
- {
- ServiceResult Tiobon = await TiobonController.GetTiobonByIdForMVP(1);
-
- Assert.NotNull(Tiobon);
- Assert.True(Tiobon.Success);
- Assert.NotNull(Tiobon.Data);
- }
-
- [Fact]
- public async void PostTest()
- {
- TiobonArticle TiobonArticle = new TiobonArticle()
- {
- bCreateTime = DateTime.Now,
- bUpdateTime = DateTime.Now,
- btitle = "xuint :test controller addEntity",
- bcontent = "xuint :test controller addEntity. this is content.this is content."
- };
-
- var res = await TiobonController.Post(TiobonArticle);
-
- Assert.True(res.Success);
-
- var data = res.Data;
-
- Assert.NotNull(data);
- }
-
- [Fact]
- public async void Post_Insert_For_MVP_Test()
- {
- TiobonArticle TiobonArticle = new TiobonArticle()
- {
- bCreateTime = DateTime.Now,
- bUpdateTime = DateTime.Now,
- btitle = "xuint :test controller addEntity",
- bcontent = "xuint :test controller addEntity. this is content.this is content."
- };
-
- var res = await TiobonController.AddForMVP(TiobonArticle);
-
- Assert.True(res.Success);
-
- var data = res.Data;
-
- Assert.NotNull(data);
- }
-
- [Fact]
- public async void Put_Test()
- {
- TiobonArticle TiobonArticle = new TiobonArticle()
- {
- bID = 1,
- bCreateTime = DateTime.Now,
- bUpdateTime = DateTime.Now,
- btitle = "xuint put :test controller addEntity",
- bcontent = "xuint put :test controller addEntity. this is content.this is content."
- };
-
- var res = await TiobonController.Put(TiobonArticle);
-
- Assert.True(res.Success);
-
- var data = res.Data;
-
- Assert.NotNull(data);
- }
-
- [Fact]
- public async void Delete_Test()
- {
- var res = await TiobonController.Delete(99);
-
- Assert.False(res.Success);
-
- var data = res.Data;
-
- Assert.Null(data);
- }
-
- [Fact]
- public async void Apache_Update_Test()
- {
- var res = await TiobonController.ApacheTestUpdate();
-
- Assert.True(res.Success);
- }
- }
-}
diff --git a/Tiobon.Core.Tests/Service_Test/BlogArticleService_Should.cs b/Tiobon.Core.Tests/Service_Test/BlogArticleService_Should.cs
deleted file mode 100644
index f2905312..00000000
--- a/Tiobon.Core.Tests/Service_Test/BlogArticleService_Should.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using Tiobon.Core.IServices;
-using Tiobon.Core.Model.Models;
-using Xunit;
-using System;
-using System.Linq;
-using Autofac;
-
-namespace Tiobon.Core.Tests
-{
- public class TiobonArticleService_Should
- {
-
- private ITiobonArticleServices TiobonArticleServices;
- DI_Test dI_Test = new DI_Test();
-
-
- public TiobonArticleService_Should()
- {
- //mockTiobonRep.Setup(r => r.Query());
-
- var container = dI_Test.DICollections();
-
- TiobonArticleServices = container.Resolve();
-
- }
-
-
- [Fact]
- public void TiobonArticleServices_Test()
- {
- Assert.NotNull(TiobonArticleServices);
- }
-
-
- [Fact]
- public async void Get_Tiobons_Test()
- {
- var data = await TiobonArticleServices.GetTiobons();
-
- Assert.True(data.Any());
- }
-
- [Fact]
- public async void Add_Tiobon_Test()
- {
- TiobonArticle TiobonArticle = new TiobonArticle()
- {
- bCreateTime = DateTime.Now,
- bUpdateTime = DateTime.Now,
- btitle = "xuint test title",
- bcontent = "xuint test content",
- bsubmitter = "xuint test submitter",
- };
-
- var BId = await TiobonArticleServices.Add(TiobonArticle);
-
- Assert.True(BId > 0);
- }
-
- [Fact]
- public async void Delete_Tiobon_Test()
- {
- Add_Tiobon_Test();
-
- var deleteModel = (await TiobonArticleServices.Query(d => d.btitle == "xuint test title")).FirstOrDefault();
-
- Assert.NotNull(deleteModel);
-
- var IsDel = await TiobonArticleServices.Delete(deleteModel);
-
- Assert.True(IsDel);
- }
- }
-}
diff --git a/Tiobon.Core.Tests/Tiobon.Core.Tests.csproj b/Tiobon.Core.Tests/Tiobon.Core.Tests.csproj
index d6d38e07..0befef43 100644
--- a/Tiobon.Core.Tests/Tiobon.Core.Tests.csproj
+++ b/Tiobon.Core.Tests/Tiobon.Core.Tests.csproj
@@ -46,6 +46,10 @@
+
+
+
+