using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Common.Tools;
using GxPress.Entity.Topic;
using GxPress.Repository.Interface;
using GxPress.Repository.Interface.Topic;
using GxPress.Request.App.Topic;
using GxPress.Request.App.TopicAnalyze;
using GxPress.Request.App.TopicComment;
using GxPress.Result.App.Topic;
using GxPress.Result.App.TopicComment;
using GxPress.Service.Interface.Middle;
using GxPress.Service.Interface.Topic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace GxPress.Api.AppControllers
{
///
/// APP话题
///
[Route("api/app/topic")]
[ApiController]
[Authorize]
public class TopicController : ControllerBase
{
private readonly ILogger _logger;
private readonly ITopicRepository _topicRepository;
private readonly ILoginContext _loginContext;
private readonly ITopicService _topicService;
private readonly ITopicGroupRepository _topicGroupRepository;
private readonly ITopicGroupUserRepository _topicGroupUserRepository;
private readonly ITopicAnalyzeRepository _topicAnalyzeRepository;
private readonly ITopicCommentRepository _topicCommentRepository;
private readonly IMiddleService _middleService;
public TopicController(ILogger logger, ITopicRepository repository, ILoginContext loginContext,
ITopicService topicService, ITopicGroupRepository topicGroupRepository,
ITopicGroupUserRepository topicGroupUserRepository, ITopicAnalyzeRepository topicAnalyzeRepository,
ITopicCommentRepository topicCommentRepository, IMiddleService middleService)
{
_logger = logger;
_topicRepository = repository;
_loginContext = loginContext;
_topicService = topicService;
_topicGroupRepository = topicGroupRepository;
_topicGroupUserRepository = topicGroupUserRepository;
_topicAnalyzeRepository = topicAnalyzeRepository;
_topicCommentRepository = topicCommentRepository;
_middleService = middleService;
}
///
/// 添加
///
///
///
[HttpPost("add")]
public async Task Insert(TopicInRequest request)
{
// request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
// request.Content = StringUtils.RemoveEmoji(request.Content);
// request.Title = StringUtils.RemoveEmoji(request.Title);
request.UserId = _loginContext.AccountId;
return await _topicService.InsertTopicAsync(request);
}
///
/// 获取话题详情
///
///
///
[HttpPost("app-detail")]
public async Task GetTopicDetailResult(TopicDetailRequest request)
{
request.UserId = _loginContext.AccountId;
var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
return topicDetail;
}
///
/// 获取话题详情 web专属
///
///
///
[HttpPost("web-app-detail")]
[AllowAnonymous]
public async Task GetWebTopicDetailResult(TopicDetailRequest request)
{
var topicDetail = await _topicService.GetTopicDetailResultAsync(request);
return topicDetail;
}
///
/// app话题分页列表
///
///
///
[HttpPost("list-page")]
public async Task> GetTopicListPage(TopicPageSearchRequest request)
{
request.UserId = _loginContext.AccountId;
return await _topicService.GetTopicPageAsync(request);
}
///
/// 获取用户话题分组
///
///
[HttpPost("group")]
public async Task> GetTopicGroups()
{
return await _topicGroupRepository.GetTopicGroupsAsync(_loginContext.AccountId);
}
///
/// 添加话题分组
///
///
///
[HttpPut("add-group")]
public async Task InsertTopicGroup(TopicGroupInRequest request)
{
var topicGroup = new TopicGroup { Name = request.Name, UserId = _loginContext.AccountId };
return await _topicGroupRepository.InsertAsync(topicGroup);
}
///
/// 修改分组名称
///
///
///
[HttpPut("update-group")]
public async Task UpdateGroup(TopicGroupInRequest request)
{
return await _topicGroupRepository.UpdateAsync(request);
}
///
/// 根据话题分组Id删除数据
///
///
///
[HttpDelete("delete_group")]
public async Task DeleteTopicGroup([FromBody] TopicGroupDeRequest request)
{
return await _topicService.DeleteTopicGroupAsync(request.Ids);
}
///
/// 根据分组ID查询用户
///
///
///
[HttpGet("{id}")]
public async Task> GetTopicGroupUserById(int id)
{
return await _topicGroupUserRepository.GetTopicGroupUserById(id);
}
///
/// 添加话题小组成员
///
///
///
[HttpPost("add-group-user")]
public async Task InsertAsync([FromBody]TopicGroupUserInRequest request)
{
return await _topicService.InsertTopicGroupUserAsync(request.UserIds.Distinct().ToList(), request.TopicGroupId);
}
///
/// 根据ID删除话题分组成员
///
///
///
[HttpDelete("group-user")]
public async Task DeleteUser(TopicGroupDeRequest request)
{
return await _topicService.DeleteTopicGroupUserAsync(request.Ids);
}
///
/// 排序
///
///
///
[HttpPut("sort")]
public async Task MoveSort(TopicMoveSortRequest request)
{
return await _topicGroupRepository.MoveSortAsync(request.FirstId, request.SecondId, _loginContext.AccountId);
}
///
/// 移动到
///
///
///
[HttpPut("move")]
public async Task MoveToGroup(MoveToGroupRequest request)
{
return await _topicService.MoveToGroupAsync(request);
}
///
/// 根据分组ID和姓名查询用户
///
///
///
[HttpPost("search")]
public async Task> SearchTopicGroupUsers(SearchTopicGroupUsersRequest request)
{
return await _topicGroupUserRepository.SearchTopicGroupUsersAsync(request);
}
///
/// 删除话题
///
///
///
[HttpDelete("{id}")]
public async Task Delete(int id)
{
return await _topicService.DeleteAsync(id);
}
///
/// 修改话题
///
///
///
[HttpPut("update")]
public async Task Update(TopicUpdateRequest request)
{
// request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
// request.Content = StringUtils.RemoveEmoji(request.Content);
// request.Title = StringUtils.RemoveEmoji(request.Title);
request.UserId = _loginContext.AccountId;
return await _topicService.UpdateAsync(request);
}
}
}