-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service에서 mapper 제거 및 repository에서 mapper를 이용한 객체 변환 수행
- Loading branch information
Showing
10 changed files
with
78 additions
and
54 deletions.
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
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