初始刷
This commit is contained in:
177
ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs
Normal file
177
ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs
Normal file
@@ -0,0 +1,177 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Content;
|
||||
using ZR.Model.Content.Dto;
|
||||
using ZR.Service.Content.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章目录Controller
|
||||
/// </summary>
|
||||
[Route("article/ArticleCategory")]
|
||||
[ApiExplorerSettings(GroupName = "article")]
|
||||
public class ArticleCategoryController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章目录接口
|
||||
/// </summary>
|
||||
private readonly IArticleCategoryService _ArticleCategoryService;
|
||||
|
||||
public ArticleCategoryController(IArticleCategoryService ArticleCategoryService)
|
||||
{
|
||||
_ArticleCategoryService = ArticleCategoryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章目录列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章目录列表树
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("treeList")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetTreeList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章目录详情
|
||||
/// </summary>
|
||||
/// <param name="CategoryId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{CategoryId}")]
|
||||
[AllowAnonymous]
|
||||
//[ActionPermissionFilter(Permission = "articlecategory:query")]
|
||||
public IActionResult GetArticleCategory(int CategoryId)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询目录分类
|
||||
/// </summary>
|
||||
/// <param name="categoryType"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("type{categoryType}")]
|
||||
//[ActionPermissionFilter(Permission = "articlecategory:query")]
|
||||
public IActionResult GetArticleCategoryByType(int categoryType)
|
||||
{
|
||||
var response = _ArticleCategoryService.GetFirst(x => x.CategoryType == categoryType);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加文章目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:add")]
|
||||
[Log(Title = "文章目录", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext);
|
||||
var response = _ArticleCategoryService.AddArticleCategory(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新文章目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:edit")]
|
||||
[Log(Title = "文章目录", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext);
|
||||
var response = _ArticleCategoryService.Update(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文章目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:delete")]
|
||||
[Log(Title = "文章目录", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult DeleteArticleCategory(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _ArticleCategoryService.Delete(idsArr);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出文章目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "文章目录", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "articlecategory:export")]
|
||||
public IActionResult Export([FromQuery] ArticleCategoryQueryDto parm)
|
||||
{
|
||||
parm.PageSize = 10000;
|
||||
var list = _ArticleCategoryService.GetList(parm).Result;
|
||||
|
||||
string sFileName = ExportExcel(list, "ArticleCategory", "文章目录");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文章目录,前端没用到
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("CategoryList")]
|
||||
public IActionResult CategoryList()
|
||||
{
|
||||
var response = _ArticleCategoryService.GetAll();
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存排序
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "articlecategory:edit")]
|
||||
[HttpGet("ChangeSort")]
|
||||
[Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult ChangeSort(int id = 0, int value = 0)
|
||||
{
|
||||
if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
||||
var response = _ArticleCategoryService.Update(w => w.CategoryId == id, it => new ArticleCategory ()
|
||||
{
|
||||
CategoryId = id,
|
||||
OrderNum = value
|
||||
});
|
||||
return ToResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
181
ZR.Admin.WebApi/Controllers/Article/ArticleController.cs
Normal file
181
ZR.Admin.WebApi/Controllers/Article/ArticleController.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Content;
|
||||
using ZR.Model.Content.Dto;
|
||||
using ZR.Service.Content.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 内容管理
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("article")]
|
||||
[ApiExplorerSettings(GroupName = "article")]
|
||||
public class ArticleController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章接口
|
||||
/// </summary>
|
||||
private readonly IArticleService _ArticleService;
|
||||
private readonly IArticleCategoryService _ArticleCategoryService;
|
||||
|
||||
public ArticleController(
|
||||
IArticleService ArticleService,
|
||||
IArticleCategoryService articleCategoryService)
|
||||
{
|
||||
_ArticleService = ArticleService;
|
||||
_ArticleCategoryService = articleCategoryService;
|
||||
_ArticleService = ArticleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "system:article:list")]
|
||||
public IActionResult Query([FromQuery] ArticleQueryDto parm)
|
||||
{
|
||||
var response = _ArticleService.GetList(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容批量审核通过
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("pass/{ids}")]
|
||||
[ActionPermissionFilter(Permission = "article:audit")]
|
||||
[Log(Title = "内容审核", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult PassedMonents(string ids)
|
||||
{
|
||||
long[] idsArr = Tools.SpitLongArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"审核通过失败Id 不能为空")); }
|
||||
|
||||
return ToResponse(_ArticleService.Passed(idsArr));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内容批量审核拒绝
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("reject/{ids}")]
|
||||
[ActionPermissionFilter(Permission = "article:audit")]
|
||||
[Log(Title = "内容审核", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult RejectMonents(string ids, string reason = "")
|
||||
{
|
||||
long[] idsArr = Tools.SpitLongArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"審核拒绝失败Id 不能为空")); }
|
||||
|
||||
int result = _ArticleService.Reject(reason, idsArr);
|
||||
return ToResponse(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询我的文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("mylist")]
|
||||
public IActionResult QueryMyList([FromQuery] ArticleQueryDto parm)
|
||||
{
|
||||
parm.UserId = HttpContext.GetUId();
|
||||
var response = _ArticleService.GetMyList(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章详情
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
var model = _ArticleService.GetArticle(id, userId);
|
||||
|
||||
ApiResult apiResult = ApiResult.Success(model);
|
||||
|
||||
return ToResponse(apiResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("add")]
|
||||
[ActionPermissionFilter(Permission = "system:article:add")]
|
||||
//[Log(Title = "发布文章", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] ArticleDto parm)
|
||||
{
|
||||
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
||||
addModel.AuthorName = HttpContext.GetName();
|
||||
addModel.UserId = HttpContext.GetUId();
|
||||
addModel.UserIP = HttpContext.GetClientUserIp();
|
||||
addModel.Location = HttpContextExtension.GetIpInfo(addModel.UserIP);
|
||||
addModel.AuditStatus = Model.Enum.AuditStatusEnum.Passed;
|
||||
|
||||
return SUCCESS(_ArticleService.InsertReturnIdentity(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
[ActionPermissionFilter(Permission = "system:article:update")]
|
||||
//[Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] ArticleDto parm)
|
||||
{
|
||||
parm.AuthorName = HttpContext.GetName();
|
||||
var modal = parm.Adapt<Article>().ToUpdate(HttpContext);
|
||||
var response = _ArticleService.UpdateArticle(modal);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 置顶
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("top")]
|
||||
[ActionPermissionFilter(Permission = "system:article:update")]
|
||||
[Log(Title = "置顶文章", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Top([FromBody] Article parm)
|
||||
{
|
||||
var response = _ArticleService.TopArticle(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否公开
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("changePublic")]
|
||||
[ActionPermissionFilter(Permission = "system:article:update")]
|
||||
[Log(Title = "是否公开", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult ChangePublic([FromBody] Article parm)
|
||||
{
|
||||
var response = _ArticleService.ChangeArticlePublic(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文章
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id}")]
|
||||
[ActionPermissionFilter(Permission = "system:article:delete")]
|
||||
[Log(Title = "文章删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int id = 0)
|
||||
{
|
||||
var response = _ArticleService.Delete(id);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
122
ZR.Admin.WebApi/Controllers/Article/ArticleTopicController.cs
Normal file
122
ZR.Admin.WebApi/Controllers/Article/ArticleTopicController.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Content;
|
||||
using ZR.Model.Content.Dto;
|
||||
using ZR.Service.Content.IService;
|
||||
|
||||
//创建时间:2024-04-29
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章话题
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[ApiExplorerSettings(GroupName = "article")]
|
||||
[Route("article/ArticleTopic")]
|
||||
public class ArticleTopicController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章话题接口
|
||||
/// </summary>
|
||||
private readonly IArticleTopicService _ArticleTopicService;
|
||||
|
||||
public ArticleTopicController(IArticleTopicService ArticleTopicService)
|
||||
{
|
||||
_ArticleTopicService = ArticleTopicService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章话题列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "articletopic:list")]
|
||||
public IActionResult QueryArticleTopic([FromQuery] ArticleTopicQueryDto parm)
|
||||
{
|
||||
var response = _ArticleTopicService.GetList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章话题详情
|
||||
/// </summary>
|
||||
/// <param name="TopicId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{TopicId}")]
|
||||
[ActionPermissionFilter(Permission = "articletopic:query")]
|
||||
public IActionResult GetArticleTopic(long TopicId)
|
||||
{
|
||||
var response = _ArticleTopicService.GetInfo(TopicId);
|
||||
|
||||
var info = response.Adapt<ArticleTopicDto>();
|
||||
return SUCCESS(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加文章话题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "articletopic:add")]
|
||||
[Log(Title = "文章话题", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult AddArticleTopic([FromBody] ArticleTopicDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<ArticleTopic>().ToCreate(HttpContext);
|
||||
|
||||
var response = _ArticleTopicService.AddArticleTopic(modal);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新文章话题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "articletopic:edit")]
|
||||
[Log(Title = "文章话题", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult UpdateArticleTopic([FromBody] ArticleTopicDto parm)
|
||||
{
|
||||
var modal = parm.Adapt<ArticleTopic>().ToUpdate(HttpContext);
|
||||
var response = _ArticleTopicService.UpdateArticleTopic(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文章话题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("delete/{ids}")]
|
||||
[ActionPermissionFilter(Permission = "articletopic:delete")]
|
||||
[Log(Title = "文章话题", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult DeleteArticleTopic([FromRoute] string ids)
|
||||
{
|
||||
var idArr = Tools.SplitAndConvert<long>(ids);
|
||||
|
||||
return ToResponse(_ArticleTopicService.Delete(idArr));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出文章话题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "文章话题", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "articletopic:export")]
|
||||
public IActionResult Export([FromQuery] ArticleTopicQueryDto parm)
|
||||
{
|
||||
parm.PageNum = 1;
|
||||
parm.PageSize = 100000;
|
||||
var list = _ArticleTopicService.ExportList(parm).Result;
|
||||
if (list == null || list.Count <= 0)
|
||||
{
|
||||
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
|
||||
}
|
||||
var result = ExportExcelMini(list, "文章话题", "文章话题");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
232
ZR.Admin.WebApi/Controllers/Article/FrontArticleController.cs
Normal file
232
ZR.Admin.WebApi/Controllers/Article/FrontArticleController.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Content;
|
||||
using ZR.Model.Content.Dto;
|
||||
using ZR.Service.Content.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 内容管理前端接口
|
||||
/// </summary>
|
||||
[Route("front/article")]
|
||||
[ApiExplorerSettings(GroupName = "article")]
|
||||
[Verify]
|
||||
public class FrontArticleController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章接口
|
||||
/// </summary>
|
||||
private readonly IArticleService _ArticleService;
|
||||
private readonly IArticleCategoryService _ArticleCategoryService;
|
||||
private readonly IArticlePraiseService _ArticlePraiseService;
|
||||
private readonly ISysUserService _SysUserService;
|
||||
private readonly IArticleTopicService _ArticleTopicService;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ArticleService"></param>
|
||||
/// <param name="articleCategoryService"></param>
|
||||
/// <param name="articlePraiseService"></param>
|
||||
/// <param name="sysUserService"></param>
|
||||
/// <param name="articleTopicService"></param>
|
||||
public FrontArticleController(
|
||||
IArticleService ArticleService,
|
||||
IArticleCategoryService articleCategoryService,
|
||||
IArticlePraiseService articlePraiseService,
|
||||
ISysUserService sysUserService,
|
||||
IArticleTopicService articleTopicService)
|
||||
{
|
||||
_ArticleService = ArticleService;
|
||||
_ArticleCategoryService = articleCategoryService;
|
||||
_ArticleService = ArticleService;
|
||||
_ArticlePraiseService = articlePraiseService;
|
||||
_SysUserService = sysUserService;
|
||||
_ArticleTopicService = articleTopicService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前台查询文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("homeList")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult QueryHomeList([FromQuery] ArticleQueryDto parm)
|
||||
{
|
||||
parm.UserId = HttpContext.GetUId();
|
||||
var response = _ArticleService.GetArticleList(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询最新文章列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("newList")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult QueryNew()
|
||||
{
|
||||
var predicate = Expressionable.Create<Article>();
|
||||
predicate = predicate.And(m => m.Status == "1");
|
||||
predicate = predicate.And(m => m.IsPublic == 1);
|
||||
predicate = predicate.And(m => m.ArticleType == 0);
|
||||
predicate = predicate.And(m => m.AuditStatus == Model.Enum.AuditStatusEnum.Passed);
|
||||
|
||||
var response = _ArticleService.Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.Includes(x => x.ArticleCategoryNav) //填充子对象
|
||||
.Take(10)
|
||||
.OrderBy(f => f.UpdateTime, OrderByType.Desc).ToList();
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 点赞
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="authorId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("praise/{id}")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult Praise(int id = 0, long authorId = 0)
|
||||
{
|
||||
ArticlePraise addModel = new()
|
||||
{
|
||||
UserId = HttpContext.GetUId(),
|
||||
UserIP = HttpContext.GetClientUserIp(),
|
||||
ArticleId = id,
|
||||
ToUserId = authorId
|
||||
};
|
||||
addModel.Location = HttpContextExtension.GetIpInfo(addModel.UserIP);
|
||||
|
||||
return SUCCESS(_ArticlePraiseService.Praise(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 置顶
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("top")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult Top([FromBody] Article parm)
|
||||
{
|
||||
var response = _ArticleService.TopArticle(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改可见范围
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("changePublic")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult ChangePublic([FromBody] Article parm)
|
||||
{
|
||||
if (parm == null) { return ToResponse(ResultCode.CUSTOM_ERROR); }
|
||||
var userId = HttpContext.GetUId();
|
||||
if (userId != parm.UserId)
|
||||
{
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "操作失败");
|
||||
}
|
||||
var response = _ArticleService.ChangeArticlePublic(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改评论权限
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("changeComment")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult ChangeComment([FromBody] Article parm)
|
||||
{
|
||||
if (parm == null) { return ToResponse(ResultCode.CUSTOM_ERROR); }
|
||||
var userId = HttpContext.GetUId();
|
||||
if (userId != parm.UserId)
|
||||
{
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "操作失败");
|
||||
}
|
||||
var response = _ArticleService.ChangeComment(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("del/{id}")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult Delete(long id = 0)
|
||||
{
|
||||
var userId = HttpContext.GetUId();
|
||||
var info = _ArticleService.GetId(id);
|
||||
if (info == null || info.UserId != userId)
|
||||
{
|
||||
return ToResponse(ResultCode.CUSTOM_ERROR, "删除失败(-1)");
|
||||
}
|
||||
var response = _ArticleService.Delete(id);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章详情
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Get(int id)
|
||||
{
|
||||
long userId = HttpContext.GetUId();
|
||||
var model = _ArticleService.GetArticle(id, userId);
|
||||
var user = _SysUserService.GetById(model.UserId);
|
||||
ApiResult apiResult = ApiResult.Success(model);
|
||||
model.User = new ArticleUser()
|
||||
{
|
||||
Avatar = user.Avatar,
|
||||
NickName = user.NickName,
|
||||
Sex = user.Sex,
|
||||
};
|
||||
//apiResult.Put("user", user.Adapt<UserDto>());
|
||||
return ToResponse(apiResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前台查询话题
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("topicList")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult QueryTopicList([FromQuery] ArticleTopicQueryDto parm)
|
||||
{
|
||||
var response = _ArticleTopicService.GetTopicList(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询文章话题详情
|
||||
/// </summary>
|
||||
/// <param name="TopicId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("topic/{TopicId}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetArticleTopic(long TopicId)
|
||||
{
|
||||
var response = _ArticleTopicService.GetInfo(TopicId);
|
||||
|
||||
_ArticleTopicService.Update(w => w.TopicId == TopicId, it => new ArticleTopic() { ViewNum = it.ViewNum + 1 });
|
||||
|
||||
var info = response.Adapt<ArticleTopicDto>();
|
||||
return SUCCESS(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
134
ZR.Admin.WebApi/Controllers/Article/FrontCommentController.cs
Normal file
134
ZR.Admin.WebApi/Controllers/Article/FrontCommentController.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model;
|
||||
using ZR.Model.Content;
|
||||
using ZR.Model.Content.Dto;
|
||||
using ZR.Service.Content.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 评论
|
||||
/// </summary>
|
||||
[Route("front/comment")]
|
||||
[ApiExplorerSettings(GroupName = "article")]
|
||||
[ApiController]
|
||||
public class FrontCommentController : BaseController
|
||||
{
|
||||
private readonly IArticleCommentService messageService;
|
||||
private readonly IArticleService articleService;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="messageService"></param>
|
||||
/// <param name="articleService"></param>
|
||||
public FrontCommentController(
|
||||
IArticleCommentService messageService, IArticleService articleService)
|
||||
{
|
||||
this.messageService = messageService;
|
||||
this.articleService = articleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询评论列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
public IActionResult QueryList([FromQuery] MessageQueryDto parm)
|
||||
{
|
||||
parm.PageSize = 10;
|
||||
PagedInfo<ArticleCommentDto>? response;
|
||||
//查询二级评论
|
||||
if (parm.CommentId > 0)
|
||||
{
|
||||
response = messageService.GetReplyComments(parm.CommentId, parm);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = messageService.GetMessageList(parm);
|
||||
}
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 评论
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("add")]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult Create([FromBody] ArticleCommentDto parm)
|
||||
{
|
||||
var uid = HttpContextExtension.GetUId(HttpContext);
|
||||
if (uid <= 0) { return ToResponse(ResultCode.DENY); }
|
||||
|
||||
var addModel = parm.Adapt<ArticleComment>().ToCreate(context: HttpContext);
|
||||
addModel.UserIP = HttpContextExtension.GetClientUserIp(HttpContext);
|
||||
addModel.UserId = uid;
|
||||
return SUCCESS(messageService.AddMessage(addModel).Adapt<ArticleCommentDto>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 评论点赞
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("praise")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
[Verify]
|
||||
public IActionResult Praise([FromBody] ArticleCommentDto dto)
|
||||
{
|
||||
if (dto == null || dto.CommentId <= 0) return ToResponse(ResultCode.PARAM_ERROR);
|
||||
//var uid = HttpContextExtension.GetUId(HttpContext);
|
||||
|
||||
return SUCCESS(messageService.PraiseMessage(dto.CommentId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 评论删除
|
||||
/// </summary>
|
||||
/// <param name="mid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("delete/{mid}")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
[Verify]
|
||||
public IActionResult Delete(long mid)
|
||||
{
|
||||
var uid = HttpContextExtension.GetUId(HttpContext);
|
||||
if (uid <= 0) { return ToResponse(ResultCode.DENY); }
|
||||
return SUCCESS(messageService.DeleteMessage(mid.ParseToLong(), uid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询我的评论列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("mylist")]
|
||||
[Verify]
|
||||
public IActionResult QueryMyCommentList([FromQuery] MessageQueryDto parm)
|
||||
{
|
||||
PagedInfo<ArticleCommentDto> response = messageService.GetMyMessageList(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 评论置顶
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("top")]
|
||||
[Verify]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult Top([FromBody] ArticleCommentDto parm)
|
||||
{
|
||||
var uid = HttpContextExtension.GetUId(HttpContext);
|
||||
if (uid <= 0) { return ToResponse(ResultCode.DENY); }
|
||||
var contentInfo = articleService.GetArticle(parm.TargetId, uid);
|
||||
if (contentInfo == null) { return ToResponse(ResultCode.CUSTOM_ERROR, "操作失败"); }
|
||||
return SUCCESS(messageService.TopMessage(parm.CommentId, parm.Top));
|
||||
}
|
||||
}
|
||||
}
|
||||
91
ZR.Admin.WebApi/Controllers/Article/MomentsController.cs
Normal file
91
ZR.Admin.WebApi/Controllers/Article/MomentsController.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Model.Content;
|
||||
using ZR.Model.Content.Dto;
|
||||
using ZR.Model.Enum;
|
||||
using ZR.Service.Content.IService;
|
||||
|
||||
namespace ZR.Admin.WebApi.Controllers
|
||||
{
|
||||
[Verify]
|
||||
[Route("moment")]
|
||||
[ApiExplorerSettings(GroupName = "article")]
|
||||
public class MomentsController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态接口
|
||||
/// </summary>
|
||||
private readonly IArticleService _ArticleService;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ArticleService"></param>
|
||||
public MomentsController(
|
||||
IArticleService ArticleService)
|
||||
{
|
||||
_ArticleService = ArticleService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询我的
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("mylist")]
|
||||
public IActionResult QueryMyList([FromQuery] ArticleQueryDto parm)
|
||||
{
|
||||
parm.UserId = HttpContext.GetUId();
|
||||
parm.ArticleType = 2;
|
||||
var response = _ArticleService.GetMyList(parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询动态列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("momentList")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult QueryMonentList([FromQuery] ArticleQueryDto parm)
|
||||
{
|
||||
parm.UserId = HttpContext.GetUId();
|
||||
parm.ArticleType = 2;
|
||||
if (parm.TabId == 100)
|
||||
{
|
||||
return SUCCESS(_ArticleService.GetFollowMonentList(parm));
|
||||
}
|
||||
return SUCCESS(_ArticleService.GetMonentList(parm));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态发布
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("publishMoment")]
|
||||
[ActionPermissionFilter(Permission = "common")]
|
||||
public IActionResult PublishMoment([FromBody] ArticleDto parm)
|
||||
{
|
||||
if (parm == null) { return ToResponse(ResultCode.PARAM_ERROR); }
|
||||
var addModel = parm.Adapt<Article>().ToCreate(context: HttpContext);
|
||||
addModel.Tags = parm.TopicName;
|
||||
|
||||
return SUCCESS(_ArticleService.PublishMonent(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getInfo")]
|
||||
public IActionResult GetInfo()
|
||||
{
|
||||
var userId = HttpContext.GetUId();
|
||||
|
||||
var monentNum = _ArticleService.Queryable()
|
||||
.Count(f => f.UserId == userId && f.ArticleType == ArticleTypeEnum.Monent);
|
||||
|
||||
return SUCCESS(new { monentNum, commentNum = 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user