Skip to content

Commit

Permalink
Merge pull request #40 from mash-up-kr/develop
Browse files Browse the repository at this point in the history
feat: add isReaction field
  • Loading branch information
seohyun0120 authored Aug 4, 2024
2 parents ecc4087 + f399c76 commit 7304d4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/service/meme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function getTodayMemeList(
{ isDeleted: 0 },
).lean();

const memeList = await getMemeListWithKeywordsAndisSaved(user, todayMemeList);
const memeList = await getMemeListWithKeywordsAndisSavedAndisReaction(user, todayMemeList);

const memeIds = todayMemeList.map((meme) => meme._id);
logger.info(
Expand Down Expand Up @@ -91,7 +91,7 @@ async function getAllMemeList(
.sort({ createdAt: -1 })
.lean();

const allMemeList = await getMemeListWithKeywordsAndisSaved(user, memeList);
const allMemeList = await getMemeListWithKeywordsAndisSavedAndisReaction(user, memeList);

logger.info(`Get all meme list - page(${page}), size(${size}), total(${totalMemes})`);

Expand All @@ -104,7 +104,7 @@ async function getAllMemeList(
}

// MemeList에서 keywords와 isSaved 정보를 확인하여 추가 반환
async function getMemeListWithKeywordsAndisSaved(
async function getMemeListWithKeywordsAndisSavedAndisReaction(
user: IUserDocument,
memeList: IMemeDocument[],
): Promise<IMemeGetResponse[]> {
Expand All @@ -118,10 +118,17 @@ async function getMemeListWithKeywordsAndisSaved(
InteractionType.SAVE,
true, // {isDeleted: false} 조건으로 save 상태인지 확인
);
const isReaction = await MemeInteractionService.getMemeInteractionInfo(
user,
meme,
InteractionType.REACTION,
true,
);
return {
..._.omit(meme, 'keywordIds'),
keywords,
isSaved: !_.isNil(isSaved),
isReaction: !_.isNil(isReaction),
} as IMemeGetResponse;
}),
);
Expand Down Expand Up @@ -203,7 +210,7 @@ async function searchMemeByKeyword(
.sort({ reaction: -1 })
.lean();

const memeList = await getMemeListWithKeywordsAndisSaved(user, searchedMemeList);
const memeList = await getMemeListWithKeywordsAndisSavedAndisReaction(user, searchedMemeList);

logger.info(
`Get all meme list with keyword(${keyword.name}) - page(${page}), size(${size}), total(${totalMemes})`,
Expand Down Expand Up @@ -309,7 +316,7 @@ export {
deleteMemeSave,
getTodayMemeList,
getAllMemeList,
getMemeListWithKeywordsAndisSaved,
getMemeListWithKeywordsAndisSavedAndisReaction,
deleteKeywordOfMeme,
getMemeWithKeywords,
searchMemeByKeyword,
Expand Down
10 changes: 8 additions & 2 deletions src/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ async function getLastSeenMemeList(user: IUserDocument): Promise<IMemeGetRespons
{ isDeleted: 0 },
).lean();

const getLastSeenMemeList = await MemeService.getMemeListWithKeywordsAndisSaved(user, memeList);
const getLastSeenMemeList = await MemeService.getMemeListWithKeywordsAndisSavedAndisReaction(
user,
memeList,
);
logger.info(
`Get lastSeenMemeList - deviceId(${user.deviceId}), memeList(${getLastSeenMemeList})`,
);
Expand Down Expand Up @@ -190,7 +193,10 @@ async function getSavedMemeList(
{ isDeleted: 0 },
).lean();

const savedMemeList = await MemeService.getMemeListWithKeywordsAndisSaved(user, memeList);
const savedMemeList = await MemeService.getMemeListWithKeywordsAndisSavedAndisReaction(
user,
memeList,
);
logger.info(`Get savedMemeList - deviceId(${user.deviceId}), memeList(${savedMemeList})`);

return {
Expand Down

0 comments on commit 7304d4d

Please sign in to comment.