using System;
using System.Threading.Tasks;
using GxPress.Common.Page;
using GxPress.Repository.Interface;
using GxPress.Request.Admin.Article;
using GxPress.Request.Article;
using GxPress.Result.Article;
using GxPress.Service.Interface.Article;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace GxPress.Api.AdminControllers
{
///
/// 审批文章
///
[Route("api/admin/article")]
[ApiController]
[Authorize]
public class AdminArticleController : ControllerBase
{
private readonly IArticleRepository _articleRepository;
private readonly IArticleService _articleService;
public AdminArticleController(IArticleRepository articleRepository, IArticleService articleService)
{
_articleRepository = articleRepository;
_articleService = articleService;
}
///
/// 添加文章
///
///
///
[HttpPost]
public async Task Add([FromBody] ArticleAddRequest request)
{
if (!string.IsNullOrEmpty(request.Summary) && request.Summary.Length > 500)
{
throw new Exception("保存失败,字符数不能超出500");
}
return await _articleService.AddAsync(request);
}
///
/// 修改文章
///
///
///
[HttpPut]
public async Task Edit([FromBody] ArticleEditRequest request)
{
if (!string.IsNullOrEmpty(request.Summary) && request.Summary.Length > 500)
{
throw new Exception("保存失败,字符数不能超出500");
}
return await _articleService.EditAsync(request);
}
///
/// 列表
///
///
[HttpGet("")]
[AllowAnonymous]
public async Task> GetList([FromQuery] ArticleSearchRequest request)
{
var pagedList = await _articleRepository.GetListAsync(request.Keyword, request);
return pagedList;
}
///
/// 文章
///
///
[HttpGet("{id}")]
[AllowAnonymous]
public async Task Get(int id)
{
var article= await _articleService.GetAsync(id,0);
return article;
}
///
/// 删除文章
///
///
///
[HttpDelete("{id}")]
public async Task Delete(int id)
{
return await _articleRepository.DeleteAsync(id);
}
/////
///// 文章 点赞 收藏 转发
/////
/////
//[HttpPost("analyze")]
//[AllowAnonymous]
//public async Task AddArticleAnalyze([FromBody] ArticleAnalyzeRequest request)
//{
// return await _articleAnalyzeRepository.SetArticleAnalyzeAsync(request);
//}
///
/// 克隆文章
///
///
///
[HttpPost("clone")]
public async Task CloneArticle(CloneArticleRequest request)
{
return await _articleRepository.CloneArticleAsync(request);
}
}
}