|
1 | 1 | package com.learn.SpringBootRESTService;
|
2 | 2 |
|
| 3 | +import java.util.List; |
| 4 | + |
3 | 5 | import org.springframework.beans.factory.annotation.Autowired;
|
4 | 6 | import org.springframework.http.HttpHeaders;
|
5 | 7 | import org.springframework.http.HttpStatus;
|
6 | 8 | import org.springframework.http.HttpStatusCode;
|
7 | 9 | import org.springframework.http.ResponseEntity;
|
| 10 | +import org.springframework.web.bind.annotation.GetMapping; |
| 11 | +import org.springframework.web.bind.annotation.PathVariable; |
8 | 12 | import org.springframework.web.bind.annotation.PostMapping;
|
9 | 13 | import org.springframework.web.bind.annotation.RequestBody;
|
| 14 | +import org.springframework.web.bind.annotation.RequestParam; |
10 | 15 | import org.springframework.web.bind.annotation.RestController;
|
| 16 | +import org.springframework.web.server.ResponseStatusException; |
11 | 17 |
|
12 | 18 | import com.learn.SpringBootRESTService.Service.LibraryService;
|
13 | 19 | import com.learn.SpringBootRESTService.repository.LibraryRepository;
|
@@ -48,6 +54,22 @@ public ResponseEntity addBookImplementation(@RequestBody Library library) {
|
48 | 54 |
|
49 | 55 | }
|
50 | 56 |
|
| 57 | + @GetMapping("/getBooks/{id}") |
| 58 | + public Library getBookById(@PathVariable(value = "id")String id) { |
| 59 | + try{ |
| 60 | + Library lib = repository.findById(id).get(); |
| 61 | + |
| 62 | + return lib; |
| 63 | + } |
| 64 | + catch (Exception e) { |
| 65 | + throw new ResponseStatusException(HttpStatus.NOT_FOUND); |
| 66 | + } |
| 67 | + |
| 68 | + } |
51 | 69 |
|
| 70 | + @GetMapping("/getBooks/author") |
| 71 | + public List<Library> getBookByAuthorName(@RequestParam(value = "authorname")String authorname) { |
| 72 | + return repository.findAllByAuthor(authorname); |
| 73 | + } |
52 | 74 |
|
53 | 75 | }
|
0 commit comments