Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ data class BookSearchResponse private constructor(
val searchCategoryName: String?,
val books: List<BookSummary>
) {
fun from(updatedBooks: List<BookSummary>): BookSearchResponse {
return BookSearchResponse(
version = this.version,
title = this.title,
link = this.link,
pubDate = this.pubDate,
totalResults = this.totalResults,
startIndex = this.startIndex,
itemsPerPage = this.itemsPerPage,
query = this.query,
searchCategoryId = this.searchCategoryId,
searchCategoryName = this.searchCategoryName,
books = updatedBooks
)
}
Comment on lines +22 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

data class의 copy() 메서드 활용으로 간소화 가능

새로운 from 메서드의 구현은 올바르지만, data class의 내장 copy() 메서드를 사용하면 더 간결하게 작성할 수 있습니다.

다음과 같이 리팩토링할 수 있습니다:

-    fun from(updatedBooks: List<BookSummary>): BookSearchResponse {
-        return BookSearchResponse(
-            version = this.version,
-            title = this.title,
-            link = this.link,
-            pubDate = this.pubDate,
-            totalResults = this.totalResults,
-            startIndex = this.startIndex,
-            itemsPerPage = this.itemsPerPage,
-            query = this.query,
-            searchCategoryId = this.searchCategoryId,
-            searchCategoryName = this.searchCategoryName,
-            books = updatedBooks
-        )
-    }
+    fun from(updatedBooks: List<BookSummary>): BookSearchResponse {
+        return this.copy(books = updatedBooks)
+    }
🤖 Prompt for AI Agents
In apis/src/main/kotlin/org/yapp/apis/book/dto/response/BookSearchResponse.kt
around lines 22 to 36, the from() method manually copies all properties to
create a new instance. Refactor this method to use the data class's built-in
copy() function with the updatedBooks list as the only changed property, which
simplifies the code and reduces redundancy.


companion object {
fun from(response: AladinSearchResponse): BookSearchResponse {
val books = response.item?.mapNotNull { BookSummary.fromAladinItem(it) } ?: emptyList()
Expand Down Expand Up @@ -62,7 +78,7 @@ data class BookSearchResponse private constructor(
author = item.author,
publisher = item.publisher,
coverImageUrl = item.cover,
userBookStatus = BookStatus.BEFORE_READING
userBookStatus = BookStatus.BEFORE_REGISTRATION
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ class BookUseCase(

val userBooksReponse = userBookService.findAllByUserIdAndBookIsbnIn(UserBooksByIsbnsRequest.of(userId, isbns))
val statusMap = userBooksReponse.associateBy({ it.bookIsbn }, { it.status })
searchResponse.books.forEach { bookSummary ->

val updatedBooks = searchResponse.books.map { bookSummary ->
statusMap[bookSummary.isbn]?.let { status ->
bookSummary.updateStatus(status)
}
} ?: bookSummary
}
return searchResponse

return searchResponse.from(updatedBooks)
}

fun getBookDetail(bookDetailRequest: BookDetailRequest): BookDetailResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.yapp.domain.userbook

enum class BookStatus {
BEFORE_REGISTRATION, // 등록 전
BEFORE_READING, // 읽기 전
READING, // 읽는 중
COMPLETED // 완독
Expand Down