Skip to content

Commit 5522638

Browse files
committed
feat: Add BooksController🫸🌀✏️📗🐧🐳⬆
1 parent 3341f5e commit 5522638

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package id.my.hendisantika.books.controller;
2+
3+
import id.my.hendisantika.books.entity.Books;
4+
import id.my.hendisantika.books.service.BooksService;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.PathVariable;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
import java.util.List;
13+
14+
/**
15+
* Created by IntelliJ IDEA.
16+
* Project : books
17+
* User: hendisantika
18+
* Email: hendisantika@gmail.com
19+
* Telegram : @hendisantika34
20+
* Date: 01/11/24
21+
* Time: 07.58
22+
* To change this template use File | Settings | File Templates.
23+
*/
24+
@RestController
25+
@RequestMapping("/api/books")
26+
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
27+
public class BooksController {
28+
29+
private final BooksService booksService;
30+
31+
@GetMapping
32+
public List<Books> getAllBooks() {
33+
return booksService.getAllBooks();
34+
}
35+
36+
@GetMapping("/{id}")
37+
public Books getBookById(@PathVariable Long id) {
38+
return booksService.getBookById(id);
39+
}
40+
}

src/main/java/id/my/hendisantika/books/service/BooksService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import id.my.hendisantika.books.entity.Books;
44
import id.my.hendisantika.books.repository.BooksRepository;
55
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
67
import org.springframework.stereotype.Service;
78

89
import java.util.List;
@@ -17,17 +18,20 @@
1718
* Time: 07.57
1819
* To change this template use File | Settings | File Templates.
1920
*/
21+
@Slf4j
2022
@Service
2123
@RequiredArgsConstructor
2224
public class BooksService {
2325

2426
private final BooksRepository bookRepository;
2527

2628
public List<Books> getAllBooks() {
29+
log.info("Getting all books");
2730
return bookRepository.findAll();
2831
}
2932

3033
public Books getBookById(Long id) {
34+
log.info("Getting book by id {}", id);
3135
return bookRepository.findById(id).orElse(null);
3236
}
3337
}

0 commit comments

Comments
 (0)