File tree Expand file tree Collapse file tree 6 files changed +63
-18
lines changed
Identity_Field/src/main/java/com/iluwater/fieild Expand file tree Collapse file tree 6 files changed +63
-18
lines changed Original file line number Diff line number Diff line change 33import com .iluwater .fieild .model .Book ;
44import com .iluwater .fieild .services .BookService ;
55import org .springframework .beans .factory .annotation .Autowired ;
6- import org .springframework .web .bind .annotation .*;
6+ import org .springframework .web .bind .annotation .GetMapping ;
7+ import org .springframework .web .bind .annotation .PathVariable ;
8+ import org .springframework .web .bind .annotation .PostMapping ;
9+ import org .springframework .web .bind .annotation .RequestBody ;
10+ import org .springframework .web .bind .annotation .RequestMapping ;
11+ import org .springframework .web .bind .annotation .RestController ;
712
13+ /**
14+ * Book Controller class to call the bookService methods.
15+ * */
816@ RestController
917@ RequestMapping ("/books" )
1018public class BookController {
1119 private final BookService bookService ;
1220
21+ /**
22+ * Constructor.
23+ * */
1324 @ Autowired
1425 public BookController (BookService bookService ) {
1526 this .bookService = bookService ;
1627 }
17-
18- // Create a new book
28+ /**
29+ * Create a new book.
30+ * */
1931 @ PostMapping
2032 public Book createBook (@ RequestBody String title , String author ) {
21- return bookService .createBook (title ,author );
33+ return bookService .createBook (title , author );
2234 }
2335
24- // Get a book by ID
36+ /**
37+ * Get a book by ID.
38+ * */
2539 @ GetMapping ("/{id}" )
2640 public Book getBook (@ PathVariable Long id ) {
2741 return bookService .getBookById (id );
Original file line number Diff line number Diff line change 2727import javax .persistence .Entity ;
2828import lombok .Getter ;
2929import lombok .Setter ;
30+ /**
31+ * Setters & Getters.
32+ */
3033@ Setter
3134@ Getter
3235@ Entity
3336public class Book extends DomainObject {
3437 private String title ;
3538 private String author ;
3639
37- /** Book constructor*/
40+ /**
41+ * Book constructor.
42+ */
3843 public Book (String title , String author ) {
3944 this .title = title ;
4045 this .author = author ;
Original file line number Diff line number Diff line change 2424*/
2525package com .iluwater .fieild .model ;
2626import java .util .regex .Pattern ;
27-
27+ import javax . persistence . Entity ;
2828import lombok .Getter ;
2929import lombok .Setter ;
30- import javax .persistence .Entity ;
3130
31+ /**
32+ * Setters & Getters.
33+ */
3234@ Setter
3335@ Getter
3436@ Entity
3537public class Client extends DomainObject {
3638 private static final String EMAIL_REGEX = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\ .[a-zA-Z]{2,}$" ;
3739 private String name ;
3840 private String email ;
39-
41+ /**
42+ * Client Constructor.
43+ */
4044 public Client (String name , String email ) {
4145 Pattern pattern = Pattern .compile (EMAIL_REGEX );
4246 this .name = name ;
Original file line number Diff line number Diff line change 3838import lombok .Getter ;
3939import lombok .Setter ;
4040
41+ /**
42+ * Setters & Getters.
43+ */
4144@ Getter
4245@ Setter
4346@ MappedSuperclass
Original file line number Diff line number Diff line change 11package com .iluwater .fieild .services ;
22import com .iluwater .fieild .model .Book ;
3- import org .springframework .stereotype .Repository ;
43import javax .persistence .EntityManager ;
5-
4+ import org .springframework .stereotype .Repository ;
5+ /**
6+ * Book Repo.
7+ */
68@ Repository
79public class BookRepository {
810 private final EntityManager entityManager ;
9-
11+ /**
12+ * BookRepository constructor.
13+ */
1014 public BookRepository (EntityManager entityManager ) {
1115 this .entityManager = entityManager ;
1216 }
13-
17+ /**
18+ * create a new book.
19+ */
1420 public Book createBook (String title , String author ) {
1521 Book book = new Book (title , author );
1622 entityManager .persist (book );
1723 return book ;
1824 }
25+ /**
26+ * ID Getter.
27+ */
1928 public Book getBookById (Long id ) {
2029 return entityManager .find (Book .class , id );
2130 }
Original file line number Diff line number Diff line change 11package com .iluwater .fieild .services ;
2- import com .iluwater .fieild .model .* ;
2+ import com .iluwater .fieild .model .Book ;
33import org .springframework .beans .factory .annotation .Autowired ;
44import org .springframework .stereotype .Service ;
5-
5+ /**
6+ * Book Service Class to implement the logic.
7+ */
68@ Service
79public class BookService {
810
911 private final BookRepository bookRepository ;
10-
12+ /**
13+ * BookService constructor.
14+ */
1115 @ Autowired
1216 public BookService (BookRepository bookRepository ) {
1317 this .bookRepository = bookRepository ;
1418 }
15- public Book createBook (String title ,String author ) {
16- return bookRepository .createBook (title ,author );
19+ /**
20+ * Create a new book.
21+ */
22+ public Book createBook (String title , String author ) {
23+ return bookRepository .createBook (title , author );
1724 }
25+ /**
26+ * ID Getter.
27+ */
1828 public Book getBookById (Long id ) {
1929 return bookRepository .getBookById (id );
2030 }
You can’t perform that action at this time.
0 commit comments