WebNoteController.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System.Threading.Tasks;
  2. using GxPress.Auth;
  3. using GxPress.Common.Page;
  4. using GxPress.Repository.Interface.Note;
  5. using GxPress.Request.App.Note;
  6. using GxPress.Request.Web;
  7. using GxPress.Result.App.Note;
  8. using GxPress.Result.Web;
  9. using GxPress.Service.Interface.Note;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.Extensions.Logging;
  13. namespace GxPress.Api.WebControllers
  14. {
  15. /// <summary>
  16. /// 网页笔记
  17. /// </summary>
  18. [Route("api/web/note")]
  19. [ApiController]
  20. [Authorize]
  21. public class WebNoteController : Controller
  22. {
  23. private readonly ILogger<WebNoteController> _logger;
  24. private readonly INoteService _noteService;
  25. private readonly INoteRepository noteRepository;
  26. private readonly ILoginContext _loginContext;
  27. public WebNoteController(ILogger<WebNoteController> logger, INoteService noteService, ILoginContext loginContext, INoteRepository noteRepository)
  28. {
  29. _logger = logger;
  30. _noteService = noteService;
  31. _loginContext = loginContext;
  32. this.noteRepository = noteRepository;
  33. }
  34. /// <summary>
  35. /// 添加笔记
  36. /// </summary>
  37. /// <param name="request"></param>
  38. /// <returns></returns>
  39. [HttpPut("add")]
  40. public async Task<NoteAddOrModifyResult> InsertNote(NoteInRequest request)
  41. {
  42. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  43. // request.Content = StringUtils.RemoveEmoji(request.Content);
  44. request.UserId = _loginContext.AccountId;
  45. return await _noteService.InsertNoteAsync(request);
  46. }
  47. /// <summary>
  48. /// 获取笔记分页
  49. /// </summary>
  50. /// <param name="request"></param>
  51. /// <returns></returns>
  52. [HttpPost("search")]
  53. [AllowAnonymous]
  54. public async Task<PagedList<NotePageListRequest>> NotePageList(NoteSearchPageListRequest request)
  55. {
  56. request.UserId = _loginContext.AccountId;
  57. return await _noteService.NotePageListAsync(request);
  58. }
  59. /// <summary>
  60. /// 获取笔记详情
  61. /// </summary>
  62. /// <param name="id"></param>
  63. /// <returns></returns>
  64. [HttpGet("{id}")]
  65. public async Task<NoteDetailResult> GetNoteDetail(int id)
  66. {
  67. var note = await _noteService.GetNoteDetailAsync(id, _loginContext.AccountId);
  68. return note;
  69. }
  70. /// <summary>
  71. /// 获取笔记详情
  72. /// </summary>
  73. /// <param name="id"></param>
  74. /// <returns></returns>
  75. [HttpGet("web/{id}")]
  76. [AllowAnonymous]
  77. public async Task<NoteDetailResult> GetWebNoteDetail(int id)
  78. {
  79. var note = await _noteService.GetNoteDetailAsync(id, 0);
  80. return note;
  81. }
  82. /// <summary>
  83. /// 修改笔记
  84. /// </summary>
  85. /// <param name="note"></param>
  86. /// <returns></returns>
  87. [HttpPut("update")]
  88. public async Task<NoteAddOrModifyResult> UpdateNote(Entity.Note.Note note)
  89. {
  90. // note.HtmlContent = StringUtils.RemoveEmoji(note.HtmlContent);
  91. // note.Content = StringUtils.RemoveEmoji(note.Content);
  92. // note.Title = StringUtils.RemoveEmoji(note.Title);
  93. return await _noteService.UpdateNoteAsync(note);
  94. }
  95. /// <summary>
  96. /// 删除笔记
  97. /// </summary>
  98. /// <param name="id"></param>
  99. /// <returns></returns>
  100. [HttpDelete("{id}")]
  101. public async Task<bool> DeleteAsync(int id) => await _noteService.DeleteAsync(id, _loginContext.AccountId);
  102. /// <summary>
  103. ///查询个人摘录
  104. /// </summary>
  105. /// <param name="request"></param>
  106. /// <returns></returns>
  107. [HttpPost("extract")]
  108. public async Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request)
  109. {
  110. request.UserId = _loginContext.AccountId;
  111. return await _noteService.GetAllByUserId(request);
  112. }
  113. /// <summary>
  114. /// web页面查询话题
  115. /// </summary>
  116. /// <param name="request"></param>
  117. /// <returns></returns>
  118. [HttpPost("topic")]
  119. public async Task<PagedList<NoteTopicResult>> GetTopicNoteAsync(NoteSearchPageListRequest request)
  120. {
  121. request.UserId = _loginContext.AccountId;
  122. return await noteRepository.GetTopicNoteAsync(request);
  123. }
  124. /// <summary>
  125. /// 笔记没有文件夹分页
  126. /// </summary>
  127. /// <param name="request"></param>
  128. /// <returns></returns>
  129. [HttpPost("list")]
  130. public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
  131. {
  132. request.UserId = _loginContext.AccountId;
  133. return await _noteService.GetNoteNotFolderPageResult(request);
  134. }
  135. /// <summary>
  136. /// 笔记设置置顶
  137. /// </summary>
  138. /// <param name="id"></param>
  139. /// <returns></returns>
  140. [HttpPut("{id}")]
  141. public async Task<bool> SetIsTopAsync(int id)
  142. {
  143. return await noteRepository.SetIsTopAsync(id);
  144. }
  145. /// <summary>
  146. /// 获取笔记/话题草稿分页
  147. /// </summary>
  148. /// <param name="request"></param>
  149. /// <returns></returns>
  150. [HttpPost("draft-list")]
  151. public async Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request)
  152. {
  153. request.UserId = _loginContext.AccountId;
  154. return await _noteService.NoteTopicDraftPageListAsync(request);
  155. }
  156. /// <summary>
  157. /// 清空草稿箱
  158. /// </summary>
  159. /// <param name="typeValue">0 笔记 1 话题本</param>
  160. /// <returns></returns>
  161. [HttpPut("clear-draft/{typeValue}")]
  162. public async Task<bool> ClearDraftAsync(int typeValue)
  163. {
  164. return await noteRepository.ClearDraftAsync(_loginContext.AccountId, typeValue);
  165. }
  166. /// <summary>
  167. /// 草稿删除
  168. /// </summary>
  169. /// <param name="id"></param>
  170. /// <returns></returns>
  171. [HttpDelete("draft/{id}")]
  172. public async Task<bool> DraftDeleteAsync(int id)
  173. {
  174. return await _noteService.DraftDeleteAsync(id);
  175. }
  176. }
  177. }