@@ -46,11 +46,11 @@ public ResponseEntity<Book> getBook(@PathVariable Long id){
4646 else return new ResponseEntity <>(book , HttpStatus .OK );
4747 }
4848
49- @ GetMapping ("/by-topics -id/{topicIds}" )
49+ @ GetMapping ("/by-topic -id/{topicIds}" )
5050 public ResponseEntity <List <Book >> getAllBooksByTopicId (@ PathVariable Long [] topicIds ){
5151 List <Book > allBooksByTopicId = new ArrayList <>();
5252 for (Long topicId : topicIds ){
53- List <Book > booksByTopicId = bookService .findByTopicId (topicId );
53+ List <Book > booksByTopicId = bookService .findByTopicsId (topicId );
5454 if (!booksByTopicId .isEmpty ()){
5555 allBooksByTopicId .addAll (booksByTopicId );
5656 }
@@ -61,6 +61,20 @@ public ResponseEntity<List<Book>> getAllBooksByTopicId(@PathVariable Long [] top
6161 else return new ResponseEntity <>(allBooksByTopicId , HttpStatus .OK );
6262 }
6363
64+ @ GetMapping ("/by-author-id/{authorIds}" )
65+ public ResponseEntity <List <Book >> getAllBooksByAuthorId (@ PathVariable Long [] authorIds ){
66+ List <Book > allBooksByAuthorId = new ArrayList <>();
67+ for (Long authorId : authorIds ){
68+ List <Book > booksByAuthorId = bookService .findByAuthorsId (authorId );
69+ if (!booksByAuthorId .isEmpty ()){
70+ allBooksByAuthorId .addAll (booksByAuthorId );
71+ }
72+ }
73+ if (allBooksByAuthorId .isEmpty ()){
74+ return new ResponseEntity <>(allBooksByAuthorId , HttpStatus .NO_CONTENT );
75+ }
76+ else return new ResponseEntity <>(allBooksByAuthorId , HttpStatus .OK );
77+ }
6478
6579 @ PostMapping ("" )
6680 public ResponseEntity <Book > saveBook (@ RequestBody @ Valid Book book , BindingResult bindingResult ,
0 commit comments