Skip to content

[BMOL-30] 책 삭제 기능 - DELETE v1/library/mylist/:bookId 구현#24

Open
Dawon00 wants to merge 5 commits intoBookmark-Oneday:mainfrom
Dawon00:Dawon00
Open

[BMOL-30] 책 삭제 기능 - DELETE v1/library/mylist/:bookId 구현#24
Dawon00 wants to merge 5 commits intoBookmark-Oneday:mainfrom
Dawon00:Dawon00

Conversation

@Dawon00
Copy link
Collaborator

@Dawon00 Dawon00 commented May 29, 2023

Jira : https://bookmarkoneliner.atlassian.net/browse/BMOL-30?atlOrigin=eyJpIjoiNDFhODc2ZjhiMzlmNGFiY2IxYzE2NDY1YzUxMWQzYzUiLCJwIjoiaiJ9

postman : https://documenter.getpostman.com/view/25839648/2s93XsZmxm

  • header의 user_id, path variables의 bookId 를 통해 책을 삭제하는 기능
  • 성공 시 업데이트한 row 의 갯수인 1과 status code 200 OK 반환

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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete의 경우 진짜 row를 삭제하는 경우는 거의 없습니다. (삭제한 내역도 결국 데이터이고, history기록이 되어야하니까요)
이경우 deleted_at의 시간을 업데이트 해주면 되고, get 할때 query에서 deleted_at이 null인 row는 제외 하도록 query하면 됩니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 처음엔 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();
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳이 두번으로 나눠서 할 필요없이 where절에 둘다 넣어서 한번의 query로 찾으면 될것 같네요..

Comment on lines +86 to +91
const result = await bookShelfService.deleteBook(bookData);
if (result === 1) {
ctx.body = "SUCCESS";
} else {
ctx.body = "FAIL";
}
Copy link
Collaborator

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을 비교 하는것이 좋아요.

deleted_at: currentTimestamp,
});

return await query;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에서 언급한 것처럼 이 쿼리의 결과 값이 1이상인 경우에 성공이라면

const result = await query
return (result > 0)

요렇게 성공/실패에 대한 bool을 리턴하는것이 좋습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants