Skip to content
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

✨ 좋아요 및 좋아요 취소 API #42

Merged
merged 22 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/mocks/consts/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const errorMessage = Object.freeze({
'0000': 'Unknown error',
Legitgoons marked this conversation as resolved.
Show resolved Hide resolved
'4003': 'Malformed request body',
'4040': 'Requested resource not found',
'4220': 'Unprocessable Content',
Expand Down
26 changes: 16 additions & 10 deletions src/app/mocks/handler/like.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ export const likeHandlers = [
return createHttpErrorResponse('4040');
}

if (!likeInfo.isLiked) {
likeInfo.isLiked = true;
likeInfo.totalCount += 1;
feeds[formattedFeedId].isLiked = true;
feeds[formattedFeedId].likeCount += 1;
// 이미 좋아요 누른 경우
if (likeInfo.isLiked) {
return createHttpErrorResponse('0000');
}

likeInfo.isLiked = true;
likeInfo.totalCount += 1;
feeds[formattedFeedId].isLiked = true;
feeds[formattedFeedId].likeCount += 1;

return createHttpSuccessResponse({ isLiked: true });
}),

Expand All @@ -66,13 +69,16 @@ export const likeHandlers = [
return createHttpErrorResponse('4040');
}

if (likeInfo.isLiked) {
likeInfo.isLiked = false;
likeInfo.totalCount -= 1;
feeds[formattedFeedId].isLiked = false;
feeds[formattedFeedId].likeCount -= 1;
// 이미 좋아요 취소를 누른 경우
if (!likeInfo.isLiked) {
return createHttpErrorResponse('0000');
}

likeInfo.isLiked = false;
likeInfo.totalCount -= 1;
feeds[formattedFeedId].isLiked = false;
feeds[formattedFeedId].likeCount -= 1;

return createHttpSuccessResponse({ isLiked: false });
}),
];