@ -1,35 +1,35 @@
using System.Linq.Expressions ;
using System.Text.RegularExpressions ;
using Blog .Core.Common.Helper;
using Blog .Core.IServices;
using Blog .Core.Model;
using Blog .Core.Model.Models;
using Blog .Core.Model.ViewModels;
using Blog .Core.SwaggerHelper;
using Tiobon .Core.Common.Helper;
using Tiobon .Core.IServices;
using Tiobon .Core.Model;
using Tiobon .Core.Model.Models;
using Tiobon .Core.Model.ViewModels;
using Tiobon .Core.SwaggerHelper;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Mvc ;
using Serilog ;
using StackExchange.Profiling ;
using static Blog . Core . Extensions . CustomApiVersion ;
using static Tiobon . Core . Extensions . CustomApiVersion ;
namespace Blog .Core.Controllers
namespace Tiobon .Core.Controllers
{
/// <summary>
/// 博客管理
/// </summary>
[Produces("application/json")]
[Route("api/Blog ")]
public class Blog Controller : BaseApiController
[Route("api/Tiobon ")]
public class Tiobon Controller : BaseApiController
{
public IBlogArticleServices _ blog ArticleServices { get ; set ; }
private readonly ILogger < Blog Controller> _l ogger ;
public ITiobonArticleServices _ Tiobon ArticleServices { get ; set ; }
private readonly ILogger < Tiobon Controller> _l ogger ;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="logger"></param>
///
public Blog Controller( ILogger < Blog Controller> logger )
public Tiobon Controller( ILogger < Tiobon Controller> logger )
{
_l ogger = logger ;
}
@ -44,7 +44,7 @@ namespace Blog.Core.Controllers
/// <param name="key"></param>
/// <returns></returns>
[HttpGet]
public async Task < MessageModel < PageModel < Blog Article> > > Get ( int id , int page = 1 , string bcategory = "技术博文" , string key = "" )
public async Task < MessageModel < PageModel < Tiobon Article> > > Get ( int id , int page = 1 , string bcategory = "技术博文" , string key = "" )
{
int intPageSize = 6 ;
if ( string . IsNullOrEmpty ( key ) | | string . IsNullOrWhiteSpace ( key ) )
@ -52,13 +52,13 @@ namespace Blog.Core.Controllers
key = "" ;
}
Expression < Func < Blog Article, bool > > whereExpression = a = > ( a . bcategory = = bcategory & & a . IsDeleted = = false ) & & ( ( a . btitle ! = null & & a . btitle . Contains ( key ) ) | | ( a . bcontent ! = null & & a . bcontent . Contains ( key ) ) ) ;
Expression < Func < Tiobon Article, bool > > whereExpression = a = > ( a . bcategory = = bcategory & & a . IsDeleted = = false ) & & ( ( a . btitle ! = null & & a . btitle . Contains ( key ) ) | | ( a . bcontent ! = null & & a . bcontent . Contains ( key ) ) ) ;
var pageModelBlog = await _ blog ArticleServices. QueryPage ( whereExpression , page , intPageSize , " bID desc " ) ;
var pageModelTiobon = await _ Tiobon ArticleServices. QueryPage ( whereExpression , page , intPageSize , " bID desc " ) ;
using ( MiniProfiler . Current . Step ( "获取成功后,开始处理最终数据" ) )
{
foreach ( var item in pageModelBlog . data )
foreach ( var item in pageModelTiobon . data )
{
if ( ! string . IsNullOrEmpty ( item . bcontent ) )
{
@ -72,7 +72,7 @@ namespace Blog.Core.Controllers
}
}
return SuccessPage ( pageModelBlog ) ;
return SuccessPage ( pageModelTiobon ) ;
}
@ -82,11 +82,11 @@ namespace Blog.Core.Controllers
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
//[Authorize(Policy = "Scope_Blog Module_Policy")]
//[Authorize(Policy = "Scope_Tiobon Module_Policy")]
[Authorize]
public async Task < MessageModel < Blog ViewModels> > Get ( long id )
public async Task < MessageModel < Tiobon ViewModels> > Get ( long id )
{
return Success ( await _ blogArticleServices . GetBlog Details( id ) ) ;
return Success ( await _ TiobonArticleServices . GetTiobon Details( id ) ) ;
}
@ -97,25 +97,25 @@ namespace Blog.Core.Controllers
/// <returns></returns>
[HttpGet]
[Route("DetailNuxtNoPer")]
public async Task < MessageModel < Blog ViewModels> > DetailNuxtNoPer ( long id )
public async Task < MessageModel < Tiobon ViewModels> > DetailNuxtNoPer ( long id )
{
_l ogger . LogInformation ( "xxxxxxxxxxxxxxxxxxx" ) ;
Log . Information ( "yyyyyyyyyyyyyyyyy" ) ;
return Success ( await _ blogArticleServices . GetBlog Details( id ) ) ;
return Success ( await _ TiobonArticleServices . GetTiobon Details( id ) ) ;
}
[HttpGet]
[Route("GoUrl")]
public async Task < IActionResult > GoUrl ( long id = 0 )
{
var response = await _ blog ArticleServices. QueryById ( id ) ;
var response = await _ Tiobon ArticleServices. 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 _ blog ArticleServices. Update ( response ) ;
await _ Tiobon ArticleServices. Update ( response ) ;
return Redirect ( response . bsubmitter ) ;
}
@ -125,26 +125,26 @@ namespace Blog.Core.Controllers
}
[HttpGet]
[Route("GetBlog sByTypesForMVP")]
public async Task < MessageModel < List < Blog Article> > > GetBlog sByTypesForMVP ( string types = "" , int id = 0 )
[Route("GetTiobon sByTypesForMVP")]
public async Task < MessageModel < List < Tiobon Article> > > GetTiobon sByTypesForMVP ( string types = "" , int id = 0 )
{
if ( types . IsNotEmptyOrNull ( ) )
{
var blog s = await _ blog ArticleServices. Query ( d = > d . bcategory ! = null & & types . Contains ( d . bcategory ) & & d . IsDeleted = = false , d = > d . bID , false ) ;
return Success ( blog s) ;
var Tiobon s = await _ Tiobon ArticleServices. Query ( d = > d . bcategory ! = null & & types . Contains ( d . bcategory ) & & d . IsDeleted = = false , d = > d . bID , false ) ;
return Success ( Tiobon s) ;
}
return Success ( new List < Blog Article> ( ) { } ) ;
return Success ( new List < Tiobon Article> ( ) { } ) ;
}
[HttpGet]
[Route("GetBlog ByIdForMVP")]
public async Task < MessageModel < BlogArticle > > GetBlog ByIdForMVP( long id = 0 )
[Route("GetTiobon ByIdForMVP")]
public async Task < MessageModel < TiobonArticle > > GetTiobon ByIdForMVP( long id = 0 )
{
if ( id > 0 )
{
return Success ( await _ blog ArticleServices. QueryById ( id ) ) ;
return Success ( await _ Tiobon ArticleServices. QueryById ( id ) ) ;
}
return Success ( new Blog Article( ) ) ;
return Success ( new Tiobon Article( ) ) ;
}
/// <summary>
@ -155,11 +155,11 @@ namespace Blog.Core.Controllers
////MVC自带特性 对 api 进行组管理
//[ApiExplorerSettings(GroupName = "v2")]
////路径 如果以 / 开头,表示绝对路径,反之相对 controller 的想u地路径
//[Route("/api/v2/blog/Blog test")]
//[Route("/api/v2/Tiobon/Tiobon test")]
//和上边的版本控制以及路由地址都是一样的
[CustomRoute(ApiVersions.V2, "Blog test")]
public MessageModel < string > V2_Blog test ( )
[CustomRoute(ApiVersions.V2, "Tiobon test")]
public MessageModel < string > V2_Tiobon test ( )
{
return Success < string > ( "我是第二版的博客信息" ) ;
}
@ -167,21 +167,21 @@ namespace Blog.Core.Controllers
/// <summary>
/// 添加博客【无权限】
/// </summary>
/// <param name="blog Article"></param>
/// <param name="Tiobon Article"></param>
/// <returns></returns>
[HttpPost]
//[Authorize(Policy = "Scope_Blog Module_Policy")]
//[Authorize(Policy = "Scope_Tiobon Module_Policy")]
[Authorize]
public async Task < MessageModel < string > > Post ( [ FromBody ] BlogArticle blog Article)
public async Task < MessageModel < string > > Post ( [ FromBody ] TiobonArticle Tiobon Article)
{
if ( blog Article. btitle . Length > 5 & & blog Article. bcontent . Length > 5 0 )
if ( Tiobon Article. btitle . Length > 5 & & Tiobon Article. bcontent . Length > 5 0 )
{
blog Article. bCreateTime = DateTime . Now ;
blog Article. bUpdateTime = DateTime . Now ;
blog Article. IsDeleted = false ;
blog Article. bcategory = "技术博文" ;
var id = ( await _ blog ArticleServices. Add ( blog Article) ) ;
Tiobon Article. bCreateTime = DateTime . Now ;
Tiobon Article. bUpdateTime = DateTime . Now ;
Tiobon Article. IsDeleted = false ;
Tiobon Article. bcategory = "技术博文" ;
var id = ( await _ Tiobon ArticleServices. Add ( Tiobon Article) ) ;
return id > 0 ? Success < string > ( id . ObjToString ( ) ) : Failed ( "添加失败" ) ;
}
else
@ -194,45 +194,45 @@ namespace Blog.Core.Controllers
/// <summary>
///
/// </summary>
/// <param name="blog Article"></param>
/// <param name="Tiobon Article"></param>
/// <returns></returns>
[HttpPost]
[Route("AddForMVP")]
[Authorize(Permissions.Name)]
public async Task < MessageModel < string > > AddForMVP ( [ FromBody ] BlogArticle blog Article)
public async Task < MessageModel < string > > AddForMVP ( [ FromBody ] TiobonArticle Tiobon Article)
{
blog Article. bCreateTime = DateTime . Now ;
blog Article. bUpdateTime = DateTime . Now ;
blog Article. IsDeleted = false ;
var id = ( await _ blog ArticleServices. Add ( blog Article) ) ;
Tiobon Article. bCreateTime = DateTime . Now ;
Tiobon Article. bUpdateTime = DateTime . Now ;
Tiobon Article. IsDeleted = false ;
var id = ( await _ Tiobon ArticleServices. Add ( Tiobon Article) ) ;
return id > 0 ? Success < string > ( id . ObjToString ( ) ) : Failed ( "添加失败" ) ;
}
/// <summary>
/// 更新博客信息
/// </summary>
/// <param name="Blog Article"></param>
/// <param name="Tiobon Article"></param>
/// <returns></returns>
// PUT: api/User/5
[HttpPut]
[Route("Update")]
[Authorize(Permissions.Name)]
public async Task < MessageModel < string > > Put ( [ FromBody ] BlogArticle Blog Article)
public async Task < MessageModel < string > > Put ( [ FromBody ] TiobonArticle Tiobon Article)
{
if ( Blog Article ! = null & & Blog Article. bID > 0 )
if ( Tiobon Article ! = null & & Tiobon Article. bID > 0 )
{
var model = await _ blog ArticleServices. QueryById ( Blog Article. bID ) ;
var model = await _ Tiobon ArticleServices. QueryById ( Tiobon Article. bID ) ;
if ( model ! = null )
{
model . btitle = Blog Article. btitle ;
model . bcategory = Blog Article. bcategory ;
model . bsubmitter = Blog Article. bsubmitter ;
model . bcontent = Blog Article. bcontent ;
model . btraffic = Blog Article. btraffic ;
model . btitle = Tiobon Article. btitle ;
model . bcategory = Tiobon Article. bcategory ;
model . bsubmitter = Tiobon Article. bsubmitter ;
model . bcontent = Tiobon Article. bcontent ;
model . btraffic = Tiobon Article. btraffic ;
if ( await _ blog ArticleServices. Update ( model ) )
if ( await _ Tiobon ArticleServices. Update ( model ) )
{
return Success < string > ( Blog Article? . bID . ObjToString ( ) ) ;
return Success < string > ( Tiobon Article? . bID . ObjToString ( ) ) ;
}
}
}
@ -253,13 +253,13 @@ namespace Blog.Core.Controllers
{
if ( id > 0 )
{
var blog Article = await _ blog ArticleServices. QueryById ( id ) ;
if ( blog Article = = null )
var Tiobon Article = await _ Tiobon ArticleServices. QueryById ( id ) ;
if ( Tiobon Article = = null )
{
return Failed ( "查询无数据" ) ;
}
blog Article. IsDeleted = true ;
return await _ blog ArticleServices. Update ( blog Article) ? Success ( blog Article? . bID . ObjToString ( ) , "删除成功" ) : Failed ( "删除失败" ) ;
Tiobon Article. IsDeleted = true ;
return await _ Tiobon ArticleServices. Update ( Tiobon Article) ? Success ( Tiobon Article? . bID . ObjToString ( ) , "删除成功" ) : Failed ( "删除失败" ) ;
}
return Failed ( "入参无效" ) ;
}
@ -272,7 +272,7 @@ namespace Blog.Core.Controllers
[Route("ApacheTestUpdate")]
public async Task < MessageModel < bool > > ApacheTestUpdate ( )
{
return Success ( await _ blog ArticleServices. Update ( new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}" , bID = 1 } ) , "更新成功" ) ;
return Success ( await _ Tiobon ArticleServices. Update ( new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}" , bID = 1 } ) , "更新成功" ) ;
}
}
}