123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using GxPress.Auth;
- using GxPress.Common.Page;
- using GxPress.Repository.Interface.Note;
- using GxPress.Request.App.Note;
- using GxPress.Result.App.Note;
- using GxPress.Service.Interface.Note;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- namespace GxPress.Api.AppControllers
- {
- /// <summary>
- /// 个人笔记
- /// </summary>
- [Route("api/app/note")]
- [ApiController]
- [Authorize]
- public class NoteController : ControllerBase
- {
- private readonly ILogger<NoteController> _logger;
- private readonly INoteService _noteService;
- private readonly ILoginContext _loginContext;
- private readonly INoteRepository noteRepository;
- public NoteController(ILogger<NoteController> logger, INoteService noteService, ILoginContext loginContext, INoteRepository noteRepository)
- {
- _logger = logger;
- _noteService = noteService;
- _loginContext = loginContext;
- this.noteRepository = noteRepository;
- }
- /// <summary>
- /// 添加笔记
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPut("add")]
- public async Task<NoteAddOrModifyResult> InsertNote(NoteInRequest request)
- {
- // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
- // request.Content = StringUtils.RemoveEmoji(request.Content);
- request.UserId = _loginContext.AccountId;
- return await _noteService.InsertNoteAsync(request);
- }
- /// <summary>
- /// 获取笔记分页
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("search")]
- public async Task<PagedList<NotePageListRequest>> NotePageList(NoteSearchPageListRequest request)
- {
- request.UserId = _loginContext.AccountId;
- return await _noteService.NotePageListAsync(request);
- }
- /// <summary>
- /// 获取笔记详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("{id}")]
- public async Task<NoteDetailResult> GetNoteDetail(int id)
- {
- var note = await _noteService.GetNoteDetailAsync(id, _loginContext.AccountId);
- return note;
- }
- /// <summary>
- /// 获取笔记详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("web/{id}")]
- [AllowAnonymous]
- public async Task<NoteDetailResult> GetWebNoteDetail(int id)
- {
- var note = await _noteService.GetNoteDetailAsync(id, 0);
- return note;
- }
- /// <summary>
- /// 修改笔记
- /// </summary>
- /// <param name="note"></param>
- /// <returns></returns>
- [HttpPut("update")]
- public async Task<NoteAddOrModifyResult> UpdateNote(Entity.Note.Note note)
- {
- // note.HtmlContent = StringUtils.RemoveEmoji(note.HtmlContent);
- // note.Content = StringUtils.RemoveEmoji(note.Content);
- // note.Title = StringUtils.RemoveEmoji(note.Title);
- return await _noteService.UpdateNoteAsync(note);
- }
- /// <summary>
- /// 删除笔记
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("{id}")]
- public async Task<bool> DeleteAsync(int id) => await _noteService.DeleteAsync(id, _loginContext.AccountId);
- /// <summary>
- /// 笔记没有文件夹分页
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("list")]
- public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
- {
- request.UserId = _loginContext.AccountId;
- return await _noteService.GetNoteNotFolderPageResult(request);
- }
- /// <summary>
- /// 获取笔记/话题草稿分页
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("draft-list")]
- public async Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request)
- {
- request.UserId = _loginContext.AccountId;
- return await _noteService.NoteTopicDraftPageListAsync(request);
- }
- /// <summary>
- /// 笔记设置置顶
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpPut("{id}")]
- public async Task<bool> SetIsTopAsync(int id)
- {
- return await noteRepository.SetIsTopAsync(id);
- }
- /// <summary>
- /// 清空草稿箱
- /// </summary>
- /// <param name="typeValue">0 笔记 1 话题本</param>
- /// <returns></returns>
- [HttpPut("clear-draft/{typeValue}")]
- public async Task<bool> ClearDraftAsync(int typeValue)
- {
- return await noteRepository.ClearDraftAsync(_loginContext.AccountId, typeValue);
- }
- /// <summary>
- /// 草稿删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("draft/{id}")]
- public async Task<bool> DraftDeleteAsync(int id)
- {
- return await _noteService.DraftDeleteAsync(id);
- }
- [HttpGet("update/list")]
- [AllowAnonymous]
- public async Task<bool> UpdateNoteTextContentAsync()
- {
- return await _noteService.UpdateNoteTextContentAsync();
- }
- }
- }
|