forked from pokers/backend_template
-
Notifications
You must be signed in to change notification settings - Fork 2
[BMOL-30] 책 삭제 기능 - DELETE v1/library/mylist/:bookId 구현 #24
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
Open
Dawon00
wants to merge
5
commits into
Bookmark-Oneday:main
Choose a base branch
from
Dawon00:Dawon00
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29254f2
feat: 책 삭제 api
Dawon00 a9a5523
[BMOL-30] 책 삭제 기능 - DELETE v1/library/mylist/:bookId 구현
Dawon00 77a6cb6
Merge branch 'Dawon00' of https://github.com/Dawon00/bookmark-backend…
Dawon00 c0a5617
[BMOL-30] user_id, bookId 존재하지 않는 경우 에러 메세지
Dawon00 1ba9722
[BMOL-30] getBookByUserIDAndBookId 함수 생성, 책 delete 방식 수정
Dawon00 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,137 +1,155 @@ | ||
| const { BookHistoryRepository } = require('./repositories/bookHistoryRepository') | ||
| const { AccountRepository } = require('./repositories/accountRepository') | ||
| const { BookTimerDecorator } = require('./bookTimerDecorator') | ||
|
|
||
| const { MyBookNotFound, InternalServerError, BookHistoryNotFound } = require('../services/errorService') | ||
| const { | ||
| BookHistoryRepository, | ||
| } = require("./repositories/bookHistoryRepository"); | ||
| const { AccountRepository } = require("./repositories/accountRepository"); | ||
| const { BookTimerDecorator } = require("./bookTimerDecorator"); | ||
|
|
||
| const { | ||
| MyBookNotFound, | ||
| InternalServerError, | ||
| BookHistoryNotFound, | ||
| } = require("../services/errorService"); | ||
|
|
||
| class BookTimerDao { | ||
| constructor(){ | ||
| this._daoName = 'BookTimerDao' | ||
| constructor() { | ||
| this._daoName = "BookTimerDao"; | ||
| this._repo = { | ||
| bookHistory: new BookHistoryRepository(), | ||
| account: new AccountRepository(), | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| get daoName(){ | ||
| return this._daoName | ||
| get daoName() { | ||
| return this._daoName; | ||
| } | ||
|
|
||
| async getBookTimerInfoByBookId(bookId){ | ||
| const bookTimerDecorator = new BookTimerDecorator() | ||
| async getBookTimerInfoByBookId(bookId) { | ||
| const bookTimerDecorator = new BookTimerDecorator(); | ||
|
|
||
| const [accountInfo, bookHistoryInfo] = await Promise.all([ | ||
| this._repo.account.getAccountByBookId(bookId), | ||
| this._repo.bookHistory.getBookHistoryListByBookId(bookId) | ||
| ]) | ||
| this._repo.bookHistory.getBookHistoryListByBookId(bookId), | ||
| ]); | ||
|
|
||
| // deleted book check | ||
| if (!accountInfo || !bookHistoryInfo){ | ||
| throw new MyBookNotFound(bookId) | ||
| if (!accountInfo || !bookHistoryInfo) { | ||
| throw new MyBookNotFound(bookId); | ||
| } | ||
|
|
||
| const bookTimerInfo = bookTimerDecorator.decorateBookTimer(bookId, {accountInfo, bookHistoryInfo}) | ||
| const bookTimerInfo = bookTimerDecorator.decorateBookTimer(bookId, { | ||
| accountInfo, | ||
| bookHistoryInfo, | ||
| }); | ||
|
|
||
| const result = { | ||
| data : bookTimerInfo | ||
| } | ||
| return result | ||
| data: bookTimerInfo, | ||
| }; | ||
| return result; | ||
| } | ||
|
|
||
| async postReadingTimeInfo(bookId, reading_time){ | ||
| const accountRepo = new AccountRepository() | ||
| const bookHistoryRepo = new BookHistoryRepository() | ||
| async postReadingTimeInfo(bookId, reading_time) { | ||
| const accountRepo = new AccountRepository(); | ||
| const bookHistoryRepo = new BookHistoryRepository(); | ||
|
|
||
| const accountInfo = await accountRepo.getAccountByBookId(bookId) | ||
| const accountInfo = await accountRepo.getAccountByBookId(bookId); | ||
| // deleted book check | ||
| if (!accountInfo){ | ||
| throw new MyBookNotFound(bookId) | ||
| if (!accountInfo) { | ||
| throw new MyBookNotFound(bookId); | ||
| } | ||
|
|
||
| const postResult = await bookHistoryRepo.insertReadingTimeByBookId(accountInfo.user_id, bookId, reading_time) | ||
| const postResult = await bookHistoryRepo.insertReadingTimeByBookId( | ||
| accountInfo.user_id, | ||
| bookId, | ||
| reading_time | ||
| ); | ||
|
|
||
| // postResult check | ||
| if (!postResult || !postResult.length < 0){ | ||
| throw new InternalServerError() | ||
| if (!postResult || !postResult.length < 0) { | ||
| throw new InternalServerError(); | ||
| } | ||
|
|
||
| const addedBookHistoryResult = await bookHistoryRepo.getBookHistoryByBookHistoryId(postResult[0].id) | ||
| const addedBookHistoryResult = | ||
| await bookHistoryRepo.getBookHistoryByBookHistoryId( | ||
| postResult[0].id | ||
| ); | ||
|
|
||
| // if id of added book history is not in table, throw error | ||
| if (!addedBookHistoryResult){ | ||
| throw new InternalServerError() | ||
| if (!addedBookHistoryResult) { | ||
| throw new InternalServerError(); | ||
| } | ||
|
|
||
| const result = { | ||
| data : addedBookHistoryResult | ||
| } | ||
| return result | ||
| data: addedBookHistoryResult, | ||
| }; | ||
| return result; | ||
| } | ||
|
|
||
| async deleteReadingTimeByHistoryId(bookId, bookHistoryId) { | ||
| const accountRepo = new AccountRepository(); | ||
| const bookHistoryRepo = new BookHistoryRepository(); | ||
|
|
||
| async deleteReadingTimeByHistoryId(bookId, bookHistoryId){ | ||
| const accountRepo = new AccountRepository() | ||
| const bookHistoryRepo = new BookHistoryRepository() | ||
| const accountInfo = await accountRepo.getAccountByBookId(bookId); | ||
| const bookHistoryInfo = | ||
| await bookHistoryRepo.getBookHistoryByBookHistoryId(bookHistoryId); | ||
|
|
||
| const accountInfo = await accountRepo.getAccountByBookId(bookId) | ||
| const bookHistoryInfo = await bookHistoryRepo.getBookHistoryByBookHistoryId(bookHistoryId) | ||
|
|
||
| // deleted book check | ||
| if (!accountInfo){ | ||
| throw new MyBookNotFound(bookId) | ||
| if (!accountInfo) { | ||
| throw new MyBookNotFound(bookId); | ||
| } | ||
|
|
||
| // deleted book history check | ||
| if (!bookHistoryInfo){ | ||
| throw new BookHistoryNotFound(bookId) | ||
| if (!bookHistoryInfo) { | ||
| throw new BookHistoryNotFound(bookId); | ||
| } | ||
|
|
||
| const deleteResults = await bookHistoryRepo.removeReadingTimeByBookHistoryId(bookHistoryId) | ||
| const deleteResults = | ||
| await bookHistoryRepo.removeReadingTimeByBookHistoryId( | ||
| bookHistoryId | ||
| ); | ||
|
|
||
| const removedBookHistoryResult = | ||
| await bookHistoryRepo.getBookHistoryByBookHistoryId(bookHistoryId); | ||
|
|
||
| const removedBookHistoryResult = | ||
| await bookHistoryRepo.getBookHistoryByBookHistoryId(bookHistoryId) | ||
|
|
||
| // if id of added book history is in table, throw error | ||
| if (removedBookHistoryResult){ | ||
| throw new InternalServerError() | ||
| if (removedBookHistoryResult) { | ||
| throw new InternalServerError(); | ||
| } | ||
|
|
||
| const result = { | ||
| data : deleteResults | ||
| } | ||
| return result | ||
| data: deleteResults, | ||
| }; | ||
| return result; | ||
| } | ||
|
|
||
| async deleteReadingTimeByBookId(bookId){ | ||
| const accountRepo = new AccountRepository() | ||
| const bookHistoryRepo = new BookHistoryRepository() | ||
| async deleteReadingTimeByBookId(bookId) { | ||
| const accountRepo = new AccountRepository(); | ||
| const bookHistoryRepo = new BookHistoryRepository(); | ||
|
|
||
| const accountInfo = await accountRepo.getAccountByBookId(bookId); | ||
|
|
||
| const accountInfo = await accountRepo.getAccountByBookId(bookId) | ||
|
|
||
| // deleted book check | ||
| if (!accountInfo){ | ||
| throw new MyBookNotFound(bookId) | ||
| if (!accountInfo) { | ||
| throw new MyBookNotFound(bookId); | ||
| } | ||
|
|
||
| const deleteResults = await bookHistoryRepo.removeReadingTimeByBookId(bookId) | ||
|
|
||
| const deleteResults = await bookHistoryRepo.removeReadingTimeByBookId( | ||
| bookId | ||
| ); | ||
|
|
||
| //id check | ||
| const removedBookResult = | ||
| await bookHistoryRepo.getBookHistoryListByBookId(bookId) | ||
| const removedBookResult = | ||
| await bookHistoryRepo.getBookHistoryListByBookId(bookId); | ||
|
|
||
|
|
||
| // if id of added book history is in table, throw error | ||
| if(removedBookResult && removedBookResult.length > 0) | ||
| throw new InternalServerError() | ||
| if (removedBookResult && removedBookResult.length > 0) { | ||
| throw new InternalServerError(); | ||
| } | ||
|
|
||
|
|
||
| const result = { | ||
| data : deleteResults | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| data: deleteResults, | ||
| }; | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| module.exports = { BookTimerDao } | ||
| module.exports = { BookTimerDao }; |
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.
1 이라는 것은 실패인지 성공인지 직관적으로 알수 없는거라서요렇게 하는 것 보다는 bookShelfService.deleteBook(bookData) 이 method가 성공 했을때는 true 실패시 false를 리턴하도록하고 bool을 비교 하는것이 좋아요.