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
{
///
/// 个人笔记
///
[Route("api/app/note")]
[ApiController]
[Authorize]
public class NoteController : ControllerBase
{
private readonly ILogger _logger;
private readonly INoteService _noteService;
private readonly ILoginContext _loginContext;
private readonly INoteRepository noteRepository;
public NoteController(ILogger logger, INoteService noteService, ILoginContext loginContext, INoteRepository noteRepository)
{
_logger = logger;
_noteService = noteService;
_loginContext = loginContext;
this.noteRepository = noteRepository;
}
///
/// 添加笔记
///
///
///
[HttpPut("add")]
public async Task InsertNote(NoteInRequest request)
{
// request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
// request.Content = StringUtils.RemoveEmoji(request.Content);
request.UserId = _loginContext.AccountId;
return await _noteService.InsertNoteAsync(request);
}
///
/// 获取笔记分页
///
///
///
[HttpPost("search")]
public async Task> NotePageList(NoteSearchPageListRequest request)
{
request.UserId = _loginContext.AccountId;
return await _noteService.NotePageListAsync(request);
}
///
/// 获取笔记详情
///
///
///
[HttpGet("{id}")]
public async Task GetNoteDetail(int id)
{
var note = await _noteService.GetNoteDetailAsync(id, _loginContext.AccountId);
return note;
}
///
/// 获取笔记详情
///
///
///
[HttpGet("web/{id}")]
[AllowAnonymous]
public async Task GetWebNoteDetail(int id)
{
var note = await _noteService.GetNoteDetailAsync(id, 0);
return note;
}
///
/// 修改笔记
///
///
///
[HttpPut("update")]
public async Task 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);
}
///
/// 删除笔记
///
///
///
[HttpDelete("{id}")]
public async Task DeleteAsync(int id) => await _noteService.DeleteAsync(id, _loginContext.AccountId);
///
/// 笔记没有文件夹分页
///
///
///
[HttpPost("list")]
public async Task> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
{
request.UserId = _loginContext.AccountId;
return await _noteService.GetNoteNotFolderPageResult(request);
}
///
/// 获取笔记/话题草稿分页
///
///
///
[HttpPost("draft-list")]
public async Task> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request)
{
request.UserId = _loginContext.AccountId;
return await _noteService.NoteTopicDraftPageListAsync(request);
}
///
/// 笔记设置置顶
///
///
///
[HttpPut("{id}")]
public async Task SetIsTopAsync(int id)
{
return await noteRepository.SetIsTopAsync(id);
}
///
/// 清空草稿箱
///
/// 0 笔记 1 话题本
///
[HttpPut("clear-draft/{typeValue}")]
public async Task ClearDraftAsync(int typeValue)
{
return await noteRepository.ClearDraftAsync(_loginContext.AccountId, typeValue);
}
///
/// 草稿删除
///
///
///
[HttpDelete("draft/{id}")]
public async Task DraftDeleteAsync(int id)
{
return await _noteService.DraftDeleteAsync(id);
}
}
}