|
|
|
@ -1,9 +1,11 @@ |
|
|
|
|
package com.bupt.note.Controller; |
|
|
|
|
|
|
|
|
|
import com.bupt.note.Model.Note; |
|
|
|
|
import com.bupt.note.Model.Paper; |
|
|
|
|
import com.bupt.note.Model.PaperNote; |
|
|
|
|
import com.bupt.note.Repository.NoteRepository; |
|
|
|
|
import com.bupt.note.Repository.PaperNoteRepository; |
|
|
|
|
import com.bupt.note.Repository.PaperRepository; |
|
|
|
|
import com.bupt.note.ResponseData.ResponseData; |
|
|
|
|
import com.bupt.note.ResponseData.ResponseDataUtil; |
|
|
|
|
import com.bupt.note.dto.DeleteNote; |
|
|
|
@ -23,6 +25,7 @@ import java.io.IOException; |
|
|
|
|
import java.io.Writer; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
@RestController |
|
|
|
|
@RequestMapping(value = "/v1/api/notes") |
|
|
|
@ -34,6 +37,9 @@ public class NoteController { |
|
|
|
|
@Autowired |
|
|
|
|
private PaperNoteRepository paperNoteRepository; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private PaperRepository paperRepository; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private FileService fileService; |
|
|
|
|
|
|
|
|
@ -107,8 +113,8 @@ public class NoteController { |
|
|
|
|
* @param username |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("list/{id}") |
|
|
|
|
public ResponseData list(@PathVariable("id") Long paperId,@CookieValue("user") String username) { |
|
|
|
|
@GetMapping({"list/{id}","list"}) |
|
|
|
|
public ResponseData list(@PathVariable(value = "id",required = false) Long paperId,NoteForm noteForm,@CookieValue("user") String username) { |
|
|
|
|
try { |
|
|
|
|
Page<Note> list = new Page<>(); |
|
|
|
|
list.setTotal(noteRepository.count()); |
|
|
|
@ -117,9 +123,21 @@ public class NoteController { |
|
|
|
|
if (StringUtils.isNotEmpty(username)) { |
|
|
|
|
predicates.add(criteriaBuilder.equal(root.get("userName"), username)); |
|
|
|
|
} |
|
|
|
|
predicates.add(criteriaBuilder.equal(root.get("paperId"),paperId)); |
|
|
|
|
if(StringUtils.isNotEmpty(noteForm.getNoteTitle())){ |
|
|
|
|
predicates.add(criteriaBuilder.like(root.get("noteTitle"),"%"+noteForm.getNoteTitle()+"%")); |
|
|
|
|
} |
|
|
|
|
if(StringUtils.isNotEmpty(noteForm.getNoteContent())){ |
|
|
|
|
predicates.add(criteriaBuilder.like(root.get("noteContent"),"%"+noteForm.getNoteContent()+"%")); |
|
|
|
|
} |
|
|
|
|
if(paperId!=null) { |
|
|
|
|
predicates.add(criteriaBuilder.equal(root.get("paperId"), paperId)); |
|
|
|
|
} |
|
|
|
|
return criteriaQuery.where(predicates.toArray(new Predicate[0])).getRestriction(); |
|
|
|
|
}); |
|
|
|
|
noteList.forEach(note -> { |
|
|
|
|
Optional<Paper> paper=paperRepository.findById(note.getPaperId()); |
|
|
|
|
paper.ifPresent(note::setPaper); |
|
|
|
|
}); |
|
|
|
|
list.setData(noteList); |
|
|
|
|
return ResponseDataUtil.buildSuccess(list); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|