Added find endpoint
This commit is contained in:
@@ -18,6 +18,11 @@ public class NotesController {
|
||||
return noteService.getAll();
|
||||
}
|
||||
|
||||
@GetMapping("/note/{id}")
|
||||
public Note find(@PathVariable Long id){
|
||||
return noteService.find(id);
|
||||
}
|
||||
|
||||
@PostMapping("/note")
|
||||
public Note add(@RequestBody Note note){
|
||||
return noteService.add(note);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.tokishu.note.service;
|
||||
|
||||
import net.tokishu.note.model.Note;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -17,6 +19,16 @@ public class NoteService {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public Note find(Long id) {
|
||||
for (Note note : notes) {
|
||||
if (note.getId().equals(id)) {
|
||||
return note;
|
||||
}
|
||||
}
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Note not found");
|
||||
}
|
||||
|
||||
|
||||
public Note add(Note note){
|
||||
note.setId(idGenerator.getAndIncrement());
|
||||
notes.add(note);
|
||||
|
||||
Reference in New Issue
Block a user