Skip to content

Commit

Permalink
[#519] refactor: 인기 게시물 찜 여부 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-H0 committed Nov 25, 2024
1 parent 8c6e81c commit 80a3ce2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class PopularPostPreviewDto {
@Schema(description = "썸네일 이미지")
private ImageFileDto firstImage;

@Schema(description = "좋아요 여부")
private boolean isFavorite;

@Schema(description = "조회수")
private int viewCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.jeju.nanaland.domain.common.dto.PopularPostPreviewDto;
import com.jeju.nanaland.domain.common.repository.PostRepository;
import com.jeju.nanaland.domain.experience.repository.ExperienceRepository;
import com.jeju.nanaland.domain.favorite.service.MemberFavoriteService;
import com.jeju.nanaland.domain.festival.repository.FestivalRepository;
import com.jeju.nanaland.domain.market.repository.MarketRepository;
import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto;
import com.jeju.nanaland.domain.member.entity.Member;
import com.jeju.nanaland.domain.nature.repository.NatureRepository;
import com.jeju.nanaland.domain.restaurant.repository.RestaurantRepository;
import com.jeju.nanaland.global.util.RedisUtil;
Expand All @@ -35,6 +37,7 @@ public class PostViewCountService {
private final MarketRepository marketRepository;
private final NatureRepository natureRepository;
private final RestaurantRepository restaurantRepository;
private final MemberFavoriteService memberFavoriteService;
private final RedisUtil redisUtil;
private final ObjectMapper objectMapper;
// private final PostServiceImpl postService;
Expand Down Expand Up @@ -66,11 +69,19 @@ public List<PopularPostPreviewDto> getLastWeekPopularPosts(MemberInfoDto memberI
}
// redis에서 갖고온 후
List<String> serializedPosts = getJsonPopularPosts(memberInfoDto.getLanguage());
//직렬화
return deserializePostPreviewDtos(serializedPosts);

//역직렬화
List<PopularPostPreviewDto> popularPostPreviewDtos = deserializePostPreviewDtos(
serializedPosts);

// 좋아요 여부 추가
setPopularPostPreviewDtosFavoriteStatus(memberInfoDto, popularPostPreviewDtos);

return popularPostPreviewDtos;

}


// 지난 한국 인기 게시물 조회해서 id 추출 -> excludeIds
// excludeIds 제외한 카테고리 별 조회수 top 3(조회수 0이 아닌) 조회,
// 다 합친게 3개가 넘지 않으면 -> 부족한 수 만큼 카테고리 랜덤으로 추출, 추출한 카테고리에서 각 한개씩 게시물 선택
Expand Down Expand Up @@ -242,5 +253,21 @@ private List<PopularPostPreviewDto> modifyAddressTagToLongForm(
})
.collect(Collectors.toList());
}

// List<popularPostPreviewDto>에 찜 여부 추가
private void setPopularPostPreviewDtosFavoriteStatus(MemberInfoDto memberInfoDto,
List<PopularPostPreviewDto> popularPostPreviewDtos) {
Member member = memberInfoDto.getMember();

// 각 PopularPostPreviewDto의 favorite 상태를 설정
popularPostPreviewDtos.forEach(postDto -> {
boolean isFavorite = memberFavoriteService.isPostInFavorite(
member,
Category.valueOf(postDto.getCategory()),
postDto.getId()
);
postDto.setFavorite(isFavorite);
});
}
}

0 comments on commit 80a3ce2

Please sign in to comment.