Added find endpoint

This commit is contained in:
Tokishu
2025-05-15 01:33:24 +02:00
parent 18f5330e7b
commit 16ba0ef41c
3 changed files with 35 additions and 3 deletions
@@ -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);