-
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
29254f2
a9a5523
77a6cb6
c0a5617
1ba9722
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,22 +14,17 @@ class BookShelfRepository { | |
| user_id: userId, | ||
| isbn: isbn, | ||
| }) | ||
| .whereNull("deleted_at") | ||
| .select(); | ||
| } | ||
|
|
||
| async getBookByUserId(userId) { | ||
| async getBookByUserIdAndBookId(userId, bookId) { | ||
| return await pgClient("tbl_mybook") | ||
| .where({ | ||
| user_id: userId, | ||
| }) | ||
| .select(); | ||
| } | ||
|
|
||
| async getBookByBookId(bookId) { | ||
| return await pgClient("tbl_mybook") | ||
| .where({ | ||
| id: bookId, | ||
| }) | ||
| .whereNull("deleted_at") | ||
| .select(); | ||
| } | ||
|
|
||
|
|
@@ -65,12 +60,16 @@ class BookShelfRepository { | |
|
|
||
| async deleteBook(book) { | ||
| const { user_id, book_id, meta } = book; | ||
| const currentTimestamp = new Date().toISOString(); | ||
|
|
||
| const query = pgClient("tbl_mybook") | ||
| .where({ | ||
| user_id: user_id, | ||
| id: book_id, | ||
| }) | ||
| .del(); | ||
| .update({ | ||
| deleted_at: currentTimestamp, | ||
| }); | ||
|
|
||
| return await query; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위에서 언급한 것처럼 이 쿼리의 결과 값이 1이상인 경우에 성공이라면 요렇게 성공/실패에 대한 bool을 리턴하는것이 좋습니다 |
||
| } | ||
|
Comment on lines
+66
to
+75
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete의 경우 진짜 row를 삭제하는 경우는 거의 없습니다. (삭제한 내역도 결국 데이터이고, history기록이 되어야하니까요)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 처음엔 delete에서 row를 삭제했는데 deleted_at에 업데이트 하는 방향으로 수정했어요 ~ |
||
|
|
||
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을 비교 하는것이 좋아요.