diff --git a/smeem-application/src/main/java/com/smeem/application/domain/member/MemberService.java b/smeem-application/src/main/java/com/smeem/application/domain/member/MemberService.java index d108838e..47f25b1e 100644 --- a/smeem-application/src/main/java/com/smeem/application/domain/member/MemberService.java +++ b/smeem-application/src/main/java/com/smeem/application/domain/member/MemberService.java @@ -3,7 +3,6 @@ import com.smeem.application.domain.badge.Badge; import com.smeem.application.domain.trainingtime.DayType; import com.smeem.application.domain.trainingtime.TrainingTime; -import com.smeem.application.domain.visit.Visit; import com.smeem.application.port.input.MemberUseCase; import com.smeem.application.port.input.dto.request.member.UpdateMemberHasPushAlarmRequest; import com.smeem.application.port.input.dto.request.member.UpdateMemberRequest; @@ -13,6 +12,7 @@ import com.smeem.application.port.input.dto.response.member.UpdateMemberResponse; import com.smeem.application.port.input.dto.response.member.UsernameDuplicatedResponse; import com.smeem.application.port.input.dto.response.plan.RetrieveMemberPlanResponse; +import com.smeem.application.port.output.cache.CachePort; import com.smeem.application.port.output.persistence.*; import com.smeem.common.logger.HookLogger; import com.smeem.common.logger.LoggingMessage; @@ -21,6 +21,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; @Service @@ -31,10 +33,10 @@ public class MemberService implements MemberUseCase { private final TrainingTimePort trainingTimePort; private final BadgePort badgePort; private final DiaryPort diaryPort; - private final VisitPort visitPort; private final GoalPort goalPort; private final PlanPort planPort; private final HookLogger hookLogger; + private final CachePort cachePort; @Transactional public UpdateMemberResponse updateMember(long memberId, UpdateMemberRequest request) { @@ -90,11 +92,15 @@ public RetrievePerformanceResponse retrieveMemberPerformance(long memberId) { @Transactional public void visit(long memberId) { - val foundMember = memberPort.findById(memberId); - if (!visitPort.isExistByMemberAndToday(foundMember.getId())) { + Member foundMember = memberPort.findById(memberId); + String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); + String key = "visit:" + today; + + if (!cachePort.getBit(key, foundMember.getId())) { + System.out.println("test"); foundMember.visit(); memberPort.update(foundMember); - visitPort.visit(new Visit(foundMember.getId())); + cachePort.setBit(key, foundMember.getId(), true); } } diff --git a/smeem-application/src/main/java/com/smeem/application/port/output/cache/CachePort.java b/smeem-application/src/main/java/com/smeem/application/port/output/cache/CachePort.java new file mode 100644 index 00000000..f5d500e9 --- /dev/null +++ b/smeem-application/src/main/java/com/smeem/application/port/output/cache/CachePort.java @@ -0,0 +1,6 @@ +package com.smeem.application.port.output.cache; + +public interface CachePort { + void setBit(String key, long offset, boolean value); + boolean getBit(String key, long offset); +} diff --git a/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/CacheAdapter.java b/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/CacheAdapter.java new file mode 100644 index 00000000..0bc1b77f --- /dev/null +++ b/smeem-output-cache/redis/src/main/java/com/smeem/output/cache/redis/adapter/CacheAdapter.java @@ -0,0 +1,22 @@ +package com.smeem.output.cache.redis.adapter; + +import com.smeem.application.port.output.cache.CachePort; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.core.RedisTemplate; + +@Configuration +@RequiredArgsConstructor +public class CacheAdapter implements CachePort { + private final RedisTemplate redisTemplate; + + @Override + public void setBit(String key, long offset, boolean value) { + redisTemplate.opsForValue().setBit(key, offset, value); + } + + @Override + public boolean getBit(String key, long offset) { + return Boolean.TRUE.equals(redisTemplate.opsForValue().getBit(key, offset)); + } +} diff --git a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/MemberAdapter.java b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/MemberAdapter.java index b83b7bff..70a46b46 100644 --- a/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/MemberAdapter.java +++ b/smeem-output-persistence/postgresql/src/main/java/com/smeem/persistence/postgresql/adapter/MemberAdapter.java @@ -24,7 +24,6 @@ public class MemberAdapter implements MemberPort { private final DeletedDiaryRepository deletedDiaryRepository; private final DiaryRepository diaryRepository; private final TrainingTimeRepository trainingTimeRepository; - private final VisitRepository visitRepository; private final WithdrawRepository withdrawRepository; @Override @@ -55,7 +54,6 @@ public void deleteById(long id) { deletedDiaryRepository.deleteByMemberId(id); diaryRepository.deleteByMemberId(id); trainingTimeRepository.deleteByMemberId(id); - visitRepository.deleteByMemberId(id); memberRepository.deleteById(id); }