File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
src/main/java/id/my/hendisantika/books Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 3
3
import id .my .hendisantika .books .entity .Books ;
4
4
import id .my .hendisantika .books .repository .BooksRepository ;
5
5
import lombok .RequiredArgsConstructor ;
6
+ import lombok .extern .slf4j .Slf4j ;
6
7
import org .springframework .stereotype .Service ;
7
8
8
9
import java .util .List ;
17
18
* Time: 07.57
18
19
* To change this template use File | Settings | File Templates.
19
20
*/
21
+ @ Slf4j
20
22
@ Service
21
23
@ RequiredArgsConstructor
22
24
public class BooksService {
23
25
24
26
private final BooksRepository bookRepository ;
25
27
26
28
public List <Books > getAllBooks () {
29
+ log .info ("Getting all books" );
27
30
return bookRepository .findAll ();
28
31
}
29
32
30
33
public Books getBookById (Long id ) {
34
+ log .info ("Getting book by id {}" , id );
31
35
return bookRepository .findById (id ).orElse (null );
32
36
}
33
37
}
You can’t perform that action at this time.
0 commit comments