From f86ab6658a2f167c654544e8fa41358df941b59d Mon Sep 17 00:00:00 2001 From: dohun Date: Tue, 7 Jan 2025 18:50:35 +0900 Subject: [PATCH] =?UTF-8?q?CQRS=20=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20-=20=EB=A0=88=EC=9D=B4=EC=96=B4=EC=97=90=EC=84=9C?= =?UTF-8?q?=20command=EC=99=80=20query=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20-?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC=20=EA=B0=9D=EC=B2=B4=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EB=8A=94=20=EA=B5=AC=EC=84=B1=20=EA=B0=9D=EC=B2=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(MemberView,=20BookView)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/borrow/BorrowService.java | 20 ----- .../application/borrow/BorrowServiceImpl.java | 64 -------------- .../{ => command}/book/BookService.java | 7 +- .../{ => command}/book/BookServiceImpl.java | 7 +- .../command/borrow/BorrowService.java | 15 ++++ .../command/borrow/BorrowServiceImpl.java | 50 +++++++++++ .../command/member/MemberService.java | 16 ++++ .../member/MemberServiceImpl.java | 41 +++------ .../application/member/MemberService.java | 23 ----- .../query/book/BookQueryService.java | 15 ++++ .../query/book/BookQueryServiceImpl.java | 39 +++++++++ .../query/borrow/BorrowQueryService.java | 11 +++ .../query/borrow/BorrowQueryServiceImpl.java | 29 +++++++ .../query/member/MemberQueryService.java | 15 ++++ .../query/member/MemberQueryServiceImpl.java | 43 ++++++++++ .../bookcafe/domain/borrow/BorrowDetails.java | 17 ---- .../domain/borrow/BorrowRepository.java | 14 --- .../domain/{ => command}/book/Book.java | 2 +- .../{ => command}/book/BookRepository.java | 4 +- .../domain/{ => command}/book/Inventory.java | 2 +- .../domain/{ => command}/borrow/Borrow.java | 6 +- .../command/borrow/BorrowRepository.java | 11 +++ .../domain/{ => command}/borrow/Period.java | 4 +- .../{ => command}/borrow/Reservation.java | 2 +- .../domain/{ => command}/member/Level.java | 2 +- .../domain/{ => command}/member/Member.java | 8 +- .../member/MemberRepository.java | 3 +- .../query/book/BookQueryRepository.java | 11 +++ .../bookcafe/domain/query/book/BookView.java | 20 +++++ .../domain/query/borrow/BorrowDetails.java | 18 ++++ .../query/borrow/BorrowQueryRepository.java | 10 +++ .../query/member/MemberQueryRepository.java | 6 ++ .../domain/query/member/MemberView.java | 19 +++++ .../borrow/TestBorrowRepository.java | 85 ------------------- .../book/TestBookRepository.java | 10 ++- .../command/borrow/ReservationEntity.java | 15 ++++ .../command/borrow/TestBorrowRepository.java | 58 +++++++++++++ .../member/GeneralMemberRepository.java | 31 +++++++ .../member/GeneralMemberRepository.java | 32 ------- .../{ => query}/book/BookEntity.java | 4 +- .../query/book/TestBookQueryRepository.java | 42 +++++++++ .../{ => query}/borrow/BorrowEntity.java | 8 +- .../{ => query}/borrow/ReservationEntity.java | 2 +- .../borrow/TestBorrowQueryRepository.java | 49 +++++++++++ .../member/GeneralMemberQueryRepository.java | 31 +++++++ .../{ => query}/member/MemberEntity.java | 4 +- .../bookcafe/interfaces/book/BookDto.java | 2 +- .../bookcafe/interfaces/book/BookMapper.java | 4 +- .../book/BooksReservationDetails.java | 2 +- .../bookcafe/interfaces/borrow/BorrowDto.java | 2 +- .../interfaces/borrow/BorrowMapper.java | 8 +- .../interfaces/member/MemberController.java | 16 ++-- .../bookcafe/interfaces/member/MemberDto.java | 2 +- .../interfaces/member/MemberMapper.java | 4 +- .../member/MembersReservationDetails.java | 2 +- .../study/bookcafe/book/CanBorrowTest.java | 4 +- .../com/study/bookcafe/book/MapperTest.java | 6 +- .../com/study/bookcafe/borrow/MapperTest.java | 16 ++-- .../com/study/bookcafe/borrow/PeriodTest.java | 2 +- .../com/study/bookcafe/member/BorrowTest.java | 20 +++-- .../study/bookcafe/member/CanBorrowTest.java | 4 +- .../com/study/bookcafe/member/MapperTest.java | 6 +- .../study/bookcafe/member/ReserveTest.java | 10 +-- 63 files changed, 665 insertions(+), 370 deletions(-) delete mode 100644 src/main/java/com/study/bookcafe/application/borrow/BorrowService.java delete mode 100644 src/main/java/com/study/bookcafe/application/borrow/BorrowServiceImpl.java rename src/main/java/com/study/bookcafe/application/{ => command}/book/BookService.java (69%) rename src/main/java/com/study/bookcafe/application/{ => command}/book/BookServiceImpl.java (83%) create mode 100644 src/main/java/com/study/bookcafe/application/command/borrow/BorrowService.java create mode 100644 src/main/java/com/study/bookcafe/application/command/borrow/BorrowServiceImpl.java create mode 100644 src/main/java/com/study/bookcafe/application/command/member/MemberService.java rename src/main/java/com/study/bookcafe/application/{ => command}/member/MemberServiceImpl.java (66%) delete mode 100644 src/main/java/com/study/bookcafe/application/member/MemberService.java create mode 100644 src/main/java/com/study/bookcafe/application/query/book/BookQueryService.java create mode 100644 src/main/java/com/study/bookcafe/application/query/book/BookQueryServiceImpl.java create mode 100644 src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryService.java create mode 100644 src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryServiceImpl.java create mode 100644 src/main/java/com/study/bookcafe/application/query/member/MemberQueryService.java create mode 100644 src/main/java/com/study/bookcafe/application/query/member/MemberQueryServiceImpl.java delete mode 100644 src/main/java/com/study/bookcafe/domain/borrow/BorrowDetails.java delete mode 100644 src/main/java/com/study/bookcafe/domain/borrow/BorrowRepository.java rename src/main/java/com/study/bookcafe/domain/{ => command}/book/Book.java (94%) rename src/main/java/com/study/bookcafe/domain/{ => command}/book/BookRepository.java (77%) rename src/main/java/com/study/bookcafe/domain/{ => command}/book/Inventory.java (90%) rename src/main/java/com/study/bookcafe/domain/{ => command}/borrow/Borrow.java (85%) create mode 100644 src/main/java/com/study/bookcafe/domain/command/borrow/BorrowRepository.java rename src/main/java/com/study/bookcafe/domain/{ => command}/borrow/Period.java (91%) rename src/main/java/com/study/bookcafe/domain/{ => command}/borrow/Reservation.java (86%) rename src/main/java/com/study/bookcafe/domain/{ => command}/member/Level.java (95%) rename src/main/java/com/study/bookcafe/domain/{ => command}/member/Member.java (89%) rename src/main/java/com/study/bookcafe/domain/{ => command}/member/MemberRepository.java (59%) create mode 100644 src/main/java/com/study/bookcafe/domain/query/book/BookQueryRepository.java create mode 100644 src/main/java/com/study/bookcafe/domain/query/book/BookView.java create mode 100644 src/main/java/com/study/bookcafe/domain/query/borrow/BorrowDetails.java create mode 100644 src/main/java/com/study/bookcafe/domain/query/borrow/BorrowQueryRepository.java create mode 100644 src/main/java/com/study/bookcafe/domain/query/member/MemberQueryRepository.java create mode 100644 src/main/java/com/study/bookcafe/domain/query/member/MemberView.java delete mode 100644 src/main/java/com/study/bookcafe/infrastructure/borrow/TestBorrowRepository.java rename src/main/java/com/study/bookcafe/infrastructure/{ => command}/book/TestBookRepository.java (83%) create mode 100644 src/main/java/com/study/bookcafe/infrastructure/command/borrow/ReservationEntity.java create mode 100644 src/main/java/com/study/bookcafe/infrastructure/command/borrow/TestBorrowRepository.java create mode 100644 src/main/java/com/study/bookcafe/infrastructure/command/member/GeneralMemberRepository.java delete mode 100644 src/main/java/com/study/bookcafe/infrastructure/member/GeneralMemberRepository.java rename src/main/java/com/study/bookcafe/infrastructure/{ => query}/book/BookEntity.java (85%) create mode 100644 src/main/java/com/study/bookcafe/infrastructure/query/book/TestBookQueryRepository.java rename src/main/java/com/study/bookcafe/infrastructure/{ => query}/borrow/BorrowEntity.java (66%) rename src/main/java/com/study/bookcafe/infrastructure/{ => query}/borrow/ReservationEntity.java (85%) create mode 100644 src/main/java/com/study/bookcafe/infrastructure/query/borrow/TestBorrowQueryRepository.java create mode 100644 src/main/java/com/study/bookcafe/infrastructure/query/member/GeneralMemberQueryRepository.java rename src/main/java/com/study/bookcafe/infrastructure/{ => query}/member/MemberEntity.java (75%) diff --git a/src/main/java/com/study/bookcafe/application/borrow/BorrowService.java b/src/main/java/com/study/bookcafe/application/borrow/BorrowService.java deleted file mode 100644 index e114a23..0000000 --- a/src/main/java/com/study/bookcafe/application/borrow/BorrowService.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.study.bookcafe.application.borrow; - -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.domain.borrow.BorrowDetails; - -import java.util.Collection; -import java.util.List; - -public interface BorrowService { - - // 도서 대출 저장 - Borrow save(Borrow borrow); - List save(Collection borrows); - // 도서 대출 조회 - List findBorrows(long memberId); - - // 도서 예약 저장 - Reservation save(Reservation reservation); -} \ No newline at end of file diff --git a/src/main/java/com/study/bookcafe/application/borrow/BorrowServiceImpl.java b/src/main/java/com/study/bookcafe/application/borrow/BorrowServiceImpl.java deleted file mode 100644 index 9e4e11a..0000000 --- a/src/main/java/com/study/bookcafe/application/borrow/BorrowServiceImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.study.bookcafe.application.borrow; - -import com.study.bookcafe.domain.borrow.BorrowRepository; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.domain.borrow.BorrowDetails; -import org.springframework.stereotype.Service; - -import java.util.Collection; -import java.util.List; - -@Service -public class BorrowServiceImpl implements BorrowService { - private final BorrowRepository borrowRepository; - - public BorrowServiceImpl(BorrowRepository borrowRepository) { - this.borrowRepository = borrowRepository; - } - - /** - * 새로운 대출을 저장한다. - * - * @param borrow 대출 정보 - * @return 생성한 대출 정보 - */ - @Override - public Borrow save(Borrow borrow) { - return borrowRepository.save(borrow); - } - - /** - * 새로운 여러 대출들을 저장한다. - * - * @param borrows 대출 목록 - * @return 생성한 대출 정보 목록 - */ - @Override - public List save(Collection borrows) { - return borrowRepository.save(borrows); - } - - /** - * 대출 목록을 조회한다. - * - * @param memberId 회원 ID - * @return 대출 목록 - */ - @Override - public List findBorrows(long memberId) { - return borrowRepository.findByMemberId(memberId); - } - - /** - * 새로운 예약을 저장한다. - * - * @param reservation 예악 정보 - * @return 생성한 예약 정보 - */ - @Override - public Reservation save(Reservation reservation) { - return borrowRepository.save(reservation); - } - -} diff --git a/src/main/java/com/study/bookcafe/application/book/BookService.java b/src/main/java/com/study/bookcafe/application/command/book/BookService.java similarity index 69% rename from src/main/java/com/study/bookcafe/application/book/BookService.java rename to src/main/java/com/study/bookcafe/application/command/book/BookService.java index 51f3472..fb9e7c4 100644 --- a/src/main/java/com/study/bookcafe/application/book/BookService.java +++ b/src/main/java/com/study/bookcafe/application/command/book/BookService.java @@ -1,14 +1,15 @@ -package com.study.bookcafe.application.book; - -import com.study.bookcafe.domain.book.Book; +package com.study.bookcafe.application.command.book; +import com.study.bookcafe.domain.command.book.Book; import java.util.Collection; import java.util.List; public interface BookService { + // 도서 조회 (id) Book findById(long bookId); // 도서 목록 조회 (id list) List findByIds(Collection bookIds); + } diff --git a/src/main/java/com/study/bookcafe/application/book/BookServiceImpl.java b/src/main/java/com/study/bookcafe/application/command/book/BookServiceImpl.java similarity index 83% rename from src/main/java/com/study/bookcafe/application/book/BookServiceImpl.java rename to src/main/java/com/study/bookcafe/application/command/book/BookServiceImpl.java index 6484491..52b2587 100644 --- a/src/main/java/com/study/bookcafe/application/book/BookServiceImpl.java +++ b/src/main/java/com/study/bookcafe/application/command/book/BookServiceImpl.java @@ -1,9 +1,8 @@ -package com.study.bookcafe.application.book; +package com.study.bookcafe.application.command.book; -import com.study.bookcafe.domain.book.BookRepository; -import com.study.bookcafe.domain.book.Book; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.book.BookRepository; import org.springframework.stereotype.Service; - import java.util.Collection; import java.util.List; diff --git a/src/main/java/com/study/bookcafe/application/command/borrow/BorrowService.java b/src/main/java/com/study/bookcafe/application/command/borrow/BorrowService.java new file mode 100644 index 0000000..28855e5 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/command/borrow/BorrowService.java @@ -0,0 +1,15 @@ +package com.study.bookcafe.application.command.borrow; + +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.Reservation; +import java.util.Collection; + +public interface BorrowService { + + // 도서 대출 저장 + void save(Borrow borrow); + void save(Collection borrows); + + // 도서 예약 저장 + void save(Reservation reservation); +} \ No newline at end of file diff --git a/src/main/java/com/study/bookcafe/application/command/borrow/BorrowServiceImpl.java b/src/main/java/com/study/bookcafe/application/command/borrow/BorrowServiceImpl.java new file mode 100644 index 0000000..39e8f6a --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/command/borrow/BorrowServiceImpl.java @@ -0,0 +1,50 @@ +package com.study.bookcafe.application.command.borrow; + +import com.study.bookcafe.domain.command.borrow.BorrowRepository; +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.Reservation; +import org.springframework.stereotype.Service; +import java.util.Collection; + +@Service +public class BorrowServiceImpl implements BorrowService { + private final BorrowRepository borrowRepository; + + public BorrowServiceImpl(BorrowRepository borrowRepository) { + this.borrowRepository = borrowRepository; + } + + /** + * 새로운 대출을 저장한다. + * + * @param borrow 대출 정보 + * @return 생성한 대출 정보 + */ + @Override + public void save(Borrow borrow) { + borrowRepository.save(borrow); + } + + /** + * 새로운 여러 대출들을 저장한다. + * + * @param borrows 대출 목록 + * @return 생성한 대출 정보 목록 + */ + @Override + public void save(Collection borrows) { + borrowRepository.save(borrows); + } + + /** + * 새로운 예약을 저장한다. + * + * @param reservation 예악 정보 + * @return 생성한 예약 정보 + */ + @Override + public void save(Reservation reservation) { + borrowRepository.save(reservation); + } + +} diff --git a/src/main/java/com/study/bookcafe/application/command/member/MemberService.java b/src/main/java/com/study/bookcafe/application/command/member/MemberService.java new file mode 100644 index 0000000..c08ba58 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/command/member/MemberService.java @@ -0,0 +1,16 @@ +package com.study.bookcafe.application.command.member; + +import com.study.bookcafe.domain.command.member.Member; +import java.util.Collection; + +public interface MemberService { + + // 회원 조회 (id) + Member findById(long memberId); + + // 도서 대출 + void borrowBook(long memberId, Collection bookIds); + + // 도서 예약 + void reserveBook(long memberId, long bookId); +} diff --git a/src/main/java/com/study/bookcafe/application/member/MemberServiceImpl.java b/src/main/java/com/study/bookcafe/application/command/member/MemberServiceImpl.java similarity index 66% rename from src/main/java/com/study/bookcafe/application/member/MemberServiceImpl.java rename to src/main/java/com/study/bookcafe/application/command/member/MemberServiceImpl.java index c973f94..0ab661d 100644 --- a/src/main/java/com/study/bookcafe/application/member/MemberServiceImpl.java +++ b/src/main/java/com/study/bookcafe/application/command/member/MemberServiceImpl.java @@ -1,15 +1,15 @@ -package com.study.bookcafe.application.member; +package com.study.bookcafe.application.command.member; -import com.study.bookcafe.application.book.BookService; -import com.study.bookcafe.application.borrow.BorrowService; +import com.study.bookcafe.application.command.book.BookService; +import com.study.bookcafe.application.command.borrow.BorrowService; import com.study.bookcafe.application.exception.BorrowableException; import com.study.bookcafe.application.exception.NonBorrowableMemberException; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.domain.member.MemberRepository; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.member.Member; -import com.study.bookcafe.domain.borrow.BorrowDetails; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.Reservation; +import com.study.bookcafe.domain.command.member.Member; +import com.study.bookcafe.domain.command.member.MemberRepository; +import com.study.bookcafe.domain.query.borrow.BorrowDetails; import org.springframework.stereotype.Service; import java.util.Collection; @@ -44,38 +44,25 @@ public Member findById(long memberId) { * * @param memberId 회원 ID * @param bookIds 도서 ID 목록 - * @return 대출 */ @Override - public List borrowBook(long memberId, Collection bookIds) { + public void borrowBook(long memberId, Collection bookIds) { Member member = findById(memberId); List books = bookService.findByIds(bookIds); List borrows = member.borrowBook(books); - if (borrows.isEmpty()) return borrows; + if (borrows.isEmpty()) return; - return borrowService.save(borrows); - } - - /** - * 회원의 대출 목록을 조회한다. - * - * @param memberId 회원 ID - * @return 대출 목록 - */ - @Override - public List findBorrows(long memberId) { - return borrowService.findBorrows(memberId); + borrowService.save(borrows); } /** * 회원이 도서 대출을 예약한다. * @param memberId 회원 ID * @param bookId 도서 ID - * @return 예약 */ @Override - public Reservation reserveBook(long memberId, long bookId) { + public void reserveBook(long memberId, long bookId) { Member member = findById(memberId); Book book = bookService.findById(bookId); @@ -91,6 +78,6 @@ public Reservation reserveBook(long memberId, long bookId) { Reservation reservation = member.reserveBook(book); - return borrowService.save(reservation); + borrowService.save(reservation); } } \ No newline at end of file diff --git a/src/main/java/com/study/bookcafe/application/member/MemberService.java b/src/main/java/com/study/bookcafe/application/member/MemberService.java deleted file mode 100644 index 2b9c156..0000000 --- a/src/main/java/com/study/bookcafe/application/member/MemberService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.study.bookcafe.application.member; - -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.domain.member.Member; -import com.study.bookcafe.domain.borrow.BorrowDetails; - -import java.util.Collection; -import java.util.List; - -public interface MemberService { - - // 회원 조회 (id) - Member findById(long memberId); - - // 도서 대출 - List borrowBook(long memberId, Collection bookIds); - // 도서 대출 조회 - List findBorrows(long memberId); - - // 도서 예약 - Reservation reserveBook(long memberId, long bookId); -} diff --git a/src/main/java/com/study/bookcafe/application/query/book/BookQueryService.java b/src/main/java/com/study/bookcafe/application/query/book/BookQueryService.java new file mode 100644 index 0000000..9e2a486 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/query/book/BookQueryService.java @@ -0,0 +1,15 @@ +package com.study.bookcafe.application.query.book; + +import com.study.bookcafe.domain.query.book.BookView; + +import java.util.Collection; +import java.util.List; + +public interface BookQueryService { + + // 도서 조회 (id) + BookView findById(long bookId); + + // 도서 목록 조회 (id list) + List findByIds(Collection bookIds); +} diff --git a/src/main/java/com/study/bookcafe/application/query/book/BookQueryServiceImpl.java b/src/main/java/com/study/bookcafe/application/query/book/BookQueryServiceImpl.java new file mode 100644 index 0000000..2f37434 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/query/book/BookQueryServiceImpl.java @@ -0,0 +1,39 @@ +package com.study.bookcafe.application.query.book; + +import com.study.bookcafe.domain.query.book.BookQueryRepository; +import com.study.bookcafe.domain.query.book.BookView; +import org.springframework.stereotype.Service; +import java.util.Collection; +import java.util.List; + +@Service +public class BookQueryServiceImpl implements BookQueryService { + + private final BookQueryRepository bookQueryRepository; + + public BookQueryServiceImpl(BookQueryRepository bookQueryRepository) { + this.bookQueryRepository = bookQueryRepository; + } + + /** + * 도서를 ID로 조회한다. + * + * @param bookId 도서 ID + * @return 도서 + */ + @Override + public BookView findById(long bookId) { + return bookQueryRepository.findById(bookId); + } + + /** + * 도서를 ID 목록으로 조회한다. + * + * @param bookIds 도서 ID 목록 + * @return 도서 목록 + */ + @Override + public List findByIds(Collection bookIds) { + return bookQueryRepository.findByIds(bookIds); + } +} diff --git a/src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryService.java b/src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryService.java new file mode 100644 index 0000000..71be5d7 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryService.java @@ -0,0 +1,11 @@ +package com.study.bookcafe.application.query.borrow; + +import com.study.bookcafe.domain.query.borrow.BorrowDetails; +import java.util.List; + +public interface BorrowQueryService { + + // 도서 대출 조회 + List findBorrows(long memberId); + +} \ No newline at end of file diff --git a/src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryServiceImpl.java b/src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryServiceImpl.java new file mode 100644 index 0000000..15da183 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/query/borrow/BorrowQueryServiceImpl.java @@ -0,0 +1,29 @@ +package com.study.bookcafe.application.query.borrow; + +import com.study.bookcafe.domain.query.borrow.BorrowDetails; +import com.study.bookcafe.domain.command.borrow.BorrowRepository; +import com.study.bookcafe.domain.query.borrow.BorrowQueryRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class BorrowQueryServiceImpl implements BorrowQueryService { + private final BorrowQueryRepository borrowQueryRepository; + + public BorrowQueryServiceImpl(BorrowQueryRepository borrowQueryRepository) { + this.borrowQueryRepository = borrowQueryRepository; + } + + /** + * 대출 목록을 조회한다. + * + * @param memberId 회원 ID + * @return 대출 목록 + */ + @Override + public List findBorrows(long memberId) { + return borrowQueryRepository.findByMemberId(memberId); + } + +} diff --git a/src/main/java/com/study/bookcafe/application/query/member/MemberQueryService.java b/src/main/java/com/study/bookcafe/application/query/member/MemberQueryService.java new file mode 100644 index 0000000..724ae01 --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/query/member/MemberQueryService.java @@ -0,0 +1,15 @@ +package com.study.bookcafe.application.query.member; + +import com.study.bookcafe.domain.query.borrow.BorrowDetails; +import com.study.bookcafe.domain.command.member.Member; + +import java.util.List; + +public interface MemberQueryService { + + // 회원 조회 (id) + Member findById(long memberId); + + // 도서 대출 조회 + List findBorrows(long memberId); +} diff --git a/src/main/java/com/study/bookcafe/application/query/member/MemberQueryServiceImpl.java b/src/main/java/com/study/bookcafe/application/query/member/MemberQueryServiceImpl.java new file mode 100644 index 0000000..c13484a --- /dev/null +++ b/src/main/java/com/study/bookcafe/application/query/member/MemberQueryServiceImpl.java @@ -0,0 +1,43 @@ +package com.study.bookcafe.application.query.member; + +import com.study.bookcafe.application.query.borrow.BorrowQueryService; +import com.study.bookcafe.domain.query.borrow.BorrowDetails; +import com.study.bookcafe.domain.command.member.Member; +import com.study.bookcafe.domain.command.member.MemberRepository; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class MemberQueryServiceImpl implements MemberQueryService { + + private final MemberRepository memberRepository; + private final BorrowQueryService borrowService; + + public MemberQueryServiceImpl(MemberRepository memberRepository, BorrowQueryService borrowService) { + this.memberRepository = memberRepository; + this.borrowService = borrowService; + } + + /** + * 회원을 ID로 조회한다. + * + * @param memberId 회원 ID + * @return 회원 + */ + @Override + public Member findById(long memberId) { + return memberRepository.findById(memberId); + } + + /** + * 회원의 대출 목록을 조회한다. + * + * @param memberId 회원 ID + * @return 대출 목록 + */ + @Override + public List findBorrows(long memberId) { + return borrowService.findBorrows(memberId); + } +} \ No newline at end of file diff --git a/src/main/java/com/study/bookcafe/domain/borrow/BorrowDetails.java b/src/main/java/com/study/bookcafe/domain/borrow/BorrowDetails.java deleted file mode 100644 index f197c70..0000000 --- a/src/main/java/com/study/bookcafe/domain/borrow/BorrowDetails.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.study.bookcafe.domain.borrow; - -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.member.Member; -import lombok.Builder; -import lombok.Getter; -import java.time.LocalDateTime; - -@Builder -@Getter -public class BorrowDetails { - private long id; // 대출 ID - private Member member; // 회원 - private Book book; // 도서 - private LocalDateTime time; // 대출 시간 - private Period period; // 대출 기간 -} diff --git a/src/main/java/com/study/bookcafe/domain/borrow/BorrowRepository.java b/src/main/java/com/study/bookcafe/domain/borrow/BorrowRepository.java deleted file mode 100644 index 78a3e15..0000000 --- a/src/main/java/com/study/bookcafe/domain/borrow/BorrowRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.study.bookcafe.domain.borrow; - -import java.util.Collection; -import java.util.List; - -public interface BorrowRepository { - - Borrow findById(long borrowId); - List findByMemberId(long memberId); - Borrow save(Borrow borrow); - List save(Collection borrows); - Reservation save(Reservation reservation); - -} diff --git a/src/main/java/com/study/bookcafe/domain/book/Book.java b/src/main/java/com/study/bookcafe/domain/command/book/Book.java similarity index 94% rename from src/main/java/com/study/bookcafe/domain/book/Book.java rename to src/main/java/com/study/bookcafe/domain/command/book/Book.java index 186cee4..8306a1e 100644 --- a/src/main/java/com/study/bookcafe/domain/book/Book.java +++ b/src/main/java/com/study/bookcafe/domain/command/book/Book.java @@ -1,4 +1,4 @@ -package com.study.bookcafe.domain.book; +package com.study.bookcafe.domain.command.book; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/domain/book/BookRepository.java b/src/main/java/com/study/bookcafe/domain/command/book/BookRepository.java similarity index 77% rename from src/main/java/com/study/bookcafe/domain/book/BookRepository.java rename to src/main/java/com/study/bookcafe/domain/command/book/BookRepository.java index b7791e8..1f62cd8 100644 --- a/src/main/java/com/study/bookcafe/domain/book/BookRepository.java +++ b/src/main/java/com/study/bookcafe/domain/command/book/BookRepository.java @@ -1,9 +1,11 @@ -package com.study.bookcafe.domain.book; +package com.study.bookcafe.domain.command.book; import java.util.Collection; import java.util.List; public interface BookRepository { + Book findById(long bookId); List findByIds(Collection bookIds); + } diff --git a/src/main/java/com/study/bookcafe/domain/book/Inventory.java b/src/main/java/com/study/bookcafe/domain/command/book/Inventory.java similarity index 90% rename from src/main/java/com/study/bookcafe/domain/book/Inventory.java rename to src/main/java/com/study/bookcafe/domain/command/book/Inventory.java index 12a0e35..9513672 100644 --- a/src/main/java/com/study/bookcafe/domain/book/Inventory.java +++ b/src/main/java/com/study/bookcafe/domain/command/book/Inventory.java @@ -1,4 +1,4 @@ -package com.study.bookcafe.domain.book; +package com.study.bookcafe.domain.command.book; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/domain/borrow/Borrow.java b/src/main/java/com/study/bookcafe/domain/command/borrow/Borrow.java similarity index 85% rename from src/main/java/com/study/bookcafe/domain/borrow/Borrow.java rename to src/main/java/com/study/bookcafe/domain/command/borrow/Borrow.java index 79dd7dd..810b0cb 100644 --- a/src/main/java/com/study/bookcafe/domain/borrow/Borrow.java +++ b/src/main/java/com/study/bookcafe/domain/command/borrow/Borrow.java @@ -1,7 +1,7 @@ -package com.study.bookcafe.domain.borrow; +package com.study.bookcafe.domain.command.borrow; -import com.study.bookcafe.domain.member.Member; -import com.study.bookcafe.domain.book.Book; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.member.Member; import lombok.*; import java.time.LocalDateTime; diff --git a/src/main/java/com/study/bookcafe/domain/command/borrow/BorrowRepository.java b/src/main/java/com/study/bookcafe/domain/command/borrow/BorrowRepository.java new file mode 100644 index 0000000..d0e3e34 --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/command/borrow/BorrowRepository.java @@ -0,0 +1,11 @@ +package com.study.bookcafe.domain.command.borrow; + +import java.util.Collection; + +public interface BorrowRepository { + + void save(Borrow borrow); + void save(Collection borrows); + void save(Reservation reservation); + +} diff --git a/src/main/java/com/study/bookcafe/domain/borrow/Period.java b/src/main/java/com/study/bookcafe/domain/command/borrow/Period.java similarity index 91% rename from src/main/java/com/study/bookcafe/domain/borrow/Period.java rename to src/main/java/com/study/bookcafe/domain/command/borrow/Period.java index e94eb05..80162e4 100644 --- a/src/main/java/com/study/bookcafe/domain/borrow/Period.java +++ b/src/main/java/com/study/bookcafe/domain/command/borrow/Period.java @@ -1,6 +1,6 @@ -package com.study.bookcafe.domain.borrow; +package com.study.bookcafe.domain.command.borrow; -import com.study.bookcafe.domain.member.Level; +import com.study.bookcafe.domain.command.member.Level; import lombok.EqualsAndHashCode; import lombok.NonNull; import java.time.LocalDate; diff --git a/src/main/java/com/study/bookcafe/domain/borrow/Reservation.java b/src/main/java/com/study/bookcafe/domain/command/borrow/Reservation.java similarity index 86% rename from src/main/java/com/study/bookcafe/domain/borrow/Reservation.java rename to src/main/java/com/study/bookcafe/domain/command/borrow/Reservation.java index 4df3fbe..6453165 100644 --- a/src/main/java/com/study/bookcafe/domain/borrow/Reservation.java +++ b/src/main/java/com/study/bookcafe/domain/command/borrow/Reservation.java @@ -1,4 +1,4 @@ -package com.study.bookcafe.domain.borrow; +package com.study.bookcafe.domain.command.borrow; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/domain/member/Level.java b/src/main/java/com/study/bookcafe/domain/command/member/Level.java similarity index 95% rename from src/main/java/com/study/bookcafe/domain/member/Level.java rename to src/main/java/com/study/bookcafe/domain/command/member/Level.java index 8757595..9143cb4 100644 --- a/src/main/java/com/study/bookcafe/domain/member/Level.java +++ b/src/main/java/com/study/bookcafe/domain/command/member/Level.java @@ -1,4 +1,4 @@ -package com.study.bookcafe.domain.member; +package com.study.bookcafe.domain.command.member; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/domain/member/Member.java b/src/main/java/com/study/bookcafe/domain/command/member/Member.java similarity index 89% rename from src/main/java/com/study/bookcafe/domain/member/Member.java rename to src/main/java/com/study/bookcafe/domain/command/member/Member.java index ade6522..a48b756 100644 --- a/src/main/java/com/study/bookcafe/domain/member/Member.java +++ b/src/main/java/com/study/bookcafe/domain/command/member/Member.java @@ -1,8 +1,8 @@ -package com.study.bookcafe.domain.member; +package com.study.bookcafe.domain.command.member; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.borrow.Reservation; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.Reservation; import lombok.Builder; import lombok.Getter; import java.time.LocalDateTime; diff --git a/src/main/java/com/study/bookcafe/domain/member/MemberRepository.java b/src/main/java/com/study/bookcafe/domain/command/member/MemberRepository.java similarity index 59% rename from src/main/java/com/study/bookcafe/domain/member/MemberRepository.java rename to src/main/java/com/study/bookcafe/domain/command/member/MemberRepository.java index 806adf6..5f321a3 100644 --- a/src/main/java/com/study/bookcafe/domain/member/MemberRepository.java +++ b/src/main/java/com/study/bookcafe/domain/command/member/MemberRepository.java @@ -1,4 +1,5 @@ -package com.study.bookcafe.domain.member; +package com.study.bookcafe.domain.command.member; + public interface MemberRepository { Member findById(long memberId); diff --git a/src/main/java/com/study/bookcafe/domain/query/book/BookQueryRepository.java b/src/main/java/com/study/bookcafe/domain/query/book/BookQueryRepository.java new file mode 100644 index 0000000..7429a44 --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/query/book/BookQueryRepository.java @@ -0,0 +1,11 @@ +package com.study.bookcafe.domain.query.book; + +import java.util.Collection; +import java.util.List; + +public interface BookQueryRepository { + + BookView findById(long bookId); + List findByIds(Collection bookIds); + +} diff --git a/src/main/java/com/study/bookcafe/domain/query/book/BookView.java b/src/main/java/com/study/bookcafe/domain/query/book/BookView.java new file mode 100644 index 0000000..7644d3c --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/query/book/BookView.java @@ -0,0 +1,20 @@ +package com.study.bookcafe.domain.query.book; + +import com.study.bookcafe.domain.command.book.Inventory; +import lombok.Builder; +import lombok.Getter; + +import java.sql.Date; + +@Builder +@Getter +public class BookView { + private long id; // 도서 번호 + private long ISBN; // 국제표준도서번호 + private String title; // 도서 명 + private String author; // 저자 명 + private String publisher; // 출판사 + private Date publishDate; // 출판일 + private double price; // 도서 가격 + private Inventory inventory; // 도서 상태 정보 (재고, 대출, 예약) +} diff --git a/src/main/java/com/study/bookcafe/domain/query/borrow/BorrowDetails.java b/src/main/java/com/study/bookcafe/domain/query/borrow/BorrowDetails.java new file mode 100644 index 0000000..b62bde0 --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/query/borrow/BorrowDetails.java @@ -0,0 +1,18 @@ +package com.study.bookcafe.domain.query.borrow; + +import com.study.bookcafe.domain.command.borrow.Period; +import com.study.bookcafe.domain.query.book.BookView; +import com.study.bookcafe.domain.query.member.MemberView; +import lombok.Builder; +import lombok.Getter; +import java.time.LocalDateTime; + +@Builder +@Getter +public class BorrowDetails { + private long id; // 대출 ID + private MemberView member; // 회원 + private BookView book; // 도서 + private LocalDateTime time; // 대출 시간 + private Period period; // 대출 기간 +} diff --git a/src/main/java/com/study/bookcafe/domain/query/borrow/BorrowQueryRepository.java b/src/main/java/com/study/bookcafe/domain/query/borrow/BorrowQueryRepository.java new file mode 100644 index 0000000..26616bd --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/query/borrow/BorrowQueryRepository.java @@ -0,0 +1,10 @@ +package com.study.bookcafe.domain.query.borrow; + +import java.util.List; + +public interface BorrowQueryRepository { + + BorrowDetails findById(long borrowId); + List findByMemberId(long memberId); + +} diff --git a/src/main/java/com/study/bookcafe/domain/query/member/MemberQueryRepository.java b/src/main/java/com/study/bookcafe/domain/query/member/MemberQueryRepository.java new file mode 100644 index 0000000..dac634b --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/query/member/MemberQueryRepository.java @@ -0,0 +1,6 @@ +package com.study.bookcafe.domain.query.member; + + +public interface MemberQueryRepository { + MemberView findById(long memberId); +} diff --git a/src/main/java/com/study/bookcafe/domain/query/member/MemberView.java b/src/main/java/com/study/bookcafe/domain/query/member/MemberView.java new file mode 100644 index 0000000..f976d08 --- /dev/null +++ b/src/main/java/com/study/bookcafe/domain/query/member/MemberView.java @@ -0,0 +1,19 @@ +package com.study.bookcafe.domain.query.member; + +import com.study.bookcafe.domain.command.member.Level; +import lombok.Builder; +import lombok.Getter; +import java.time.LocalDateTime; + +@Builder +@Getter +public class MemberView { + private long id; // 회원 ID + private String password; // 회원 Password + private String name; // 회원 이름 + private Level level; // 회원 등급 + private int borrowCount; // 현재 대출 권수 + + private LocalDateTime createDate; // 회원 가입 일자 + private LocalDateTime updateDate; // 회원 수정 일자 +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/borrow/TestBorrowRepository.java b/src/main/java/com/study/bookcafe/infrastructure/borrow/TestBorrowRepository.java deleted file mode 100644 index c03d653..0000000 --- a/src/main/java/com/study/bookcafe/infrastructure/borrow/TestBorrowRepository.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.study.bookcafe.infrastructure.borrow; - -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.domain.member.Member; -import com.study.bookcafe.infrastructure.book.BookEntity; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.borrow.BorrowRepository; -import com.study.bookcafe.infrastructure.member.MemberEntity; -import com.study.bookcafe.domain.borrow.BorrowDetails; -import com.study.bookcafe.interfaces.borrow.BorrowMapper; -import org.springframework.stereotype.Repository; - -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Repository -public class TestBorrowRepository implements BorrowRepository { - - private final BorrowMapper borrowMapper; - - public TestBorrowRepository(BorrowMapper borrowMapper) { - this.borrowMapper = borrowMapper; - } - - Map borrows = new HashMap<>(){{ - put(1L, BorrowEntity.builder() - .member(MemberEntity.builder().id(1).build()) - .book(BookEntity.builder().id(1).ISBN(9788936433598L).build()) - .time(LocalDateTime.now()) - .build()); - put(2L, BorrowEntity.builder() - .member(MemberEntity.builder().id(1).build()) - .book(BookEntity.builder().id(2).ISBN(9788936433598L).build()) - .time(LocalDateTime.now()) - .build()); - put(3L, null); - }}; - - Map borrowDetails = new HashMap<>(){{ - put(1L, BorrowDetails.builder() - .member(Member.builder().id(1).build()) - .book(Book.builder().id(1).ISBN(9788936433598L).build()) - .time(LocalDateTime.now()) - .build()); - put(2L, BorrowDetails.builder() - .member(Member.builder().id(1).build()) - .book(Book.builder().id(2).ISBN(9788936433598L).build()) - .time(LocalDateTime.now()) - .build()); - }}; - - public Borrow findById(long borrowId) { - BorrowEntity borrowEntity = borrows.get(borrowId); - return borrowMapper.toBorrow(borrowEntity); - } - - @Override - public List findByMemberId(long memberId) { - return borrowDetails.values().stream() - .filter(borrow -> borrow.getMember().getId() == memberId) - .toList(); - } - - public Borrow save(Borrow borrow) { - BorrowEntity borrowEntity = borrows.get(borrow.getId()); - return borrowMapper.toBorrow(borrowEntity); - } - - @Override - public List save(Collection borrows) { - List borrowEntities = borrows - .stream().filter(borrow -> this.borrows.containsKey(borrow.getId())) - .map(borrow -> this.borrows.get(borrow.getId())).toList(); - return borrowMapper.toBorrows(borrowEntities); - } - - @Override - public Reservation save(Reservation reservation) { - return reservation; - } -} diff --git a/src/main/java/com/study/bookcafe/infrastructure/book/TestBookRepository.java b/src/main/java/com/study/bookcafe/infrastructure/command/book/TestBookRepository.java similarity index 83% rename from src/main/java/com/study/bookcafe/infrastructure/book/TestBookRepository.java rename to src/main/java/com/study/bookcafe/infrastructure/command/book/TestBookRepository.java index fd73565..331205a 100644 --- a/src/main/java/com/study/bookcafe/infrastructure/book/TestBookRepository.java +++ b/src/main/java/com/study/bookcafe/infrastructure/command/book/TestBookRepository.java @@ -1,8 +1,9 @@ -package com.study.bookcafe.infrastructure.book; +package com.study.bookcafe.infrastructure.command.book; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.book.BookRepository; -import com.study.bookcafe.domain.book.Inventory; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.book.BookRepository; +import com.study.bookcafe.domain.command.book.Inventory; +import com.study.bookcafe.infrastructure.query.book.BookEntity; import com.study.bookcafe.interfaces.book.BookMapper; import org.springframework.stereotype.Repository; @@ -41,4 +42,5 @@ public List findByIds(Collection bookIds) { .map(id -> books.get(id)).toList(); return bookMapper.toBookList(bookEntities); } + } diff --git a/src/main/java/com/study/bookcafe/infrastructure/command/borrow/ReservationEntity.java b/src/main/java/com/study/bookcafe/infrastructure/command/borrow/ReservationEntity.java new file mode 100644 index 0000000..ce7984f --- /dev/null +++ b/src/main/java/com/study/bookcafe/infrastructure/command/borrow/ReservationEntity.java @@ -0,0 +1,15 @@ +package com.study.bookcafe.infrastructure.command.borrow; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Builder +@Getter +public class ReservationEntity { + private long id; // 예약 번호 + private long memberId; // 회원 ID + private long bookId; // 도서 ID + private LocalDateTime time; // 예약 시간 +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/command/borrow/TestBorrowRepository.java b/src/main/java/com/study/bookcafe/infrastructure/command/borrow/TestBorrowRepository.java new file mode 100644 index 0000000..114e15a --- /dev/null +++ b/src/main/java/com/study/bookcafe/infrastructure/command/borrow/TestBorrowRepository.java @@ -0,0 +1,58 @@ +package com.study.bookcafe.infrastructure.command.borrow; + +import com.study.bookcafe.domain.command.borrow.Reservation; +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.BorrowRepository; +import com.study.bookcafe.infrastructure.query.book.BookEntity; +import com.study.bookcafe.infrastructure.query.borrow.BorrowEntity; +import com.study.bookcafe.infrastructure.query.member.MemberEntity; +import com.study.bookcafe.interfaces.borrow.BorrowMapper; +import org.springframework.stereotype.Repository; + +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Repository +public class TestBorrowRepository implements BorrowRepository { + + private final BorrowMapper borrowMapper; + + public TestBorrowRepository(BorrowMapper borrowMapper) { + this.borrowMapper = borrowMapper; + } + + Map borrows = new HashMap<>(){{ + put(1L, BorrowEntity.builder() + .member(MemberEntity.builder().id(1).build()) + .book(BookEntity.builder().id(1).ISBN(9788936433598L).build()) + .time(LocalDateTime.now()) + .build()); + put(2L, BorrowEntity.builder() + .member(MemberEntity.builder().id(1).build()) + .book(BookEntity.builder().id(2).ISBN(9788936433598L).build()) + .time(LocalDateTime.now()) + .build()); + put(3L, null); + }}; + + public void save(Borrow borrow) { + BorrowEntity borrowEntity = borrows.get(borrow.getId()); + borrowMapper.toBorrow(borrowEntity); + } + + @Override + public void save(Collection borrows) { + List borrowEntities = borrows + .stream().filter(borrow -> this.borrows.containsKey(borrow.getId())) + .map(borrow -> this.borrows.get(borrow.getId())).toList(); + borrowMapper.toBorrows(borrowEntities); + } + + @Override + public void save(Reservation reservation) { + + } +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/command/member/GeneralMemberRepository.java b/src/main/java/com/study/bookcafe/infrastructure/command/member/GeneralMemberRepository.java new file mode 100644 index 0000000..e7d16fe --- /dev/null +++ b/src/main/java/com/study/bookcafe/infrastructure/command/member/GeneralMemberRepository.java @@ -0,0 +1,31 @@ +package com.study.bookcafe.infrastructure.command.member; + +import com.study.bookcafe.domain.command.member.Level; +import com.study.bookcafe.domain.command.member.Member; +import com.study.bookcafe.domain.command.member.MemberRepository; +import com.study.bookcafe.interfaces.member.MemberMapper; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; +import java.util.Map; + +@Repository +public class GeneralMemberRepository implements MemberRepository { + + private final MemberMapper memberMapper; + + public GeneralMemberRepository(MemberMapper memberMapper) { + this.memberMapper = memberMapper; + } + + Map members = new HashMap<>(){{ + put(1L, Member.builder().id(1L).name("슈카").level(Level.BASIC).borrowCount(0).build()); + put(2L, Member.builder().id(2L).name("머스크").level(Level.WORM).borrowCount(3).build()); + put(3L, Member.builder().id(3L).name("트럼프").level(Level.LIBRARIAN).borrowCount(5).build()); + }}; + + @Override + public Member findById(long memberId) { + return members.get(memberId); + } +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/member/GeneralMemberRepository.java b/src/main/java/com/study/bookcafe/infrastructure/member/GeneralMemberRepository.java deleted file mode 100644 index 363f3c9..0000000 --- a/src/main/java/com/study/bookcafe/infrastructure/member/GeneralMemberRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.study.bookcafe.infrastructure.member; - -import com.study.bookcafe.domain.member.Level; -import com.study.bookcafe.domain.member.Member; -import com.study.bookcafe.domain.member.MemberRepository; -import com.study.bookcafe.interfaces.member.MemberMapper; -import org.springframework.stereotype.Repository; - -import java.util.HashMap; -import java.util.Map; - -@Repository -public class GeneralMemberRepository implements MemberRepository { - - private final MemberMapper memberMapper; - - public GeneralMemberRepository(MemberMapper memberMapper) { - this.memberMapper = memberMapper; - } - - Map members = new HashMap<>(){{ - put(1L, MemberEntity.builder().id(1L).name("슈카").level(Level.BASIC).borrowCount(0).build()); - put(2L, MemberEntity.builder().id(2L).name("머스크").level(Level.WORM).borrowCount(3).build()); - put(3L, MemberEntity.builder().id(3L).name("트럼프").level(Level.LIBRARIAN).borrowCount(5).build()); - }}; - - @Override - public Member findById(long memberId) { - MemberEntity memberEntity = members.get(memberId); - return memberMapper.toMember(memberEntity); - } -} diff --git a/src/main/java/com/study/bookcafe/infrastructure/book/BookEntity.java b/src/main/java/com/study/bookcafe/infrastructure/query/book/BookEntity.java similarity index 85% rename from src/main/java/com/study/bookcafe/infrastructure/book/BookEntity.java rename to src/main/java/com/study/bookcafe/infrastructure/query/book/BookEntity.java index 3f0865e..dfb6380 100644 --- a/src/main/java/com/study/bookcafe/infrastructure/book/BookEntity.java +++ b/src/main/java/com/study/bookcafe/infrastructure/query/book/BookEntity.java @@ -1,6 +1,6 @@ -package com.study.bookcafe.infrastructure.book; +package com.study.bookcafe.infrastructure.query.book; -import com.study.bookcafe.domain.book.Inventory; +import com.study.bookcafe.domain.command.book.Inventory; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/infrastructure/query/book/TestBookQueryRepository.java b/src/main/java/com/study/bookcafe/infrastructure/query/book/TestBookQueryRepository.java new file mode 100644 index 0000000..80bff0f --- /dev/null +++ b/src/main/java/com/study/bookcafe/infrastructure/query/book/TestBookQueryRepository.java @@ -0,0 +1,42 @@ +package com.study.bookcafe.infrastructure.query.book; + +import com.study.bookcafe.domain.command.book.Inventory; +import com.study.bookcafe.domain.query.book.BookQueryRepository; +import com.study.bookcafe.domain.query.book.BookView; +import com.study.bookcafe.interfaces.book.BookMapper; +import org.springframework.stereotype.Repository; + +import java.sql.Date; +import java.time.LocalDate; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Repository +public class TestBookQueryRepository implements BookQueryRepository { + + private final BookMapper bookMapper; + + public TestBookQueryRepository(BookMapper bookMapper) { + this.bookMapper = bookMapper; + } + + public static Map books = new HashMap<>(){{ + put(1L, BookView.builder().id(1L).ISBN(9788936433598L).title("채식주의자").author("한강").publisher("창비").publishDate(Date.valueOf(LocalDate.of(2007, 10, 30))) + .price(35000).inventory(new Inventory(5)).build()); + put(2L, BookView.builder().id(2L).ISBN(9788954651134L).title("흰").author("한강").publisher("문학동네").publishDate(Date.valueOf(LocalDate.of(2018, 4, 25))) + .price(13000).inventory(new Inventory(0)).build()); + }}; + + public BookView findById(long bookId) { + return books.get(bookId); + } + + @Override + public List findByIds(Collection bookIds) { + return bookIds.stream() + .filter(id -> books.containsKey(id)) + .map(id -> books.get(id)).toList(); + } +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/borrow/BorrowEntity.java b/src/main/java/com/study/bookcafe/infrastructure/query/borrow/BorrowEntity.java similarity index 66% rename from src/main/java/com/study/bookcafe/infrastructure/borrow/BorrowEntity.java rename to src/main/java/com/study/bookcafe/infrastructure/query/borrow/BorrowEntity.java index 20b4e78..941da89 100644 --- a/src/main/java/com/study/bookcafe/infrastructure/borrow/BorrowEntity.java +++ b/src/main/java/com/study/bookcafe/infrastructure/query/borrow/BorrowEntity.java @@ -1,8 +1,8 @@ -package com.study.bookcafe.infrastructure.borrow; +package com.study.bookcafe.infrastructure.query.borrow; -import com.study.bookcafe.domain.borrow.Period; -import com.study.bookcafe.infrastructure.book.BookEntity; -import com.study.bookcafe.infrastructure.member.MemberEntity; +import com.study.bookcafe.domain.command.borrow.Period; +import com.study.bookcafe.infrastructure.query.book.BookEntity; +import com.study.bookcafe.infrastructure.query.member.MemberEntity; import lombok.Builder; import lombok.Getter; import lombok.NonNull; diff --git a/src/main/java/com/study/bookcafe/infrastructure/borrow/ReservationEntity.java b/src/main/java/com/study/bookcafe/infrastructure/query/borrow/ReservationEntity.java similarity index 85% rename from src/main/java/com/study/bookcafe/infrastructure/borrow/ReservationEntity.java rename to src/main/java/com/study/bookcafe/infrastructure/query/borrow/ReservationEntity.java index 85c8025..1290773 100644 --- a/src/main/java/com/study/bookcafe/infrastructure/borrow/ReservationEntity.java +++ b/src/main/java/com/study/bookcafe/infrastructure/query/borrow/ReservationEntity.java @@ -1,4 +1,4 @@ -package com.study.bookcafe.infrastructure.borrow; +package com.study.bookcafe.infrastructure.query.borrow; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/infrastructure/query/borrow/TestBorrowQueryRepository.java b/src/main/java/com/study/bookcafe/infrastructure/query/borrow/TestBorrowQueryRepository.java new file mode 100644 index 0000000..89ab50f --- /dev/null +++ b/src/main/java/com/study/bookcafe/infrastructure/query/borrow/TestBorrowQueryRepository.java @@ -0,0 +1,49 @@ +package com.study.bookcafe.infrastructure.query.borrow; + +import com.study.bookcafe.domain.query.book.BookView; +import com.study.bookcafe.domain.query.borrow.BorrowDetails; +import com.study.bookcafe.domain.query.borrow.BorrowQueryRepository; +import com.study.bookcafe.domain.query.member.MemberView; +import com.study.bookcafe.interfaces.borrow.BorrowMapper; +import org.springframework.stereotype.Repository; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Repository +public class TestBorrowQueryRepository implements BorrowQueryRepository { + + private final BorrowMapper borrowMapper; + + public TestBorrowQueryRepository(BorrowMapper borrowMapper) { + this.borrowMapper = borrowMapper; + } + + Map borrowsDetails = new HashMap<>(){{ + put(1L, BorrowDetails.builder() + .member(MemberView.builder().id(1).build()) + .book(BookView.builder().id(1).ISBN(9788936433598L).build()) + .time(LocalDateTime.now()) + .build()); + put(2L, BorrowDetails.builder() + .member(MemberView.builder().id(1).build()) + .book(BookView.builder().id(2).ISBN(9788936433598L).build()) + .time(LocalDateTime.now()) + .build()); + }}; + + @Override + public BorrowDetails findById(long borrowId) { + return borrowsDetails.get(borrowId); + } + + @Override + public List findByMemberId(long memberId) { + return borrowsDetails.values().stream() + .filter(borrow -> borrow.getMember().getId() == memberId) + .toList(); + } + +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/query/member/GeneralMemberQueryRepository.java b/src/main/java/com/study/bookcafe/infrastructure/query/member/GeneralMemberQueryRepository.java new file mode 100644 index 0000000..692cfc6 --- /dev/null +++ b/src/main/java/com/study/bookcafe/infrastructure/query/member/GeneralMemberQueryRepository.java @@ -0,0 +1,31 @@ +package com.study.bookcafe.infrastructure.query.member; + +import com.study.bookcafe.domain.command.member.Level; +import com.study.bookcafe.domain.query.member.MemberQueryRepository; +import com.study.bookcafe.domain.query.member.MemberView; +import com.study.bookcafe.interfaces.member.MemberMapper; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; +import java.util.Map; + +@Repository +public class GeneralMemberQueryRepository implements MemberQueryRepository { + + private final MemberMapper memberMapper; + + public GeneralMemberQueryRepository(MemberMapper memberMapper) { + this.memberMapper = memberMapper; + } + + Map memberViews = new HashMap<>(){{ + put(1L, MemberView.builder().id(1L).name("슈카").level(Level.BASIC).borrowCount(0).build()); + put(2L, MemberView.builder().id(2L).name("머스크").level(Level.WORM).borrowCount(3).build()); + put(3L, MemberView.builder().id(3L).name("트럼프").level(Level.LIBRARIAN).borrowCount(5).build()); + }}; + + @Override + public MemberView findById(long memberId) { + return memberViews.get(memberId); + } +} diff --git a/src/main/java/com/study/bookcafe/infrastructure/member/MemberEntity.java b/src/main/java/com/study/bookcafe/infrastructure/query/member/MemberEntity.java similarity index 75% rename from src/main/java/com/study/bookcafe/infrastructure/member/MemberEntity.java rename to src/main/java/com/study/bookcafe/infrastructure/query/member/MemberEntity.java index 3dd49af..d0ac620 100644 --- a/src/main/java/com/study/bookcafe/infrastructure/member/MemberEntity.java +++ b/src/main/java/com/study/bookcafe/infrastructure/query/member/MemberEntity.java @@ -1,6 +1,6 @@ -package com.study.bookcafe.infrastructure.member; +package com.study.bookcafe.infrastructure.query.member; -import com.study.bookcafe.domain.member.Level; +import com.study.bookcafe.domain.command.member.Level; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/study/bookcafe/interfaces/book/BookDto.java b/src/main/java/com/study/bookcafe/interfaces/book/BookDto.java index 88f882c..a2d6971 100644 --- a/src/main/java/com/study/bookcafe/interfaces/book/BookDto.java +++ b/src/main/java/com/study/bookcafe/interfaces/book/BookDto.java @@ -1,6 +1,6 @@ package com.study.bookcafe.interfaces.book; -import com.study.bookcafe.domain.book.Inventory; +import com.study.bookcafe.domain.command.book.Inventory; import lombok.*; import java.sql.Date; diff --git a/src/main/java/com/study/bookcafe/interfaces/book/BookMapper.java b/src/main/java/com/study/bookcafe/interfaces/book/BookMapper.java index 821b369..c1563d4 100644 --- a/src/main/java/com/study/bookcafe/interfaces/book/BookMapper.java +++ b/src/main/java/com/study/bookcafe/interfaces/book/BookMapper.java @@ -1,7 +1,7 @@ package com.study.bookcafe.interfaces.book; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.infrastructure.book.BookEntity; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.infrastructure.query.book.BookEntity; import org.mapstruct.*; import java.util.List; diff --git a/src/main/java/com/study/bookcafe/interfaces/book/BooksReservationDetails.java b/src/main/java/com/study/bookcafe/interfaces/book/BooksReservationDetails.java index d4ec484..356e0ce 100644 --- a/src/main/java/com/study/bookcafe/interfaces/book/BooksReservationDetails.java +++ b/src/main/java/com/study/bookcafe/interfaces/book/BooksReservationDetails.java @@ -1,6 +1,6 @@ package com.study.bookcafe.interfaces.book; -import com.study.bookcafe.domain.member.Member; +import com.study.bookcafe.domain.command.member.Member; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowDto.java b/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowDto.java index 34f98db..0ab342f 100644 --- a/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowDto.java +++ b/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowDto.java @@ -1,6 +1,6 @@ package com.study.bookcafe.interfaces.borrow; -import com.study.bookcafe.domain.borrow.Period; +import com.study.bookcafe.domain.command.borrow.Period; import com.study.bookcafe.interfaces.member.MemberDto; import com.study.bookcafe.interfaces.book.BookDto; import lombok.*; diff --git a/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowMapper.java b/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowMapper.java index b62dce1..f0a880c 100644 --- a/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowMapper.java +++ b/src/main/java/com/study/bookcafe/interfaces/borrow/BorrowMapper.java @@ -1,10 +1,10 @@ package com.study.bookcafe.interfaces.borrow; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.infrastructure.borrow.ReservationEntity; +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.Reservation; +import com.study.bookcafe.infrastructure.command.borrow.ReservationEntity; +import com.study.bookcafe.infrastructure.query.borrow.BorrowEntity; import com.study.bookcafe.interfaces.book.BookMapper; -import com.study.bookcafe.infrastructure.borrow.BorrowEntity; import com.study.bookcafe.interfaces.member.MemberMapper; import jdk.jfr.Name; import org.mapstruct.*; diff --git a/src/main/java/com/study/bookcafe/interfaces/member/MemberController.java b/src/main/java/com/study/bookcafe/interfaces/member/MemberController.java index 01c1b33..888a264 100644 --- a/src/main/java/com/study/bookcafe/interfaces/member/MemberController.java +++ b/src/main/java/com/study/bookcafe/interfaces/member/MemberController.java @@ -1,11 +1,11 @@ package com.study.bookcafe.interfaces.member; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.member.Member; +import com.study.bookcafe.application.query.member.MemberQueryService; +import com.study.bookcafe.domain.command.member.Member; import com.study.bookcafe.interfaces.borrow.BorrowDto; import com.study.bookcafe.interfaces.borrow.RequestBorrowDto; import com.study.bookcafe.interfaces.borrow.BorrowMapper; -import com.study.bookcafe.application.member.MemberService; +import com.study.bookcafe.application.command.member.MemberService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -15,27 +15,29 @@ public class MemberController { private final MemberService memberService; + private final MemberQueryService memberQueryService; private final MemberMapper memberMapper; private final BorrowMapper borrowMapper; - public MemberController(MemberService memberService, MemberMapper memberMapper, BorrowMapper borrowMapper) { + public MemberController(MemberService memberService, MemberMapper memberMapper, BorrowMapper borrowMapper, MemberQueryService memberQueryService) { this.memberService = memberService; this.memberMapper = memberMapper; this.borrowMapper = borrowMapper; + this.memberQueryService = memberQueryService; } @GetMapping("/member/{id}") @ResponseBody public ResponseEntity member(@PathVariable long id) { - Member member = memberService.findById(id); + Member member = memberQueryService.findById(id); return ResponseEntity.ok(memberMapper.toMemberDto(member)); } @PostMapping("/member/borrow") @ResponseBody public ResponseEntity> borrowBook(@RequestBody RequestBorrowDto requestBorrowDto) { - List borrows = memberService.borrowBook(requestBorrowDto.getMemberId(), requestBorrowDto.getBookdIdList()); - return ResponseEntity.ok(borrowMapper.toBorrowDtos(borrows)); + memberService.borrowBook(requestBorrowDto.getMemberId(), requestBorrowDto.getBookdIdList()); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/com/study/bookcafe/interfaces/member/MemberDto.java b/src/main/java/com/study/bookcafe/interfaces/member/MemberDto.java index 4beab4c..67e20bd 100644 --- a/src/main/java/com/study/bookcafe/interfaces/member/MemberDto.java +++ b/src/main/java/com/study/bookcafe/interfaces/member/MemberDto.java @@ -1,6 +1,6 @@ package com.study.bookcafe.interfaces.member; -import com.study.bookcafe.domain.member.Level; +import com.study.bookcafe.domain.command.member.Level; import lombok.*; @Builder diff --git a/src/main/java/com/study/bookcafe/interfaces/member/MemberMapper.java b/src/main/java/com/study/bookcafe/interfaces/member/MemberMapper.java index ee4ecaa..e3f8832 100644 --- a/src/main/java/com/study/bookcafe/interfaces/member/MemberMapper.java +++ b/src/main/java/com/study/bookcafe/interfaces/member/MemberMapper.java @@ -1,7 +1,7 @@ package com.study.bookcafe.interfaces.member; -import com.study.bookcafe.domain.member.Member; -import com.study.bookcafe.infrastructure.member.MemberEntity; +import com.study.bookcafe.domain.command.member.Member; +import com.study.bookcafe.infrastructure.query.member.MemberEntity; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; diff --git a/src/main/java/com/study/bookcafe/interfaces/member/MembersReservationDetails.java b/src/main/java/com/study/bookcafe/interfaces/member/MembersReservationDetails.java index c6260b3..7999501 100644 --- a/src/main/java/com/study/bookcafe/interfaces/member/MembersReservationDetails.java +++ b/src/main/java/com/study/bookcafe/interfaces/member/MembersReservationDetails.java @@ -1,6 +1,6 @@ package com.study.bookcafe.interfaces.member; -import com.study.bookcafe.domain.book.Book; +import com.study.bookcafe.domain.command.book.Book; import lombok.Getter; import lombok.Setter; diff --git a/src/test/java/com/study/bookcafe/book/CanBorrowTest.java b/src/test/java/com/study/bookcafe/book/CanBorrowTest.java index 2d40972..a530f92 100644 --- a/src/test/java/com/study/bookcafe/book/CanBorrowTest.java +++ b/src/test/java/com/study/bookcafe/book/CanBorrowTest.java @@ -1,7 +1,7 @@ package com.study.bookcafe.book; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.book.Inventory; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.book.Inventory; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/study/bookcafe/book/MapperTest.java b/src/test/java/com/study/bookcafe/book/MapperTest.java index e1c5342..08de840 100644 --- a/src/test/java/com/study/bookcafe/book/MapperTest.java +++ b/src/test/java/com/study/bookcafe/book/MapperTest.java @@ -1,11 +1,11 @@ package com.study.bookcafe.book; import com.google.gson.Gson; +import com.study.bookcafe.infrastructure.query.book.BookEntity; import com.study.bookcafe.interfaces.common.JsonHelper; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.book.Inventory; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.book.Inventory; import com.study.bookcafe.interfaces.book.BookDto; -import com.study.bookcafe.infrastructure.book.BookEntity; import com.study.bookcafe.interfaces.book.BookMapper; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/study/bookcafe/borrow/MapperTest.java b/src/test/java/com/study/bookcafe/borrow/MapperTest.java index 723e1d8..cb761af 100644 --- a/src/test/java/com/study/bookcafe/borrow/MapperTest.java +++ b/src/test/java/com/study/bookcafe/borrow/MapperTest.java @@ -1,19 +1,19 @@ package com.study.bookcafe.borrow; import com.google.gson.Gson; +import com.study.bookcafe.infrastructure.query.book.BookEntity; +import com.study.bookcafe.infrastructure.query.borrow.BorrowEntity; +import com.study.bookcafe.infrastructure.query.member.MemberEntity; import com.study.bookcafe.interfaces.common.JsonHelper; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.borrow.Borrow; -import com.study.bookcafe.domain.member.Level; -import com.study.bookcafe.domain.member.Member; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.borrow.Borrow; +import com.study.bookcafe.domain.command.member.Level; +import com.study.bookcafe.domain.command.member.Member; import com.study.bookcafe.interfaces.book.BookDto; import com.study.bookcafe.interfaces.borrow.BorrowDto; import com.study.bookcafe.interfaces.member.MemberDto; -import com.study.bookcafe.infrastructure.book.BookEntity; -import com.study.bookcafe.infrastructure.borrow.BorrowEntity; -import com.study.bookcafe.infrastructure.member.MemberEntity; import com.study.bookcafe.interfaces.borrow.BorrowMapper; -import com.study.bookcafe.domain.borrow.Period; +import com.study.bookcafe.domain.command.borrow.Period; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; diff --git a/src/test/java/com/study/bookcafe/borrow/PeriodTest.java b/src/test/java/com/study/bookcafe/borrow/PeriodTest.java index 4a44bd7..452c366 100644 --- a/src/test/java/com/study/bookcafe/borrow/PeriodTest.java +++ b/src/test/java/com/study/bookcafe/borrow/PeriodTest.java @@ -1,6 +1,6 @@ package com.study.bookcafe.borrow; -import com.study.bookcafe.domain.borrow.Period; +import com.study.bookcafe.domain.command.borrow.Period; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/study/bookcafe/member/BorrowTest.java b/src/test/java/com/study/bookcafe/member/BorrowTest.java index 2277f01..1433554 100644 --- a/src/test/java/com/study/bookcafe/member/BorrowTest.java +++ b/src/test/java/com/study/bookcafe/member/BorrowTest.java @@ -1,10 +1,11 @@ package com.study.bookcafe.member; import com.google.gson.Gson; -import com.study.bookcafe.application.member.MemberService; -import com.study.bookcafe.domain.borrow.BorrowDetails; +import com.study.bookcafe.application.command.member.MemberService; +import com.study.bookcafe.application.query.member.MemberQueryService; +import com.study.bookcafe.domain.query.borrow.BorrowDetails; import com.study.bookcafe.interfaces.common.JsonHelper; -import com.study.bookcafe.domain.borrow.Borrow; +import com.study.bookcafe.domain.command.borrow.Borrow; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -19,6 +20,8 @@ public class BorrowTest { @Autowired private MemberService memberService; + @Autowired + private MemberQueryService memberQueryService; private final Gson gson = JsonHelper.getGson(); @@ -26,13 +29,12 @@ public class BorrowTest { @DisplayName("회원이 도서를 대출한다.") public void testBorrowBook() { - List borrows1 = memberService.borrowBook(1, List.of(1L)); - List borrows2 = memberService.borrowBook(3, List.of(2L)); + long memberId = 1; + memberService.borrowBook(memberId, List.of(1L)); - System.out.println(gson.toJson(borrows1)); + List borrows = memberQueryService.findBorrows(memberId); - borrows1.forEach(borrow -> assertThat(Borrow.successBorrow(borrow)).isEqualTo(true)); - borrows2.forEach(borrow -> assertThat(Borrow.successBorrow(borrow)).isEqualTo(true)); + borrows.forEach(borrow -> assertThat(borrow.getMember().getId()).isEqualTo(memberId)); } @@ -42,7 +44,7 @@ public void testFindBorrows() { long memberId = 1L; - List borrows = memberService.findBorrows(memberId); + List borrows = memberQueryService.findBorrows(memberId); assertThat(borrows.size()).isEqualTo(2); } diff --git a/src/test/java/com/study/bookcafe/member/CanBorrowTest.java b/src/test/java/com/study/bookcafe/member/CanBorrowTest.java index e7ed1c7..f813f8a 100644 --- a/src/test/java/com/study/bookcafe/member/CanBorrowTest.java +++ b/src/test/java/com/study/bookcafe/member/CanBorrowTest.java @@ -1,7 +1,7 @@ package com.study.bookcafe.member; -import com.study.bookcafe.domain.member.Level; -import com.study.bookcafe.domain.member.Member; +import com.study.bookcafe.domain.command.member.Level; +import com.study.bookcafe.domain.command.member.Member; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/study/bookcafe/member/MapperTest.java b/src/test/java/com/study/bookcafe/member/MapperTest.java index 1e9c4a5..a30bae3 100644 --- a/src/test/java/com/study/bookcafe/member/MapperTest.java +++ b/src/test/java/com/study/bookcafe/member/MapperTest.java @@ -1,11 +1,11 @@ package com.study.bookcafe.member; import com.google.gson.Gson; +import com.study.bookcafe.infrastructure.query.member.MemberEntity; import com.study.bookcafe.interfaces.common.JsonHelper; -import com.study.bookcafe.domain.member.Level; -import com.study.bookcafe.domain.member.Member; +import com.study.bookcafe.domain.command.member.Level; +import com.study.bookcafe.domain.command.member.Member; import com.study.bookcafe.interfaces.member.MemberDto; -import com.study.bookcafe.infrastructure.member.MemberEntity; import com.study.bookcafe.interfaces.member.MemberMapper; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/study/bookcafe/member/ReserveTest.java b/src/test/java/com/study/bookcafe/member/ReserveTest.java index 5ae88c5..65f7bd4 100644 --- a/src/test/java/com/study/bookcafe/member/ReserveTest.java +++ b/src/test/java/com/study/bookcafe/member/ReserveTest.java @@ -1,10 +1,10 @@ package com.study.bookcafe.member; -import com.study.bookcafe.domain.book.Book; -import com.study.bookcafe.domain.book.Inventory; -import com.study.bookcafe.domain.borrow.Reservation; -import com.study.bookcafe.domain.member.Level; -import com.study.bookcafe.domain.member.Member; +import com.study.bookcafe.domain.command.book.Book; +import com.study.bookcafe.domain.command.book.Inventory; +import com.study.bookcafe.domain.command.borrow.Reservation; +import com.study.bookcafe.domain.command.member.Level; +import com.study.bookcafe.domain.command.member.Member; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.sql.Date;