添加note
This commit is contained in:
parent
1e86af810f
commit
62461960d4
@ -1,10 +1,26 @@
|
||||
package asia.yulinling.workflow.controller;
|
||||
|
||||
import asia.yulinling.workflow.constant.Status;
|
||||
import asia.yulinling.workflow.model.ApiResponse;
|
||||
import asia.yulinling.workflow.model.entity.Note;
|
||||
import asia.yulinling.workflow.service.NoteService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Slf4j
|
||||
@RequestMapping("/api22")
|
||||
@RequestMapping("/api")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class NoteController {
|
||||
private final NoteService noteService;
|
||||
|
||||
@PostMapping("/note")
|
||||
public ApiResponse<?> note() {
|
||||
Note note = new Note();
|
||||
noteService.addNote(note);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
88
src/main/java/asia/yulinling/workflow/model/vo/NoteVO.java
Normal file
88
src/main/java/asia/yulinling/workflow/model/vo/NoteVO.java
Normal file
@ -0,0 +1,88 @@
|
||||
package asia.yulinling.workflow.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 笔记VO
|
||||
* </p>
|
||||
*
|
||||
* @author yulinling
|
||||
* @since 2025/8/13
|
||||
*/
|
||||
@Data
|
||||
public class NoteVO {
|
||||
Long id;
|
||||
|
||||
/**
|
||||
* 用户id,外键
|
||||
*/
|
||||
Long userId;
|
||||
|
||||
/**
|
||||
* 笔记本id,外键
|
||||
*/
|
||||
Long notebookId;
|
||||
|
||||
/**
|
||||
* 笔记标题
|
||||
*/
|
||||
String title;
|
||||
|
||||
/**
|
||||
* 笔记本内容
|
||||
*/
|
||||
String content;
|
||||
|
||||
/**
|
||||
* 笔记本内容预览,截取前200字符
|
||||
*/
|
||||
String previewText;
|
||||
|
||||
/**
|
||||
* 笔记内容字数统计
|
||||
*/
|
||||
Integer wordCount;
|
||||
|
||||
/**
|
||||
* 是否置顶显示
|
||||
*/
|
||||
Boolean isPinned;
|
||||
|
||||
/**
|
||||
* 是否归档(不显示在默认列表中)
|
||||
*/
|
||||
Boolean isArchived;
|
||||
|
||||
/**
|
||||
* 是否标记为收藏
|
||||
*/
|
||||
Boolean isFavorite;
|
||||
|
||||
/**
|
||||
* 是否需要密码查看
|
||||
*/
|
||||
Boolean passwordProtected;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
Date updateTime;
|
||||
|
||||
/**
|
||||
* 提醒时间
|
||||
*/
|
||||
Date reminderTime;
|
||||
|
||||
/**
|
||||
* 笔记封面图片url
|
||||
*/
|
||||
String coverImage;
|
||||
}
|
||||
@ -1,5 +1,65 @@
|
||||
package asia.yulinling.workflow.service;
|
||||
|
||||
public interface NoteService {
|
||||
import asia.yulinling.workflow.dto.request.PageParam;
|
||||
import asia.yulinling.workflow.dto.response.PageResult;
|
||||
import asia.yulinling.workflow.model.entity.Note;
|
||||
import asia.yulinling.workflow.model.vo.NoteVO;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Transactional
|
||||
public interface NoteService {
|
||||
/**
|
||||
* 添加笔记本
|
||||
*
|
||||
* @param note 笔记
|
||||
*/
|
||||
void addNote(Note note);
|
||||
|
||||
/**
|
||||
* 删除笔记本
|
||||
*
|
||||
* @param noteId 笔记本id
|
||||
*/
|
||||
void deleteNoteById(Long noteId);
|
||||
|
||||
/**
|
||||
* 更新笔记本
|
||||
*
|
||||
* @param note 笔记本
|
||||
*/
|
||||
void updateNote(Note note);
|
||||
|
||||
/**
|
||||
* 获取笔记内容
|
||||
*
|
||||
* @param noteId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
NoteVO getNote(Long noteId);
|
||||
|
||||
/**
|
||||
* 获取笔记本列表
|
||||
*
|
||||
* @param pageParam 分页参数
|
||||
* @return 笔记列表
|
||||
*/
|
||||
PageResult<NoteVO> getNoteList(PageParam pageParam);
|
||||
|
||||
/**
|
||||
* 获取指定用户的笔记本列表
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 笔记本列表
|
||||
*/
|
||||
List<Note> getNoteListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据笔记Id检测笔记是否存在
|
||||
*
|
||||
* @param noteId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
boolean isNoteNotExist(Long noteId);
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Transactional
|
||||
public interface UserService {
|
||||
|
||||
boolean checkUserIdExist(Long userId);
|
||||
boolean isUserIdNoteExist(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户列表分页
|
||||
|
||||
@ -1,10 +1,118 @@
|
||||
package asia.yulinling.workflow.service.impl;
|
||||
|
||||
import asia.yulinling.workflow.dto.request.PageParam;
|
||||
import asia.yulinling.workflow.dto.response.PageResult;
|
||||
import asia.yulinling.workflow.exception.ServiceException;
|
||||
import asia.yulinling.workflow.mapper.NoteMapper;
|
||||
import asia.yulinling.workflow.model.entity.Note;
|
||||
import asia.yulinling.workflow.model.vo.NoteVO;
|
||||
import asia.yulinling.workflow.service.NoteService;
|
||||
import asia.yulinling.workflow.service.NotebookService;
|
||||
import asia.yulinling.workflow.service.UserService;
|
||||
import asia.yulinling.workflow.utils.PageUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NoteServiceImpl implements NoteService {
|
||||
private final NoteMapper noteMapper;
|
||||
private final NotebookService notebookService;
|
||||
private final UserService userService;
|
||||
|
||||
/**
|
||||
* 添加笔记本
|
||||
*
|
||||
* @param note 笔记
|
||||
*/
|
||||
@Override
|
||||
public void addNote(Note note) {
|
||||
if (notebookService.isNotebookNotExist(note.getNotebookId())) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
int result = noteMapper.insert(note);
|
||||
|
||||
if (result == 0) {
|
||||
throw new ServiceException("新增笔记失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除笔记本
|
||||
*
|
||||
* @param noteId 笔记本id
|
||||
*/
|
||||
@Override
|
||||
public void deleteNoteById(Long noteId) {
|
||||
if (isNoteNotExist(noteId)) {
|
||||
throw new ServiceException("笔记不存在");
|
||||
}
|
||||
|
||||
int result = noteMapper.deleteById(noteId);
|
||||
|
||||
if (result == 0) {
|
||||
throw new ServiceException("删除笔记失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新笔记本
|
||||
*
|
||||
* @param note 笔记本
|
||||
*/
|
||||
@Override
|
||||
public void updateNote(Note note) {
|
||||
if (isNoteNotExist(note.getId())) {
|
||||
throw new ServiceException("笔记不存在");
|
||||
}
|
||||
|
||||
int result = noteMapper.updateById(note);
|
||||
if (result == 0) {
|
||||
throw new ServiceException("更新笔记成功");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoteVO getNote(Long noteId) {
|
||||
Note note = noteMapper.selectById(noteId);
|
||||
NoteVO noteVO = new NoteVO();
|
||||
BeanUtils.copyProperties(note, noteVO);
|
||||
return noteVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<NoteVO> getNoteList(PageParam pageParam) {
|
||||
Page<Note> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
|
||||
Page<Note> pageResult = noteMapper.selectPage(page, null);
|
||||
List<NoteVO> noteVOList = new ArrayList<>();
|
||||
for (Note note : pageResult.getRecords()) {
|
||||
NoteVO noteVO = new NoteVO();
|
||||
BeanUtils.copyProperties(note, noteVO);
|
||||
noteVOList.add(noteVO);
|
||||
}
|
||||
return PageUtil.buildPageResult(pageResult, noteVOList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> getNoteListByUserId(Long userId) {
|
||||
if (userService.isUserIdNoteExist(userId)) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
return noteMapper.selectList(new LambdaQueryWrapper<Note>().eq(Note::getUserId, userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNoteNotExist(Long noteId) {
|
||||
return noteMapper.exists(new LambdaQueryWrapper<Note>().eq(Note::getId, noteId));
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
@Override
|
||||
public void addNotebook(Notebook notebook) {
|
||||
|
||||
if (userService.checkUserIdExist(notebook.getUserId())) {
|
||||
if (userService.isUserIdNoteExist(notebook.getUserId())) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
|
||||
@Override
|
||||
public void deleteNotebookById(Long notebookId) {
|
||||
if (userService.checkUserIdExist(notebookId)) {
|
||||
if (isNotebookNotExist(notebookId)) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
|
||||
@Override
|
||||
public void updateNotebook(Notebook notebook) {
|
||||
if (userService.checkUserIdExist(notebook.getUserId())) {
|
||||
if (userService.isUserIdNoteExist(notebook.getUserId())) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
*/
|
||||
@Override
|
||||
public List<Notebook> getNotebookListByUserId(Long userId) {
|
||||
if (userService.checkUserIdExist(userId)) {
|
||||
if (userService.isUserIdNoteExist(userId)) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ public class UserServiceImpl implements UserService {
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUserIdExist(Long userId) {
|
||||
public boolean isUserIdNoteExist(Long userId) {
|
||||
return !userMapper.exists(new LambdaQueryWrapper<User>().eq(User::getId, userId));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user