File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed
apis/src/main/kotlin/org/yapp/apis/book/service
domain/src/main/kotlin/org/yapp/domain/book
global-utils/src/main/kotlin/org/yapp/globalutils/validator Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ class BookManagementService(
1010 private val bookDomainService : BookDomainService
1111) {
1212 fun findOrCreateBook (request : BookCreateRequest ): BookCreateResponse {
13- val isbn = request.validIsbn()
14-
15- val bookVO = bookDomainService.findByIsbn(isbn)
16- return BookCreateResponse .from(bookVO)
13+ val bookInfoVO = bookDomainService.findOrCreate(
14+ request.validIsbn(),
15+ request.validTitle(),
16+ request.validAuthor(),
17+ request.validAuthor(),
18+ request.coverImageUrl,
19+ request.publicationYear,
20+ request.description
21+ )
22+ return BookCreateResponse .from(bookInfoVO)
1723 }
1824
1925}
Original file line number Diff line number Diff line change @@ -15,6 +15,36 @@ class BookDomainService(
1515 return BookInfoVO .newInstance(book)
1616 }
1717
18+ fun findOrCreate (
19+ isbn : String ,
20+ title : String ,
21+ author : String ,
22+ publisher : String ,
23+ coverImageUrl : String ,
24+ publicationYear : Int? = null,
25+ description : String? = null
26+ ): BookInfoVO {
27+ return findByIsbnOrNull(isbn) ? : run {
28+ val newBook = Book .create(
29+ isbn = isbn,
30+ title = title,
31+ author = author,
32+ publisher = publisher,
33+ coverImageUrl = coverImageUrl,
34+ publicationYear = publicationYear,
35+ description = description
36+ )
37+ val savedBook = bookRepository.save(newBook)
38+ BookInfoVO .newInstance(savedBook)
39+ }
40+ }
41+
42+ private fun findByIsbnOrNull (isbn : String ): BookInfoVO ? {
43+ val book = bookRepository.findById(isbn)
44+ return book?.let { BookInfoVO .newInstance(it) }
45+ }
46+
47+
1848 fun save (
1949 isbn : String ,
2050 title : String ,
Original file line number Diff line number Diff line change 11package org.yapp.globalutils.validator
22
33object IsbnValidator {
4- private val ISBN_REGEX = Regex (" ^(\\ d {10}|\\ d {13})$" )
4+ private val ISBN_REGEX = Regex (" ^(. {10}|. {13})$" )
55
66 fun isValidIsbn (isbn : String ): Boolean {
77 return isbn.matches(ISBN_REGEX )
You can’t perform that action at this time.
0 commit comments