Skip to content

Commit f2d7a06

Browse files
author
Javad Bagirov
committed
findAllById post service
1 parent 6baecb8 commit f2d7a06

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/main/java/org/blog/app/controller/PostController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public List<Post> all() {
1919
return postService.findAll();
2020
}
2121

22+
@GetMapping("/id")
23+
public Post get(@RequestParam("id") Long id) {
24+
return postService.findAllBy(id);
25+
}
26+
2227
@PostMapping()
2328
public Post save(@RequestBody Post post) {
2429
return postService.save(post);

src/main/java/org/blog/app/service/PostService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public List<Post> findAll(){
1717
return postRepository.findAll();
1818
}
1919

20+
public Post findAllBy(Long id) {
21+
return postRepository.findById(id).orElse(null);
22+
}
23+
2024
public Post save(Post post) {
2125
return postRepository.save(post);
2226
}

0 commit comments

Comments
 (0)