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

리액션 카운트로 업데이트 #47

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/controller/meme.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,14 @@ const searchMemeListByKeyword = async (req: CustomRequest, res: Response, next:
const createMemeReaction = async (req: CustomRequest, res: Response, next: NextFunction) => {
const user = req.requestedUser;
const meme = req.requestedMeme;
const { count = 1 } = req.body;

try {
const result: boolean = await MemeService.createMemeInteraction(
user,
meme,
InteractionType.REACTION,
count,
);
return res.json(createSuccessResponse(HttpCode.CREATED, 'Create Meme Reaction', result));
} catch (err) {
Expand Down
10 changes: 10 additions & 0 deletions src/routes/meme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,16 @@ router.post('/:memeId/watch/:type', getRequestedUserInfo, getRequestedMemeInfo,
* type: string
* required: true
* description: 리액션할 밈 id
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* count:
* type: number
* example: 1
* responses:
* 201:
* description: Created Meme Reaction
Expand Down
3 changes: 2 additions & 1 deletion src/service/meme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ async function createMemeInteraction(
user: IUserDocument,
meme: IMemeDocument,
interactionType: InteractionType,
count: number = 1,
): Promise<boolean> {
try {
// 'save' interaction은 isDeleted 조건 검색 필요없음
Expand All @@ -265,7 +266,7 @@ async function createMemeInteraction(
);

// interactionType에 따른 동작 처리 (MemeInteracionService에서 진행)
await MemeInteractionService.updateMemeInteraction(user, meme, interactionType);
await MemeInteractionService.updateMemeInteraction(user, meme, interactionType, count);
}
return true;
} catch (err) {
Expand Down
3 changes: 2 additions & 1 deletion src/service/memeInteraction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async function updateMemeInteraction(
user: IUserDocument,
meme: IMemeDocument,
interactionType: InteractionType,
count: number = 1,
): Promise<void> {
switch (interactionType) {
// 'save' isDeleted false로 변경
Expand All @@ -159,7 +160,7 @@ async function updateMemeInteraction(
case InteractionType.REACTION:
await MemeModel.findOneAndUpdate(
{ _id: meme._id, isDeleted: false },
{ $inc: { reaction: 1 } },
{ $inc: { reaction: count } },
{
projection: { _id: 0, createdAt: 0, updatedAt: 0 },
returnDocument: 'after',
Expand Down