-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 책 저장 상태 변경 api 개발 #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
3a9909d
[feat] 구현 ing... (#42)
hd0rable 0f4f7d0
[feat] 구현 ing... (#42)
hd0rable 3fbf5cc
Merge branch 'feat/#34-get-book-detail-search' into feat/#42-post-boo…
hd0rable 093a5a4
[feat] 구현 ing... (#42)
hd0rable 5620cf4
[feat] BookCommandController (#42)
hd0rable 4a70c29
[feat] BookCommandPersistenceAdapter.save (#42)
hd0rable 2bfc13e
[feat] BookCommandPort.save (#42)
hd0rable 2bea46a
[test] BookIsSavedControllerTest 테스트 코드 작성 (#42)
hd0rable 92c2221
[refactor] import 문 정리 (#42)
hd0rable f728ddf
[feat] BookSavedService.isSavedBook (#42)
hd0rable 025f237
[feat] BookSavedUseCase.isSavedBook (#42)
hd0rable e968630
[feat] 관련 예외코드 추가 (#42)
hd0rable d6328f0
[feat] NaverDetailBookParseResult.toBook (#42)
hd0rable f4c1cdf
[feat] PostBookIsSavedRequest (#42)
hd0rable 6fa794c
[feat] SavedBookJpaRepository.deleteByUserJpaEntity_UserIdAndBookJpaE…
hd0rable 3eec684
[feat] SavedCommandPersistenceAdapter.saveBook (#42)
hd0rable 1c4700a
[refactor] 공백 삭제 (#42)
hd0rable c05164d
Merge branch 'feat/#34-get-book-search-recent-search-add' into feat/#…
hd0rable cf6f8f9
[refactor] 사용하지 않는 에러코드 삭제 (#42)
hd0rable fd54f63
[refactor] 서비스 로직 리팩토링 (#42)
hd0rable a21c997
[refactor] 에러코드 수정 (#42)
hd0rable ed27d96
Merge branch 'feat/#34-get-book-search-recent-search-add' into feat/#…
hd0rable 7a948cf
Merge remote-tracking branch 'origin/feat/#34-get-book-search-recent-…
hd0rable db219ef
Merge remote-tracking branch 'origin/develop' into feat/#42-post-book…
hd0rable fa12f00
Merge remote-tracking branch 'origin/develop' into feat/#42-post-book…
hd0rable 17a1632
[refactor] user 예외처리 어댑터에서만 하도록 수정 (#42)
hd0rable d432e4f
[refactor] user 예외처리 어댑터에서만 하도록 수정 (#42)
hd0rable 0db8690
[refactor] book 도메인 equals,hashcode 오버라이드 정적 팩토리 메서드 생성 (#42)
hd0rable 9ff6087
[refactor] 컨트롤러 에서 저장/삭제 여부 반환 (#42)
hd0rable c13fba3
[refactor] 로직변경에따른 테스트코드 수정 (#42)
hd0rable af0f115
[refactor] 메서드명 변경 (#42)
hd0rable 38d5193
[refactor] 관련 에러코드 추가 (#42)
hd0rable e211eba
[refactor] dto에서 book 변환 책임 분리 (#42)
hd0rable 1faa918
[refactor] 서비스에서 비지니스 예외처리하도록, 도메인에서 도메인 생성 검증하도록 리펙토링 (#42)
hd0rable 36a70b6
[test] 테스트 코드 수정 (#42)
hd0rable 77616e2
[test] 테스트 코드 수정 (#42)
hd0rable 725f85c
[test] 어댑터 메서드 수정 (#42)
hd0rable 0c90611
[test] 어댑터 메서드 수정 (#42)
hd0rable 6610801
[refactor] 서비스 로직 수정 (#42)
hd0rable bd5deef
[refactor] 서비스 로직 수정 (#42)
hd0rable c5b77c0
[refactor] 에러코드 추가 (#42)
hd0rable b8cb01b
[refactor] ci 레디스 탬플릿 수정 (#42)
hd0rable 65a8653
[refactor] ci 레디스 탬플릿 수정 (#42)
hd0rable fda8fa5
[refactor] ci 레디스 탬플릿 수정 (#42)
hd0rable d220ba2
[refactor] ci 레디스 탬플릿 수정 (#42)
hd0rable 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 hidden or 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
21 changes: 20 additions & 1 deletion
21
src/main/java/konkuk/thip/book/adapter/in/web/BookCommandController.java
This file contains hidden or 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,10 +1,29 @@ | ||
| package konkuk.thip.book.adapter.in.web; | ||
|
|
||
| import jakarta.validation.constraints.Pattern; | ||
| import konkuk.thip.book.adapter.in.web.request.PostBookIsSavedRequest; | ||
| import konkuk.thip.book.adapter.in.web.response.PostBookIsSavedResponse; | ||
| import konkuk.thip.book.application.port.in.BookSavedUseCase; | ||
| import konkuk.thip.common.dto.BaseResponse; | ||
| import konkuk.thip.common.security.annotation.UserId; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @Validated | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class BookCommandController { | ||
|
|
||
| private final BookSavedUseCase bookSavedUseCase; | ||
|
|
||
| //책 저장 상태 변경 | ||
| @PostMapping("/books/{isbn}/saved") | ||
| public BaseResponse<PostBookIsSavedResponse> changeSavedBook(@PathVariable("isbn") | ||
| @Pattern(regexp = "\\d{13}") final String isbn, | ||
| @RequestBody final PostBookIsSavedRequest postBookIsSavedRequest, | ||
| @UserId final Long userId) { | ||
| return BaseResponse.ok(PostBookIsSavedResponse.of(bookSavedUseCase.changeSavedBook(isbn,postBookIsSavedRequest.type(),userId))); | ||
| } | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/konkuk/thip/book/adapter/in/web/request/PostBookIsSavedRequest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package konkuk.thip.book.adapter.in.web.request; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
|
|
||
| public record PostBookIsSavedRequest( | ||
| @NotNull(message = "type은 필수입니다.") | ||
| boolean type | ||
| ) { | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/konkuk/thip/book/adapter/in/web/response/PostBookIsSavedResponse.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package konkuk.thip.book.adapter.in.web.response; | ||
|
|
||
| import konkuk.thip.book.application.port.in.dto.BookDetailSearchResult; | ||
| import konkuk.thip.book.application.port.in.dto.BookIsSavedResult; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record PostBookIsSavedResponse( | ||
| String isbn, | ||
| boolean isSaved | ||
| ) { | ||
| public static PostBookIsSavedResponse of(BookIsSavedResult bookIsSavedResult) { | ||
| return new PostBookIsSavedResponse(bookIsSavedResult.isbn(),bookIsSavedResult.isSaved()); | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -12,5 +12,4 @@ public record NaverDetailBookParseResult( | |
| String isbn, | ||
| String description | ||
| ) { | ||
|
|
||
| } | ||
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
src/main/java/konkuk/thip/book/application/port/in/BookSavedUseCase.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package konkuk.thip.book.application.port.in; | ||
|
|
||
| import konkuk.thip.book.application.port.in.dto.BookIsSavedResult; | ||
|
|
||
| public interface BookSavedUseCase { | ||
| BookIsSavedResult changeSavedBook(String isbn, boolean isSave, Long userId); | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/konkuk/thip/book/application/port/in/dto/BookIsSavedResult.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package konkuk.thip.book.application.port.in.dto; | ||
|
|
||
|
|
||
| public record BookIsSavedResult( | ||
| String isbn, | ||
| boolean isSaved | ||
| ) | ||
| { | ||
| public static BookIsSavedResult of( String isbn,boolean isSaved) { | ||
| return new BookIsSavedResult(isbn, isSaved); | ||
| } | ||
| } |
This file contains hidden or 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
78 changes: 78 additions & 0 deletions
78
src/main/java/konkuk/thip/book/application/service/BookSavedService.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package konkuk.thip.book.application.service; | ||
|
|
||
| import jakarta.transaction.Transactional; | ||
| import konkuk.thip.book.adapter.out.api.dto.NaverDetailBookParseResult; | ||
| import konkuk.thip.book.application.port.in.BookSavedUseCase; | ||
| import konkuk.thip.book.application.port.in.dto.BookIsSavedResult; | ||
| import konkuk.thip.book.application.port.out.BookApiQueryPort; | ||
| import konkuk.thip.book.application.port.out.BookCommandPort; | ||
| import konkuk.thip.book.domain.Book; | ||
| import konkuk.thip.common.exception.BusinessException; | ||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
| import konkuk.thip.saved.application.port.out.SavedCommandPort; | ||
| import konkuk.thip.saved.application.port.out.SavedQueryPort; | ||
| import konkuk.thip.book.domain.SavedBooks; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.BOOK_NOT_SAVED_DB_CANNOT_DELETE; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class BookSavedService implements BookSavedUseCase { | ||
|
|
||
| private final BookApiQueryPort bookApiQueryPort; | ||
| private final BookCommandPort bookCommandPort; | ||
| private final SavedCommandPort savedCommandPort; | ||
| private final SavedQueryPort savedQueryPort; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public BookIsSavedResult changeSavedBook(String isbn, boolean isSave, Long userId) { | ||
|
|
||
| Book book; | ||
|
|
||
| try { | ||
| // Book 조회 시도 | ||
| book = bookCommandPort.findByIsbn(isbn); | ||
| } catch (EntityNotFoundException e) { | ||
| // 책이 DB에 없을 때 처리 | ||
|
|
||
| if (!isSave) { | ||
| // 삭제 요청인데 책이 없으면 저장하지 않은 책이므로 예외 처리 | ||
| throw new BusinessException(BOOK_NOT_SAVED_DB_CANNOT_DELETE); | ||
| } | ||
|
|
||
| // 저장 요청이면 네이버 API로 책 정보 조회 후 저장 | ||
| NaverDetailBookParseResult naverResult = bookApiQueryPort.findDetailBookByKeyword(isbn); | ||
| Book newBook = Book.withoutId( | ||
| naverResult.title(), | ||
| naverResult.isbn(), | ||
| naverResult.author(), | ||
| false, | ||
| naverResult.publisher(), | ||
| naverResult.imageUrl(), | ||
| null, | ||
| naverResult.description()); | ||
|
|
||
| Long newBookId = bookCommandPort.save(newBook); | ||
| book = newBook.withId(newBookId); | ||
| } | ||
|
|
||
| // 유저가 저장한 책 목록 조회 | ||
| SavedBooks savedBooks = savedQueryPort.findByUserId(userId); | ||
|
|
||
| if (isSave) { | ||
| // 저장 요청 시 이미 저장되어 있으면 예외 발생 | ||
| savedBooks.validateNotAlreadySaved(book); | ||
| savedCommandPort.saveBook(userId, book.getId()); | ||
| } else { | ||
| // 삭제 요청 시 저장되어 있지 않으면 예외 발생 | ||
| savedBooks.validateCanDelete(book); | ||
| savedCommandPort.deleteBook(userId, book.getId()); | ||
| } | ||
|
|
||
| return BookIsSavedResult.of(isbn, isSave); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package konkuk.thip.book.domain; | ||
|
|
||
| import konkuk.thip.common.exception.BusinessException; | ||
| import lombok.Getter; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.*; | ||
|
|
||
| @Getter | ||
| public class SavedBooks { | ||
| private final Set<Book> books; | ||
|
|
||
| public SavedBooks(List<Book> books) { | ||
| // Set으로 변환해서 중복 여부 검사 | ||
| Set<Book> bookSet = new HashSet<>(books); | ||
| if (bookSet.size() != books.size()) { | ||
| throw new BusinessException(DUPLICATED_BOOKS_IN_COLLECTION); | ||
| } | ||
| // 불변 Set으로 저장 (Collections.unmodifiableSet 사용) | ||
| this.books = Collections.unmodifiableSet(bookSet); | ||
| } | ||
|
|
||
| // 중복 저장 검증 | ||
| public void validateNotAlreadySaved(Book book) { | ||
| if (books.contains(book)) { | ||
| throw new BusinessException(BOOK_ALREADY_SAVED); | ||
| } | ||
| } | ||
|
|
||
| // 삭제 가능 여부 검증 | ||
| public void validateCanDelete(Book book) { | ||
| if (!books.contains(book)) { | ||
| throw new BusinessException(BOOK_NOT_SAVED_CANNOT_DELETE); | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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 hidden or 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.
p3 : response dto에 isbn 값을 포함시키신 이유가 뭔가요?
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.
저희 서비스로직에서 isbn값으로 책 상세조회를 하기때문에 책 저장 상태변경을할때 책에 대한 정보를 넘겨줘야하는 것으로 알고있습니다!