79 lines
2.3 KiB
Java
79 lines
2.3 KiB
Java
package com.devassistant.note.controller;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.devassistant.framework.common.RestResult;
|
|
import com.devassistant.note.model.NoteRecord;
|
|
import com.devassistant.note.service.NoteService;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@RequestMapping("note")
|
|
public class NoteController {
|
|
|
|
private final NoteService noteService;
|
|
|
|
/**
|
|
* 添加笔记
|
|
*
|
|
* @param body 笔记内容
|
|
* @return 添加结果
|
|
*/
|
|
@PostMapping("/addNote")
|
|
public RestResult<?> addNote(@RequestBody JSONObject body, HttpServletRequest request) {
|
|
String content = body.getString("content");
|
|
NoteRecord noteRecord = noteService.addNote(content, request);
|
|
return RestResult.genSuccessResult(noteRecord);
|
|
}
|
|
|
|
/**
|
|
* 修改笔记
|
|
*
|
|
* @param body 笔记内容
|
|
* @return 添加结果
|
|
*/
|
|
@PostMapping("/updateNote")
|
|
public RestResult<?> updateNote(@RequestBody JSONObject body, HttpServletRequest request) {
|
|
Integer id = body.getInteger("id");
|
|
String content = body.getString("content");
|
|
noteService.updateNote(id, content, request);
|
|
return RestResult.genSuccessResult();
|
|
}
|
|
|
|
/**
|
|
* 获取笔记列表
|
|
*
|
|
* @param body 查询条件
|
|
* @return 笔记列表
|
|
*/
|
|
@PostMapping("/getNoteList")
|
|
public RestResult<?> getNoteList(@RequestBody JSONObject body) {
|
|
String searchText = body.getString("searchText");
|
|
List<NoteRecord> noteList = noteService.getNoteList(searchText);
|
|
return RestResult.genSuccessResult(noteList);
|
|
}
|
|
|
|
/**
|
|
* 删除笔记
|
|
*
|
|
* @param body 查询条件
|
|
* @return 删除结果
|
|
*/
|
|
@PostMapping("/delNote")
|
|
public RestResult<?> delNote(@RequestBody JSONObject body) {
|
|
Integer id = body.getInteger("id");
|
|
noteService.delNote(id);
|
|
return RestResult.genSuccessResult();
|
|
}
|
|
|
|
}
|