using System.Collections.Generic; using System.Threading.Tasks; using GxPress.Auth; using GxPress.Common.Page; using GxPress.Repository.Interface.Missive; using GxPress.Request.App.Missive; using GxPress.Result.App.Missive; using GxPress.Service.Interface.Missive; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Linq; using System; namespace GxPress.Api.AppControllers { /// /// 站内信 /// [Route("api/app/missive")] [ApiController] [Authorize] public class MissiveController : ControllerBase { private readonly IMissiveRepository _missiveRepository; private readonly IMissiveService _missiveService; private readonly ILoginContext _loginContext; public MissiveController(IMissiveRepository missiveRepository, IMissiveService missiveService, ILoginContext loginContext) { _missiveRepository = missiveRepository; _missiveService = missiveService; _loginContext = loginContext; } /// /// 根据站内信ID获取详情 /// /// /// [HttpGet("get/{missiveId}")] public async Task GetMissiveInfo(int missiveId) { return await _missiveService.GetMissiveInfoAsync(missiveId, _loginContext.AccountId); } /// /// 添加/修改站内信 /// /// /// [HttpPut("add")] public async Task Insert(MissiveInRequest request) { // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent); // request.Content = StringUtils.RemoveEmoji(request.Content); // request.Title = StringUtils.RemoveEmoji(request.Title); request.UserId = _loginContext.AccountId; request.MissiveAddresseeUserIds.Remove(request.UserId); request.MissiveCcUserIds.Remove(request.UserId); return await _missiveService.InsertOrUpdateAsync(request); } /// /// 获取站内信列表 /// /// /// [HttpPost("search")] public async Task> GetMissiveSearchResult(MissiveSearchRequest request) { request.UserId = _loginContext.AccountId; return await _missiveService.GetMissiveSearchResultAsync(request); } /// /// 获取站内信详情 /// /// /// [HttpGet("{id}")] public async Task GetMissiveDetail(int id) { return await _missiveService.GetMissiveDetailAsync(id); } /// /// 获取站内信详情-web专属 /// /// /// [HttpGet("web/{id}")] [AllowAnonymous] public async Task GetWebMissiveDetail(int id) { var missiveInfos = await _missiveService.GetMissiveInfoAsync(id, 0); missiveInfos.Items = missiveInfos.Items.OrderByDescending(n => Convert.ToDateTime(n.CreatedDate)).ToList(); return missiveInfos; } /// /// 获取站内信已读未读数据 /// /// /// [HttpPost("read")] public async Task> GetMissiveReadListAsync(MissiveReadListRequest request) { return await _missiveService.GetMissiveReadListAsync(request); } /// /// 站内信撤回 /// /// /// [HttpPut("recall/{missiveId}")] public async Task RecallAsync(int missiveId) { return await _missiveService.RecallAsync(missiveId); } } }