-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
메서드의 파라미터 타입을 추상화 타입으로 변경 #6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package com.study.bookcafe.dao; | ||
|
||
import com.study.bookcafe.domain.Borrow; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface BorrowRepository { | ||
|
||
Borrow findById(long borrowId); | ||
Borrow save(Borrow borrow); | ||
List<Borrow> save(List<Borrow> borrowList); | ||
List<Borrow> save(Collection<Borrow> borrows); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 28 additions & 15 deletions
43
src/main/java/com/study/bookcafe/dao/TestBorrowRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,51 @@ | ||
package com.study.bookcafe.dao; | ||
|
||
import com.study.bookcafe.domain.Book; | ||
import com.study.bookcafe.domain.Borrow; | ||
import com.study.bookcafe.domain.Member; | ||
import com.study.bookcafe.entity.BookEntity; | ||
import com.study.bookcafe.entity.BorrowEntity; | ||
import com.study.bookcafe.entity.MemberEntity; | ||
import com.study.bookcafe.mapper.BorrowMapper; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Repository | ||
public class TestBorrowRepository implements BorrowRepository { | ||
Map<Long, Borrow> borrows = new HashMap<>(){{ | ||
put(1L, Borrow.builder() | ||
.member(Member.builder().id(1).build()) | ||
.book(Book.builder().id(1).ISBN(9788936433598L).build()).build()); | ||
put(2L, Borrow.builder() | ||
.member(Member.builder().id(1).build()) | ||
.book(Book.builder().id(2).ISBN(9788936433598L).build()).build()); | ||
|
||
private final BorrowMapper borrowMapper; | ||
|
||
public TestBorrowRepository(BorrowMapper borrowMapper) { | ||
this.borrowMapper = borrowMapper; | ||
} | ||
|
||
Map<Long, BorrowEntity> borrows = new HashMap<>(){{ | ||
put(1L, BorrowEntity.builder() | ||
.member(MemberEntity.builder().id(1).build()) | ||
.book(BookEntity.builder().id(1).ISBN(9788936433598L).build()).build()); | ||
put(2L, BorrowEntity.builder() | ||
.member(MemberEntity.builder().id(1).build()) | ||
.book(BookEntity.builder().id(2).ISBN(9788936433598L).build()).build()); | ||
put(3L, null); | ||
}}; | ||
|
||
public Borrow findById(long borrowId) { | ||
return borrows.get(borrowId); | ||
BorrowEntity borrowEntity = borrows.get(borrowId); | ||
return borrowMapper.toBorrow(borrowEntity); | ||
} | ||
|
||
public Borrow save(Borrow borrow) { | ||
return borrow; | ||
BorrowEntity borrowEntity = borrows.get(borrow.getId()); | ||
return borrowMapper.toBorrow(borrowEntity); | ||
} | ||
|
||
@Override | ||
public List<Borrow> save(List<Borrow> borrowList) { | ||
return borrowList | ||
.stream().filter(borrow -> borrows.containsKey(borrow.getId())) | ||
.map(borrow -> borrows.get(borrow.getId())).toList(); | ||
public List<Borrow> save(Collection<Borrow> borrows) { | ||
List<BorrowEntity> borrowEntities = borrows | ||
.stream().filter(borrow -> this.borrows.containsKey(borrow.getId())) | ||
.map(borrow -> this.borrows.get(borrow.getId())).toList(); | ||
return borrowMapper.toBorrowList(borrowEntities); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ | |
|
||
import com.study.bookcafe.domain.Book; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public interface BookService { | ||
// 도서 조회 (id) | ||
Book findById(long bookId); | ||
|
||
// 도서 목록 조회 (id list) | ||
List<Book> findByIdList(List<Long> bookIdList); | ||
List<Book> findByIdList(Collection<Long> bookIds); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드 명도 같이 변경하면 좋겠네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드를 변경하면서 메서드명을 보고도 아무생각없이 지나쳤던 제 자신을 반성합니다... 😥 |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적으론 이전 방식도 좋았습니다 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전 방식이 books의 타입이 <Long, Book> 이었던 코드를 말씀하시는 건가요?! 테스트 객체지만 추후에 DB와는 Entity로 주고받기 때문에 미리 느낌을 보려고 변경해봤습니다 ㅎㅎ