Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.somemore.domains.volunteerrecord.repository;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.somemore.domains.volunteerrecord.dto.response.VolunteerMonthlyRankingResponseDto;
import com.somemore.domains.volunteerrecord.dto.response.VolunteerRankingResponseDto;
import com.somemore.domains.volunteerrecord.dto.response.VolunteerTotalRankingResponseDto;
Expand Down Expand Up @@ -31,13 +34,29 @@ public void saveRanking(VolunteerRankingResponseDto rankings) {

@SuppressWarnings("unchecked")
public Optional<VolunteerRankingResponseDto> getRankings() {
ObjectMapper mapper = new ObjectMapper();

mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

List<VolunteerTotalRankingResponseDto> totalRanking =
(List<VolunteerTotalRankingResponseDto>) redisTemplate.opsForValue().get(TOTAL_RANKING_KEY);
(List<VolunteerTotalRankingResponseDto>) Optional.ofNullable(redisTemplate.opsForValue().get(TOTAL_RANKING_KEY))
.map(obj -> mapper.convertValue(obj,
mapper.getTypeFactory().constructCollectionType(List.class, VolunteerTotalRankingResponseDto.class)))
.orElse(null);

List<VolunteerMonthlyRankingResponseDto> monthlyRanking =
(List<VolunteerMonthlyRankingResponseDto>) redisTemplate.opsForValue().get(MONTHLY_RANKING_KEY);
(List<VolunteerMonthlyRankingResponseDto>) Optional.ofNullable(redisTemplate.opsForValue().get(MONTHLY_RANKING_KEY))
.map(obj -> mapper.convertValue(obj,
mapper.getTypeFactory().constructCollectionType(List.class, VolunteerMonthlyRankingResponseDto.class)))
.orElse(null);

List<VolunteerWeeklyRankingResponseDto> weeklyRanking =
(List<VolunteerWeeklyRankingResponseDto>) redisTemplate.opsForValue().get(WEEKLY_RANKING_KEY);
(List<VolunteerWeeklyRankingResponseDto>) Optional.ofNullable(redisTemplate.opsForValue().get(WEEKLY_RANKING_KEY))
.map(obj -> mapper.convertValue(obj,
mapper.getTypeFactory().constructCollectionType(List.class, VolunteerWeeklyRankingResponseDto.class)))
.orElse(null);

if (totalRanking == null || monthlyRanking == null || weeklyRanking == null) {
return Optional.empty();
Expand All @@ -49,4 +68,6 @@ public Optional<VolunteerRankingResponseDto> getRankings() {
weeklyRanking
));
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.somemore.global.redis.config;

import com.somemore.domains.volunteerrecord.dto.response.VolunteerRankingResponseDto;
import com.somemore.global.common.event.ServerEventType;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -51,6 +52,10 @@ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connec
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new CustomJacksonRedisSerializer<>(Object.class));


template.setValueSerializer(new CustomJacksonRedisSerializer<>(VolunteerRankingResponseDto.class));
template.setHashValueSerializer(new CustomJacksonRedisSerializer<>(VolunteerRankingResponseDto.class));

return template;
}

Expand Down
Loading