mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 10:29:50 +08:00
【新增】WebApi文章Controller新增【获取最新文章】【获取文章栏目】两个接口
This commit is contained in:
@@ -11,13 +11,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Auth.HttpContextUser;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Essensoft.Paylink.Alipay.Domain;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
@@ -30,26 +28,20 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
[ApiController]
|
||||
public class ArticleController : ControllerBase
|
||||
{
|
||||
|
||||
private IHttpContextUser _user;
|
||||
private readonly ICoreCmsArticleServices _articleServices;
|
||||
private readonly ICoreCmsArticleTypeServices _articleTypeServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="articleServices"></param>
|
||||
/// <param name="articleTypeServices"></param>
|
||||
public ArticleController(IHttpContextUser user, ICoreCmsArticleServices articleServices, ICoreCmsArticleTypeServices articleTypeServices)
|
||||
public ArticleController(ICoreCmsArticleServices articleServices, ICoreCmsArticleTypeServices articleTypeServices)
|
||||
{
|
||||
_user = user;
|
||||
_articleServices = articleServices;
|
||||
_articleTypeServices = articleTypeServices;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 获取通知列表
|
||||
/// <summary>
|
||||
/// 获取通知列表
|
||||
@@ -70,6 +62,41 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取文章栏目
|
||||
/// <summary>
|
||||
/// 获取文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetArticleClassify()
|
||||
{
|
||||
var jm = new WebApiCallBack
|
||||
{
|
||||
status = true,
|
||||
data = await _articleTypeServices.QueryListByClauseAsync(p => p.id > 0, p => p.sort, OrderByType.Desc, true, true)
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取最新文章
|
||||
/// <summary>
|
||||
/// 获取最新文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetNewArticle([FromBody] FMGetNewArticle entity)
|
||||
{
|
||||
var jm = new WebApiCallBack
|
||||
{
|
||||
status = true,
|
||||
data = await _articleServices.QueryListAsync(p => p.isPub == true, p => p.createTime, OrderByType.Desc, entity.num)
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取文章列表
|
||||
/// <summary>
|
||||
@@ -81,10 +108,10 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var articleType = await _articleTypeServices.QueryAsync();
|
||||
var articleType = await _articleTypeServices.QueryAsync(true, true);
|
||||
if (articleType.Any())
|
||||
{
|
||||
var where = PredicateBuilder.True<Model.Entities.CoreCmsArticle>();
|
||||
var where = PredicateBuilder.True<CoreCmsArticle>();
|
||||
if (entity.id > 0)
|
||||
{
|
||||
where = where.And(p => p.isDel == false && p.typeId == entity.id);
|
||||
@@ -99,7 +126,10 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
list,
|
||||
articleType,
|
||||
count = list.TotalCount
|
||||
count = list.TotalCount,
|
||||
list.HasNextPage,
|
||||
list.HasPreviousPage,
|
||||
list.TotalPages
|
||||
};
|
||||
}
|
||||
else
|
||||
@@ -117,7 +147,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取单个文章内容
|
||||
/// <summary>
|
||||
/// 获取单个文章内容
|
||||
/// </summary>
|
||||
@@ -138,6 +168,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
jm.data = model;
|
||||
return jm;
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,11 +210,23 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.brandId))
|
||||
{
|
||||
var brandId = obj.brandId.ObjectToInt(0);
|
||||
if (brandId > 0)
|
||||
if (obj.brandId.Contains(","))
|
||||
{
|
||||
where = where.And(p => p.brandId == brandId);
|
||||
var brandIdsIntArray = CommonHelper.StringToIntArray(obj.brandId);
|
||||
if (brandIdsIntArray.Any())
|
||||
{
|
||||
where = where.And(p => brandIdsIntArray.Contains(p.brandId));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var brandId = obj.brandId.ObjectToInt(0);
|
||||
if (brandId > 0)
|
||||
{
|
||||
where = where.And(p => p.brandId == brandId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.labelId))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user