Skip to content

Commit

Permalink
Merge pull request #12 from f-lab-edu/feature/1
Browse files Browse the repository at this point in the history
회원의 대출 목록 조회 추가
  • Loading branch information
shine-17 authored Jan 7, 2025
2 parents ba06585 + f86ab66 commit 997205a
Show file tree
Hide file tree
Showing 61 changed files with 628 additions and 272 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<Book> findByIds(Collection<Long> bookIds);

}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Borrow> borrows);

// 도서 예약 저장
void save(Reservation reservation);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.study.bookcafe.application.borrow;
package com.study.bookcafe.application.command.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.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;
import java.util.List;

@Service
public class BorrowServiceImpl implements BorrowService {
Expand All @@ -19,12 +17,12 @@ public BorrowServiceImpl(BorrowRepository borrowRepository) {
/**
* 새로운 대출을 저장한다.
*
* @param borrow 대출 정보
* @param borrow 대출 정보
* @return 생성한 대출 정보
*/
@Override
public Borrow save(Borrow borrow) {
return borrowRepository.save(borrow);
public void save(Borrow borrow) {
borrowRepository.save(borrow);
}

/**
Expand All @@ -34,8 +32,8 @@ public Borrow save(Borrow borrow) {
* @return 생성한 대출 정보 목록
*/
@Override
public List<Borrow> save(Collection<Borrow> borrows) {
return borrowRepository.save(borrows);
public void save(Collection<Borrow> borrows) {
borrowRepository.save(borrows);
}

/**
Expand All @@ -45,8 +43,8 @@ public List<Borrow> save(Collection<Borrow> borrows) {
* @return 생성한 예약 정보
*/
@Override
public Reservation save(Reservation reservation) {
return borrowRepository.save(reservation);
public void save(Reservation reservation) {
borrowRepository.save(reservation);
}

}
Original file line number Diff line number Diff line change
@@ -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<Long> bookIds);

// 도서 예약
void reserveBook(long memberId, long bookId);
}
Original file line number Diff line number Diff line change
@@ -1,14 +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.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;
Expand Down Expand Up @@ -43,27 +44,25 @@ public Member findById(long memberId) {
*
* @param memberId 회원 ID
* @param bookIds 도서 ID 목록
* @return 대출
*/
@Override
public List<Borrow> borrowBook(long memberId, Collection<Long> bookIds) {
public void borrowBook(long memberId, Collection<Long> bookIds) {
Member member = findById(memberId);
List<Book> books = bookService.findByIds(bookIds);
List<Borrow> borrows = member.borrowBook(books);

if (borrows.isEmpty()) return borrows;
if (borrows.isEmpty()) return;

return borrowService.save(borrows);
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);

Expand All @@ -79,8 +78,6 @@ public Reservation reserveBook(long memberId, long bookId) {

Reservation reservation = member.reserveBook(book);

return borrowService.save(reservation);
borrowService.save(reservation);
}


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<BookView> findByIds(Collection<Long> bookIds);
}
Original file line number Diff line number Diff line change
@@ -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<BookView> findByIds(Collection<Long> bookIds) {
return bookQueryRepository.findByIds(bookIds);
}
}
Original file line number Diff line number Diff line change
@@ -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<BorrowDetails> findBorrows(long memberId);

}
Original file line number Diff line number Diff line change
@@ -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<BorrowDetails> findBorrows(long memberId) {
return borrowQueryRepository.findByMemberId(memberId);
}

}
Original file line number Diff line number Diff line change
@@ -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<BorrowDetails> findBorrows(long memberId);
}
Original file line number Diff line number Diff line change
@@ -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<BorrowDetails> findBorrows(long memberId) {
return borrowService.findBorrows(memberId);
}
}
Loading

0 comments on commit 997205a

Please sign in to comment.