NoteController.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.Result.App.Note;
  7. using GxPress.Service.Interface.Note;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Microsoft.Extensions.Logging;
  11. namespace GxPress.Api.AppControllers
  12. {
  13. /// <summary>
  14. /// 个人笔记
  15. /// </summary>
  16. [Route("api/app/note")]
  17. [ApiController]
  18. [Authorize]
  19. public class NoteController : ControllerBase
  20. {
  21. private readonly ILogger<NoteController> _logger;
  22. private readonly INoteService _noteService;
  23. private readonly ILoginContext _loginContext;
  24. private readonly INoteRepository noteRepository;
  25. public NoteController(ILogger<NoteController> logger, INoteService noteService, ILoginContext loginContext, INoteRepository noteRepository)
  26. {
  27. _logger = logger;
  28. _noteService = noteService;
  29. _loginContext = loginContext;
  30. this.noteRepository = noteRepository;
  31. }
  32. /// <summary>
  33. /// 添加笔记
  34. /// </summary>
  35. /// <param name="request"></param>
  36. /// <returns></returns>
  37. [HttpPut("add")]
  38. public async Task<bool> InsertNote(NoteInRequest request)
  39. {
  40. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  41. // request.Content = StringUtils.RemoveEmoji(request.Content);
  42. request.UserId = _loginContext.AccountId;
  43. return await _noteService.InsertNoteAsync(request);
  44. }
  45. /// <summary>
  46. /// 获取笔记分页
  47. /// </summary>
  48. /// <param name="request"></param>
  49. /// <returns></returns>
  50. [HttpPost("search")]
  51. public async Task<PagedList<NotePageListRequest>> NotePageList(NoteSearchPageListRequest request)
  52. {
  53. request.UserId = _loginContext.AccountId;
  54. return await _noteService.NotePageListAsync(request);
  55. }
  56. /// <summary>
  57. /// 获取笔记详情
  58. /// </summary>
  59. /// <param name="id"></param>
  60. /// <returns></returns>
  61. [HttpGet("{id}")]
  62. public async Task<NoteDetailResult> GetNoteDetail(int id)
  63. {
  64. var note = await _noteService.GetNoteDetailAsync(id, _loginContext.AccountId);
  65. return note;
  66. }
  67. /// <summary>
  68. /// 获取笔记详情
  69. /// </summary>
  70. /// <param name="id"></param>
  71. /// <returns></returns>
  72. [HttpGet("web/{id}")]
  73. [AllowAnonymous]
  74. public async Task<NoteDetailResult> GetWebNoteDetail(int id)
  75. {
  76. var note = await _noteService.GetNoteDetailAsync(id, 0);
  77. return note;
  78. }
  79. /// <summary>
  80. /// 修改笔记
  81. /// </summary>
  82. /// <param name="note"></param>
  83. /// <returns></returns>
  84. [HttpPut("update")]
  85. public async Task<bool> UpdateNote(Entity.Note.Note note)
  86. {
  87. // note.HtmlContent = StringUtils.RemoveEmoji(note.HtmlContent);
  88. // note.Content = StringUtils.RemoveEmoji(note.Content);
  89. // note.Title = StringUtils.RemoveEmoji(note.Title);
  90. return await _noteService.UpdateNoteAsync(note);
  91. }
  92. /// <summary>
  93. /// 删除笔记
  94. /// </summary>
  95. /// <param name="id"></param>
  96. /// <returns></returns>
  97. [HttpDelete("{id}")]
  98. public async Task<bool> DeleteAsync(int id) => await _noteService.DeleteAsync(id, _loginContext.AccountId);
  99. /// <summary>
  100. /// 笔记没有文件夹分页
  101. /// </summary>
  102. /// <param name="request"></param>
  103. /// <returns></returns>
  104. [HttpPost("list")]
  105. public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
  106. {
  107. request.UserId = _loginContext.AccountId;
  108. return await _noteService.GetNoteNotFolderPageResult(request);
  109. }
  110. }
  111. }