[BMOL-30] 책 삭제 기능 - DELETE v1/library/mylist/:bookId 구현#24
Open
Dawon00 wants to merge 5 commits intoBookmark-Oneday:mainfrom
Open
[BMOL-30] 책 삭제 기능 - DELETE v1/library/mylist/:bookId 구현#24Dawon00 wants to merge 5 commits intoBookmark-Oneday:mainfrom
Dawon00 wants to merge 5 commits intoBookmark-Oneday:mainfrom
Conversation
pokers
reviewed
May 30, 2023
Comment on lines
+66
to
+76
| async deleteBook(book) { | ||
| const { user_id, book_id, meta } = book; | ||
| const query = pgClient("tbl_mybook") | ||
| .where({ | ||
| user_id: user_id, | ||
| id: book_id, | ||
| }) | ||
| .del(); | ||
|
|
||
| return await query; | ||
| } |
Collaborator
There was a problem hiding this comment.
delete의 경우 진짜 row를 삭제하는 경우는 거의 없습니다. (삭제한 내역도 결국 데이터이고, history기록이 되어야하니까요)
이경우 deleted_at의 시간을 업데이트 해주면 되고, get 할때 query에서 deleted_at이 null인 row는 제외 하도록 query하면 됩니다.
Collaborator
There was a problem hiding this comment.
저도 처음엔 delete에서 row를 삭제했는데 deleted_at에 업데이트 하는 방향으로 수정했어요 ~
Comment on lines
+20
to
+35
| async getBookByUserId(userId) { | ||
| return await pgClient("tbl_mybook") | ||
| .where({ | ||
| user_id: userId, | ||
| }) | ||
| .select(); | ||
| } | ||
|
|
||
| async getBookByBookId(bookId) { | ||
| return await pgClient("tbl_mybook") | ||
| .where({ | ||
| id: bookId, | ||
| }) | ||
| .select(); | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
굳이 두번으로 나눠서 할 필요없이 where절에 둘다 넣어서 한번의 query로 찾으면 될것 같네요..
pokers
reviewed
Jun 4, 2023
Comment on lines
+86
to
+91
| const result = await bookShelfService.deleteBook(bookData); | ||
| if (result === 1) { | ||
| ctx.body = "SUCCESS"; | ||
| } else { | ||
| ctx.body = "FAIL"; | ||
| } |
Collaborator
There was a problem hiding this comment.
1 이라는 것은 실패인지 성공인지 직관적으로 알수 없는거라서요렇게 하는 것 보다는 bookShelfService.deleteBook(bookData) 이 method가 성공 했을때는 true 실패시 false를 리턴하도록하고 bool을 비교 하는것이 좋아요.
| deleted_at: currentTimestamp, | ||
| }); | ||
|
|
||
| return await query; |
Collaborator
There was a problem hiding this comment.
위에서 언급한 것처럼 이 쿼리의 결과 값이 1이상인 경우에 성공이라면
const result = await query
return (result > 0)
요렇게 성공/실패에 대한 bool을 리턴하는것이 좋습니다
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Jira : https://bookmarkoneliner.atlassian.net/browse/BMOL-30?atlOrigin=eyJpIjoiNDFhODc2ZjhiMzlmNGFiY2IxYzE2NDY1YzUxMWQzYzUiLCJwIjoiaiJ9
postman : https://documenter.getpostman.com/view/25839648/2s93XsZmxm