完善notebook
This commit is contained in:
parent
dda272b9ab
commit
6e7dde5235
@ -9,6 +9,7 @@ import asia.yulinling.workflow.model.entity.Notebook;
|
||||
import asia.yulinling.workflow.model.vo.NotebookVO;
|
||||
import asia.yulinling.workflow.service.NotebookService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@ -36,14 +37,24 @@ public class NotebookController {
|
||||
}
|
||||
|
||||
@GetMapping("/notebooks/{id}")
|
||||
public void notebooksGet(@PathVariable Long id) {
|
||||
public ApiResponse<NotebookVO> notebooksGet(@PathVariable Long id) {
|
||||
NotebookVO notebookVO = notebookService.getNotebook(id);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS, notebookVO);
|
||||
}
|
||||
|
||||
@PutMapping("/notebooks/{id}")
|
||||
public void notebooksPut(@PathVariable Long id) {
|
||||
@PutMapping("/notebooks/{userId}/?id={id}")
|
||||
public ApiResponse<Object> notebooksPut(@PathVariable Long userId, @PathVariable @NonNull Long id, @Valid @RequestBody NotebookRequest notebookRequest) {
|
||||
Notebook notebook = new Notebook();
|
||||
notebook.setId(id);
|
||||
notebook.setUserId(userId);
|
||||
BeanUtils.copyProperties(notebookRequest, notebook);
|
||||
notebookService.updateNotebook(notebook);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS);
|
||||
}
|
||||
|
||||
@DeleteMapping("/notebooks/{id}")
|
||||
public void notebooksDelete(@PathVariable Long id) {
|
||||
public ApiResponse<Object> notebooksDelete(@PathVariable Long id) {
|
||||
notebookService.deleteNotebookById(id);
|
||||
return ApiResponse.ofStatus(Status.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,23 +15,21 @@ public interface NotebookService {
|
||||
*
|
||||
* @param notebook 笔记本
|
||||
*/
|
||||
int addNotebook(Notebook notebook);
|
||||
void addNotebook(Notebook notebook);
|
||||
|
||||
/**
|
||||
* 删除笔记本
|
||||
*
|
||||
* @param notebookId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteNotebookById(Long notebookId);
|
||||
void deleteNotebookById(Long notebookId);
|
||||
|
||||
/**
|
||||
* 更新笔记本
|
||||
*
|
||||
* @param notebook 笔记本
|
||||
* @return 结果
|
||||
*/
|
||||
int updateNotebook(Notebook notebook);
|
||||
void updateNotebook(Notebook notebook);
|
||||
|
||||
/**
|
||||
* 获取笔记本内容
|
||||
@ -39,7 +37,7 @@ public interface NotebookService {
|
||||
* @param notebookId 笔记本id
|
||||
* @return 结果
|
||||
*/
|
||||
Notebook getNotebook(Long notebookId);
|
||||
NotebookVO getNotebook(Long notebookId);
|
||||
|
||||
/**
|
||||
* 获取笔记本列表
|
||||
|
||||
@ -27,40 +27,58 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
public int addNotebook(Notebook notebook) {
|
||||
public void addNotebook(Notebook notebook) {
|
||||
|
||||
if (!userService.checkUserIdExist(notebook.getUserId())) {
|
||||
if (userService.checkUserIdExist(notebook.getUserId())) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.insert(notebook);
|
||||
int result = notebookMapper.insert(notebook);
|
||||
|
||||
if (result == 0) {
|
||||
throw new ServiceException("添加笔记本失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteNotebookById(Long notebookId) {
|
||||
if (!userService.checkUserIdExist(notebookId)) {
|
||||
public void deleteNotebookById(Long notebookId) {
|
||||
if (userService.checkUserIdExist(notebookId)) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.deleteById(notebookId);
|
||||
int result = notebookMapper.deleteById(notebookId);
|
||||
if (result == 0) {
|
||||
throw new ServiceException("删除笔记本失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateNotebook(Notebook notebook) {
|
||||
if (!userService.checkUserIdExist(notebook.getUserId())) {
|
||||
public void updateNotebook(Notebook notebook) {
|
||||
if (userService.checkUserIdExist(notebook.getUserId())) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
if (!checkNotebookIdExist(notebook.getId())) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.updateById(notebook);
|
||||
int result = notebookMapper.updateById(notebook);
|
||||
if (result == 0) {
|
||||
throw new ServiceException("更新笔记本失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Notebook getNotebook(Long notebookId) {
|
||||
if (!userService.checkUserIdExist(notebookId)) {
|
||||
public NotebookVO getNotebook(Long notebookId) {
|
||||
if (!checkNotebookIdExist(notebookId)) {
|
||||
throw new ServiceException("笔记本不存在");
|
||||
}
|
||||
|
||||
return notebookMapper.selectById(notebookId);
|
||||
Notebook notebook = notebookMapper.selectById(notebookId);
|
||||
NotebookVO notebookVO = new NotebookVO();
|
||||
BeanUtils.copyProperties(notebook, notebookVO);
|
||||
|
||||
return notebookVO;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +112,7 @@ public class NotebookServiceImpl implements NotebookService {
|
||||
*/
|
||||
@Override
|
||||
public List<Notebook> getNotebookListByUserId(Long userId) {
|
||||
if (!userService.checkUserIdExist(userId)) {
|
||||
if (userService.checkUserIdExist(userId)) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ public class UserServiceImpl implements UserService {
|
||||
*/
|
||||
@Override
|
||||
public boolean checkUserIdExist(Long userId) {
|
||||
return userMapper.exists(new LambdaQueryWrapper<User>().eq(User::getId, userId));
|
||||
return !userMapper.exists(new LambdaQueryWrapper<User>().eq(User::getId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user