From f0effa1ee3c424b0ee0c264b064632d89eaa174b Mon Sep 17 00:00:00 2001 From: thguss Date: Sat, 16 Nov 2024 21:04:04 +0900 Subject: [PATCH 1/9] fix: re-packaging --- .../server/persistence/adapter/MemberRoutineAdapter.java | 2 +- .../com/soptie/server/persistence/adapter/RoutineAdapter.java | 2 +- .../persistence/entity/{ => routine}/MemberRoutineEntity.java | 3 ++- .../persistence/entity/{ => routine}/RoutineEntity.java | 3 ++- .../repository/routine/MemberRoutineRepository.java | 2 +- .../persistence/repository/routine/RoutineRepository.java | 2 +- .../com/soptie/server/batch/MemberRoutineSchedulerTest.java | 4 ++-- 7 files changed, 10 insertions(+), 8 deletions(-) rename src/main/java/com/soptie/server/persistence/entity/{ => routine}/MemberRoutineEntity.java (95%) rename src/main/java/com/soptie/server/persistence/entity/{ => routine}/RoutineEntity.java (87%) diff --git a/src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java index 85945c06..2612a0b5 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java @@ -8,7 +8,7 @@ import com.soptie.server.domain.member.Member; import com.soptie.server.domain.memberroutine.MemberRoutine; import com.soptie.server.domain.routine.Routine; -import com.soptie.server.persistence.entity.MemberRoutineEntity; +import com.soptie.server.persistence.entity.routine.MemberRoutineEntity; import com.soptie.server.persistence.repository.routine.MemberRoutineRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java index a7f80038..3af8c4b7 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java @@ -6,7 +6,7 @@ import com.soptie.server.common.exception.SoftieException; import com.soptie.server.common.support.RepositoryAdapter; import com.soptie.server.domain.routine.Routine; -import com.soptie.server.persistence.entity.RoutineEntity; +import com.soptie.server.persistence.entity.routine.RoutineEntity; import com.soptie.server.persistence.repository.routine.RoutineRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/entity/MemberRoutineEntity.java b/src/main/java/com/soptie/server/persistence/entity/routine/MemberRoutineEntity.java similarity index 95% rename from src/main/java/com/soptie/server/persistence/entity/MemberRoutineEntity.java rename to src/main/java/com/soptie/server/persistence/entity/routine/MemberRoutineEntity.java index 5b46cf35..de88b706 100644 --- a/src/main/java/com/soptie/server/persistence/entity/MemberRoutineEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/routine/MemberRoutineEntity.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.entity; +package com.soptie.server.persistence.entity.routine; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLRestriction; @@ -6,6 +6,7 @@ import com.soptie.server.domain.member.Member; import com.soptie.server.domain.memberroutine.MemberRoutine; import com.soptie.server.domain.routine.Routine; +import com.soptie.server.persistence.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/soptie/server/persistence/entity/RoutineEntity.java b/src/main/java/com/soptie/server/persistence/entity/routine/RoutineEntity.java similarity index 87% rename from src/main/java/com/soptie/server/persistence/entity/RoutineEntity.java rename to src/main/java/com/soptie/server/persistence/entity/routine/RoutineEntity.java index fd92c340..107bdcc5 100644 --- a/src/main/java/com/soptie/server/persistence/entity/RoutineEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/routine/RoutineEntity.java @@ -1,6 +1,7 @@ -package com.soptie.server.persistence.entity; +package com.soptie.server.persistence.entity.routine; import com.soptie.server.domain.routine.Routine; +import com.soptie.server.persistence.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/soptie/server/persistence/repository/routine/MemberRoutineRepository.java b/src/main/java/com/soptie/server/persistence/repository/routine/MemberRoutineRepository.java index 08383a1a..f3a0244f 100644 --- a/src/main/java/com/soptie/server/persistence/repository/routine/MemberRoutineRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/routine/MemberRoutineRepository.java @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import com.soptie.server.persistence.entity.MemberRoutineEntity; +import com.soptie.server.persistence.entity.routine.MemberRoutineEntity; import com.soptie.server.persistence.repository.routine.custom.MemberRoutineCustomRepository; public interface MemberRoutineRepository diff --git a/src/main/java/com/soptie/server/persistence/repository/routine/RoutineRepository.java b/src/main/java/com/soptie/server/persistence/repository/routine/RoutineRepository.java index f077abc0..1ad825b3 100644 --- a/src/main/java/com/soptie/server/persistence/repository/routine/RoutineRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/routine/RoutineRepository.java @@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import com.soptie.server.persistence.entity.RoutineEntity; +import com.soptie.server.persistence.entity.routine.RoutineEntity; public interface RoutineRepository extends JpaRepository { //TODO: 데이터베이스 내부 자체 처리 방법 찾아보기 diff --git a/src/test/java/com/soptie/server/batch/MemberRoutineSchedulerTest.java b/src/test/java/com/soptie/server/batch/MemberRoutineSchedulerTest.java index cf13675f..67a197c4 100644 --- a/src/test/java/com/soptie/server/batch/MemberRoutineSchedulerTest.java +++ b/src/test/java/com/soptie/server/batch/MemberRoutineSchedulerTest.java @@ -21,8 +21,8 @@ import com.soptie.server.domain.memberroutine.MemberRoutineService; import com.soptie.server.domain.routine.Routine; import com.soptie.server.persistence.entity.MemberEntity; -import com.soptie.server.persistence.entity.MemberRoutineEntity; -import com.soptie.server.persistence.entity.RoutineEntity; +import com.soptie.server.persistence.entity.routine.MemberRoutineEntity; +import com.soptie.server.persistence.entity.routine.RoutineEntity; import com.soptie.server.persistence.repository.MemberRepository; import com.soptie.server.persistence.repository.routine.MemberRoutineRepository; import com.soptie.server.persistence.repository.routine.RoutineRepository; From 2979fb57e2fc62d8145bf625bef86cb437ddc25c Mon Sep 17 00:00:00 2001 From: thguss Date: Sat, 16 Nov 2024 23:32:20 +0900 Subject: [PATCH 2/9] add: added Entity --- .../entity/mission/MissionHistoryEntity.java | 12 ++++++++++++ .../entity/routine/RoutineHistoryEntity.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java create mode 100644 src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java diff --git a/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java b/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java new file mode 100644 index 00000000..da745b51 --- /dev/null +++ b/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java @@ -0,0 +1,12 @@ +package com.soptie.server.persistence.entity.mission; + +import com.soptie.server.persistence.entity.BaseEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "mission_history", schema = "softie") +public class MissionHistoryEntity extends BaseEntity { + private long memberMissionId; +} diff --git a/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java b/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java new file mode 100644 index 00000000..7b2144a3 --- /dev/null +++ b/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java @@ -0,0 +1,12 @@ +package com.soptie.server.persistence.entity.routine; + +import com.soptie.server.persistence.entity.BaseEntity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "routine_history", schema = "softie") +public class RoutineHistoryEntity extends BaseEntity { + private long memberRoutineId; +} From b42c3cde2ae0e68d7d51d08dcc0c532c925eb282 Mon Sep 17 00:00:00 2001 From: thguss Date: Sat, 16 Nov 2024 23:32:49 +0900 Subject: [PATCH 3/9] fix: re-packaging --- .../soptie/server/persistence/adapter/ChallengeAdapter.java | 2 +- .../server/persistence/adapter/MemberMissionAdapter.java | 2 +- .../com/soptie/server/persistence/adapter/MissionAdapter.java | 2 +- .../persistence/entity/{ => mission}/ChallengeEntity.java | 3 ++- .../persistence/entity/{ => mission}/MemberMissionEntity.java | 3 ++- .../server/persistence/entity/{ => mission}/MissionEntity.java | 3 ++- .../server/persistence/repository/ChallengeRepository.java | 2 +- .../server/persistence/repository/MemberMissionRepository.java | 2 +- .../server/persistence/repository/MissionRepository.java | 2 +- src/main/java/com/soptie/server/temporary/TemporaryApi.java | 2 +- 10 files changed, 13 insertions(+), 10 deletions(-) rename src/main/java/com/soptie/server/persistence/entity/{ => mission}/ChallengeEntity.java (82%) rename src/main/java/com/soptie/server/persistence/entity/{ => mission}/MemberMissionEntity.java (93%) rename src/main/java/com/soptie/server/persistence/entity/{ => mission}/MissionEntity.java (87%) diff --git a/src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java index 10db06cf..ff735179 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java @@ -6,7 +6,7 @@ import com.soptie.server.common.exception.SoftieException; import com.soptie.server.common.support.RepositoryAdapter; import com.soptie.server.domain.challenge.Challenge; -import com.soptie.server.persistence.entity.ChallengeEntity; +import com.soptie.server.persistence.entity.mission.ChallengeEntity; import com.soptie.server.persistence.repository.ChallengeRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java index 494bb8f1..82ee36fc 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java @@ -9,7 +9,7 @@ import com.soptie.server.domain.challenge.Mission; import com.soptie.server.domain.member.Member; import com.soptie.server.domain.membermission.MemberMission; -import com.soptie.server.persistence.entity.MemberMissionEntity; +import com.soptie.server.persistence.entity.mission.MemberMissionEntity; import com.soptie.server.persistence.repository.MemberMissionRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java index 361e2eec..7d502f20 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java @@ -6,7 +6,7 @@ import com.soptie.server.common.exception.SoftieException; import com.soptie.server.common.support.RepositoryAdapter; import com.soptie.server.domain.challenge.Mission; -import com.soptie.server.persistence.entity.MissionEntity; +import com.soptie.server.persistence.entity.mission.MissionEntity; import com.soptie.server.persistence.repository.MissionRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/entity/ChallengeEntity.java b/src/main/java/com/soptie/server/persistence/entity/mission/ChallengeEntity.java similarity index 82% rename from src/main/java/com/soptie/server/persistence/entity/ChallengeEntity.java rename to src/main/java/com/soptie/server/persistence/entity/mission/ChallengeEntity.java index 3b5347ee..8a7e08a8 100644 --- a/src/main/java/com/soptie/server/persistence/entity/ChallengeEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/mission/ChallengeEntity.java @@ -1,6 +1,7 @@ -package com.soptie.server.persistence.entity; +package com.soptie.server.persistence.entity.mission; import com.soptie.server.domain.challenge.Challenge; +import com.soptie.server.persistence.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/soptie/server/persistence/entity/MemberMissionEntity.java b/src/main/java/com/soptie/server/persistence/entity/mission/MemberMissionEntity.java similarity index 93% rename from src/main/java/com/soptie/server/persistence/entity/MemberMissionEntity.java rename to src/main/java/com/soptie/server/persistence/entity/mission/MemberMissionEntity.java index 184dff23..66e4d69e 100644 --- a/src/main/java/com/soptie/server/persistence/entity/MemberMissionEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/mission/MemberMissionEntity.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.entity; +package com.soptie.server.persistence.entity.mission; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLRestriction; @@ -6,6 +6,7 @@ import com.soptie.server.domain.challenge.Mission; import com.soptie.server.domain.member.Member; import com.soptie.server.domain.membermission.MemberMission; +import com.soptie.server.persistence.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/soptie/server/persistence/entity/MissionEntity.java b/src/main/java/com/soptie/server/persistence/entity/mission/MissionEntity.java similarity index 87% rename from src/main/java/com/soptie/server/persistence/entity/MissionEntity.java rename to src/main/java/com/soptie/server/persistence/entity/mission/MissionEntity.java index d92fbde1..1ed25042 100644 --- a/src/main/java/com/soptie/server/persistence/entity/MissionEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/mission/MissionEntity.java @@ -1,6 +1,7 @@ -package com.soptie.server.persistence.entity; +package com.soptie.server.persistence.entity.mission; import com.soptie.server.domain.challenge.Mission; +import com.soptie.server.persistence.entity.BaseEntity; import jakarta.persistence.Column; import jakarta.persistence.Entity; diff --git a/src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java b/src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java index 14f9521d..12122fb3 100644 --- a/src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java @@ -4,7 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository; -import com.soptie.server.persistence.entity.ChallengeEntity; +import com.soptie.server.persistence.entity.mission.ChallengeEntity; public interface ChallengeRepository extends JpaRepository { List findByThemeId(long themeId); diff --git a/src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java b/src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java index b2fc705d..ce33f9d1 100644 --- a/src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java @@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -import com.soptie.server.persistence.entity.MemberMissionEntity; +import com.soptie.server.persistence.entity.mission.MemberMissionEntity; public interface MemberMissionRepository extends JpaRepository { List findByMemberIdAndMissionIdIn(long memberId, List missionIds); diff --git a/src/main/java/com/soptie/server/persistence/repository/MissionRepository.java b/src/main/java/com/soptie/server/persistence/repository/MissionRepository.java index bd4bc426..1a3258d9 100644 --- a/src/main/java/com/soptie/server/persistence/repository/MissionRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/MissionRepository.java @@ -4,7 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository; -import com.soptie.server.persistence.entity.MissionEntity; +import com.soptie.server.persistence.entity.mission.MissionEntity; public interface MissionRepository extends JpaRepository { List findByChallengeIdIn(List challengeIds); diff --git a/src/main/java/com/soptie/server/temporary/TemporaryApi.java b/src/main/java/com/soptie/server/temporary/TemporaryApi.java index 40ebab13..f5248d6c 100644 --- a/src/main/java/com/soptie/server/temporary/TemporaryApi.java +++ b/src/main/java/com/soptie/server/temporary/TemporaryApi.java @@ -29,8 +29,8 @@ import com.soptie.server.persistence.adapter.MissionAdapter; import com.soptie.server.persistence.adapter.RoutineAdapter; import com.soptie.server.persistence.adapter.ThemeAdapter; -import com.soptie.server.persistence.entity.ChallengeEntity; import com.soptie.server.persistence.entity.ThemeEntity; +import com.soptie.server.persistence.entity.mission.ChallengeEntity; import com.soptie.server.persistence.repository.ChallengeRepository; import com.soptie.server.persistence.repository.ThemeRepository; import com.soptie.server.temporary.dto.CreateMemberDailyRoutine; From 8f5a50d30d5edafe026936ca3f57153fd681ca91 Mon Sep 17 00:00:00 2001 From: thguss Date: Sat, 16 Nov 2024 23:54:11 +0900 Subject: [PATCH 4/9] add: added updating history --- .../memberroutine/MemberRoutineService.java | 12 ++++++++++ .../routine/RoutineHistoryAdapter.java | 24 +++++++++++++++++++ .../entity/routine/RoutineHistoryEntity.java | 7 ++++++ .../routine/RoutineHistoryRepository.java | 16 +++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/main/java/com/soptie/server/persistence/adapter/routine/RoutineHistoryAdapter.java create mode 100644 src/main/java/com/soptie/server/persistence/repository/routine/RoutineHistoryRepository.java diff --git a/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java b/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java index 539eb797..55d36430 100644 --- a/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java +++ b/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java @@ -1,5 +1,6 @@ package com.soptie.server.domain.memberroutine; +import java.time.LocalDate; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -19,6 +20,7 @@ import com.soptie.server.persistence.adapter.MemberRoutineAdapter; import com.soptie.server.persistence.adapter.RoutineAdapter; import com.soptie.server.persistence.adapter.ThemeAdapter; +import com.soptie.server.persistence.adapter.routine.RoutineHistoryAdapter; import lombok.RequiredArgsConstructor; import lombok.val; @@ -31,6 +33,7 @@ public class MemberRoutineService { private final MemberAdapter memberAdapter; private final RoutineAdapter routineAdapter; private final ThemeAdapter themeAdapter; + private final RoutineHistoryAdapter routineHistoryAdapter; @Transactional public CreateMemberRoutinesResponse createRoutines( @@ -85,10 +88,19 @@ public AchieveMemberRoutineResponse achieveMemberRoutine(long memberId, long mem memberRoutine.achieve(); memberRoutineAdapter.update(memberRoutine); + updateHistory(memberRoutineId, isAchievedToday); return AchieveMemberRoutineResponse.of(memberRoutine, !isAchievedToday); } + private void updateHistory(long memberRoutineId, boolean isAchievedToday) { + if (isAchievedToday) { + routineHistoryAdapter.save(memberRoutineId); + } else { + routineHistoryAdapter.deleteByRoutineIdAndCreatedAt(memberRoutineId, LocalDate.now()); + } + } + @Transactional public void initAchievement() { memberRoutineAdapter.initAllAchievement(); diff --git a/src/main/java/com/soptie/server/persistence/adapter/routine/RoutineHistoryAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/routine/RoutineHistoryAdapter.java new file mode 100644 index 00000000..3b0e4725 --- /dev/null +++ b/src/main/java/com/soptie/server/persistence/adapter/routine/RoutineHistoryAdapter.java @@ -0,0 +1,24 @@ +package com.soptie.server.persistence.adapter.routine; + +import java.time.LocalDate; + +import org.springframework.stereotype.Component; + +import com.soptie.server.persistence.entity.routine.RoutineHistoryEntity; +import com.soptie.server.persistence.repository.routine.RoutineHistoryRepository; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class RoutineHistoryAdapter { + private final RoutineHistoryRepository historyRepository; + + public void save(long memberRoutineId) { + historyRepository.save(new RoutineHistoryEntity(memberRoutineId)); + } + + public void deleteByRoutineIdAndCreatedAt(long memberRoutineId, LocalDate date) { + historyRepository.deleteByMemberRoutineIdAndCreatedAt(memberRoutineId, date); + } +} diff --git a/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java b/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java index 7b2144a3..b2ca35d3 100644 --- a/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/routine/RoutineHistoryEntity.java @@ -4,9 +4,16 @@ import jakarta.persistence.Entity; import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "routine_history", schema = "softie") public class RoutineHistoryEntity extends BaseEntity { private long memberRoutineId; + + public RoutineHistoryEntity(long memberRoutineId) { + this.memberRoutineId = memberRoutineId; + } } diff --git a/src/main/java/com/soptie/server/persistence/repository/routine/RoutineHistoryRepository.java b/src/main/java/com/soptie/server/persistence/repository/routine/RoutineHistoryRepository.java new file mode 100644 index 00000000..1835e2f7 --- /dev/null +++ b/src/main/java/com/soptie/server/persistence/repository/routine/RoutineHistoryRepository.java @@ -0,0 +1,16 @@ +package com.soptie.server.persistence.repository.routine; + +import java.time.LocalDate; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; + +import com.soptie.server.persistence.entity.routine.RoutineHistoryEntity; + +public interface RoutineHistoryRepository extends JpaRepository { + @Modifying + @Query("DELETE FROM RoutineHistoryEntity r " + + "WHERE r.memberRoutineId = :memberRoutineId AND FUNCTION('DATE', r.createdAt) = :date") + void deleteByMemberRoutineIdAndCreatedAt(long memberRoutineId, LocalDate date); +} From 539e11254b91a72ec29f837afa8983ac14742d24 Mon Sep 17 00:00:00 2001 From: thguss Date: Sat, 16 Nov 2024 23:56:13 +0900 Subject: [PATCH 5/9] fix: re-packaging --- .../repository/routine/custom/MemberRoutineRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/soptie/server/persistence/repository/routine/custom/MemberRoutineRepositoryImpl.java b/src/main/java/com/soptie/server/persistence/repository/routine/custom/MemberRoutineRepositoryImpl.java index 8dc08a16..d824f439 100644 --- a/src/main/java/com/soptie/server/persistence/repository/routine/custom/MemberRoutineRepositoryImpl.java +++ b/src/main/java/com/soptie/server/persistence/repository/routine/custom/MemberRoutineRepositoryImpl.java @@ -1,6 +1,6 @@ package com.soptie.server.persistence.repository.routine.custom; -import static com.soptie.server.persistence.entity.QMemberRoutineEntity.*; +import static com.soptie.server.persistence.entity.routine.QMemberRoutineEntity.*; import org.springframework.stereotype.Repository; From 31da0c2b13b9e77f1c9de860a5e64569d7052d0a Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 17 Nov 2024 00:02:18 +0900 Subject: [PATCH 6/9] fix: updated history method --- .../server/domain/memberroutine/MemberRoutineService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java b/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java index 55d36430..69711210 100644 --- a/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java +++ b/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java @@ -95,9 +95,9 @@ public AchieveMemberRoutineResponse achieveMemberRoutine(long memberId, long mem private void updateHistory(long memberRoutineId, boolean isAchievedToday) { if (isAchievedToday) { - routineHistoryAdapter.save(memberRoutineId); - } else { routineHistoryAdapter.deleteByRoutineIdAndCreatedAt(memberRoutineId, LocalDate.now()); + } else { + routineHistoryAdapter.save(memberRoutineId); } } From ec0615b08d21c8ee890e6b90e24a4fc7a3456d64 Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 17 Nov 2024 00:04:19 +0900 Subject: [PATCH 7/9] fix: re-packaging --- .../soptie/server/domain/auth/AuthService.java | 4 ++-- .../server/domain/challenge/ChallengeService.java | 6 +++--- .../server/domain/member/MemberService.java | 4 ++-- .../membermission/MemberMissionService.java | 15 ++++++++++++--- .../memberroutine/MemberRoutineService.java | 4 ++-- .../server/domain/routine/RoutineService.java | 4 ++-- .../adapter/{ => mission}/ChallengeAdapter.java | 2 +- .../{ => mission}/MemberMissionAdapter.java | 2 +- .../adapter/{ => mission}/MissionAdapter.java | 2 +- .../{ => routine}/MemberRoutineAdapter.java | 2 +- .../adapter/{ => routine}/RoutineAdapter.java | 2 +- .../com/soptie/server/temporary/TemporaryApi.java | 10 +++++----- 12 files changed, 33 insertions(+), 24 deletions(-) rename src/main/java/com/soptie/server/persistence/adapter/{ => mission}/ChallengeAdapter.java (94%) rename src/main/java/com/soptie/server/persistence/adapter/{ => mission}/MemberMissionAdapter.java (98%) rename src/main/java/com/soptie/server/persistence/adapter/{ => mission}/MissionAdapter.java (94%) rename src/main/java/com/soptie/server/persistence/adapter/{ => routine}/MemberRoutineAdapter.java (98%) rename src/main/java/com/soptie/server/persistence/adapter/{ => routine}/RoutineAdapter.java (95%) diff --git a/src/main/java/com/soptie/server/domain/auth/AuthService.java b/src/main/java/com/soptie/server/domain/auth/AuthService.java index 0f5ad307..0aaf9840 100644 --- a/src/main/java/com/soptie/server/domain/auth/AuthService.java +++ b/src/main/java/com/soptie/server/domain/auth/AuthService.java @@ -16,8 +16,8 @@ import com.soptie.server.external.oauth.KakaoService; import com.soptie.server.persistence.adapter.MemberAdapter; import com.soptie.server.persistence.adapter.MemberDollAdapter; -import com.soptie.server.persistence.adapter.MemberMissionAdapter; -import com.soptie.server.persistence.adapter.MemberRoutineAdapter; +import com.soptie.server.persistence.adapter.mission.MemberMissionAdapter; +import com.soptie.server.persistence.adapter.routine.MemberRoutineAdapter; import lombok.RequiredArgsConstructor; import lombok.val; diff --git a/src/main/java/com/soptie/server/domain/challenge/ChallengeService.java b/src/main/java/com/soptie/server/domain/challenge/ChallengeService.java index 327265cb..d8f9a426 100644 --- a/src/main/java/com/soptie/server/domain/challenge/ChallengeService.java +++ b/src/main/java/com/soptie/server/domain/challenge/ChallengeService.java @@ -9,9 +9,9 @@ import com.soptie.server.api.controller.dto.response.challenge.GetChallengesByMemberResponse; import com.soptie.server.domain.membermission.MemberMission; -import com.soptie.server.persistence.adapter.ChallengeAdapter; -import com.soptie.server.persistence.adapter.MemberMissionAdapter; -import com.soptie.server.persistence.adapter.MissionAdapter; +import com.soptie.server.persistence.adapter.mission.ChallengeAdapter; +import com.soptie.server.persistence.adapter.mission.MemberMissionAdapter; +import com.soptie.server.persistence.adapter.mission.MissionAdapter; import lombok.RequiredArgsConstructor; import lombok.val; diff --git a/src/main/java/com/soptie/server/domain/member/MemberService.java b/src/main/java/com/soptie/server/domain/member/MemberService.java index f10e44c8..40cda857 100644 --- a/src/main/java/com/soptie/server/domain/member/MemberService.java +++ b/src/main/java/com/soptie/server/domain/member/MemberService.java @@ -17,8 +17,8 @@ import com.soptie.server.persistence.adapter.DollAdapter; import com.soptie.server.persistence.adapter.MemberAdapter; import com.soptie.server.persistence.adapter.MemberDollAdapter; -import com.soptie.server.persistence.adapter.MemberRoutineAdapter; -import com.soptie.server.persistence.adapter.RoutineAdapter; +import com.soptie.server.persistence.adapter.routine.MemberRoutineAdapter; +import com.soptie.server.persistence.adapter.routine.RoutineAdapter; import lombok.RequiredArgsConstructor; import lombok.val; diff --git a/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java b/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java index ed14d656..9095f9c9 100644 --- a/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java +++ b/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java @@ -1,5 +1,6 @@ package com.soptie.server.domain.membermission; +import java.time.LocalDate; import java.util.Optional; import org.springframework.stereotype.Service; @@ -10,11 +11,11 @@ import com.soptie.server.api.controller.dto.response.membermission.GetMemberMissionResponse; import com.soptie.server.common.exception.ExceptionCode; import com.soptie.server.common.exception.SoftieException; -import com.soptie.server.persistence.adapter.ChallengeAdapter; import com.soptie.server.persistence.adapter.MemberAdapter; -import com.soptie.server.persistence.adapter.MemberMissionAdapter; -import com.soptie.server.persistence.adapter.MissionAdapter; import com.soptie.server.persistence.adapter.ThemeAdapter; +import com.soptie.server.persistence.adapter.mission.ChallengeAdapter; +import com.soptie.server.persistence.adapter.mission.MemberMissionAdapter; +import com.soptie.server.persistence.adapter.mission.MissionAdapter; import lombok.RequiredArgsConstructor; import lombok.val; @@ -70,6 +71,14 @@ public void achieveMemberMission(long memberId, long missionId) { memberMissionAdapter.delete(memberMission); } + private void updateHistory(long memberRoutineId, boolean isAchievedToday) { + if (isAchievedToday) { + routineHistoryAdapter.deleteByRoutineIdAndCreatedAt(memberRoutineId, LocalDate.now()); + } else { + routineHistoryAdapter.save(memberRoutineId); + } + } + public Optional getMemberMission(long memberId) { return memberMissionAdapter.findByMember(memberId).map(this::toGetMemberMissionResponse); } diff --git a/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java b/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java index 69711210..a78ca01a 100644 --- a/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java +++ b/src/main/java/com/soptie/server/domain/memberroutine/MemberRoutineService.java @@ -17,9 +17,9 @@ import com.soptie.server.domain.routine.Routine; import com.soptie.server.domain.theme.Theme; import com.soptie.server.persistence.adapter.MemberAdapter; -import com.soptie.server.persistence.adapter.MemberRoutineAdapter; -import com.soptie.server.persistence.adapter.RoutineAdapter; import com.soptie.server.persistence.adapter.ThemeAdapter; +import com.soptie.server.persistence.adapter.routine.MemberRoutineAdapter; +import com.soptie.server.persistence.adapter.routine.RoutineAdapter; import com.soptie.server.persistence.adapter.routine.RoutineHistoryAdapter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/domain/routine/RoutineService.java b/src/main/java/com/soptie/server/domain/routine/RoutineService.java index 3e3162e2..b2744b84 100644 --- a/src/main/java/com/soptie/server/domain/routine/RoutineService.java +++ b/src/main/java/com/soptie/server/domain/routine/RoutineService.java @@ -13,8 +13,8 @@ import com.soptie.server.api.controller.dto.response.routine.GetRoutinesByMemberResponse; import com.soptie.server.api.controller.dto.response.routine.GetRoutinesByThemeResponse; import com.soptie.server.domain.memberroutine.MemberRoutine; -import com.soptie.server.persistence.adapter.MemberRoutineAdapter; -import com.soptie.server.persistence.adapter.RoutineAdapter; +import com.soptie.server.persistence.adapter.routine.MemberRoutineAdapter; +import com.soptie.server.persistence.adapter.routine.RoutineAdapter; import lombok.RequiredArgsConstructor; import lombok.val; diff --git a/src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java similarity index 94% rename from src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java rename to src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java index ff735179..9bccebde 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/ChallengeAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.adapter; +package com.soptie.server.persistence.adapter.mission; import java.util.List; diff --git a/src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java similarity index 98% rename from src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java rename to src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java index 82ee36fc..c914494a 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/MemberMissionAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.adapter; +package com.soptie.server.persistence.adapter.mission; import java.util.List; import java.util.Optional; diff --git a/src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java similarity index 94% rename from src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java rename to src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java index 7d502f20..cacda313 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/MissionAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.adapter; +package com.soptie.server.persistence.adapter.mission; import java.util.List; diff --git a/src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/routine/MemberRoutineAdapter.java similarity index 98% rename from src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java rename to src/main/java/com/soptie/server/persistence/adapter/routine/MemberRoutineAdapter.java index 2612a0b5..ffeb1eee 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/MemberRoutineAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/routine/MemberRoutineAdapter.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.adapter; +package com.soptie.server.persistence.adapter.routine; import java.util.List; diff --git a/src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/routine/RoutineAdapter.java similarity index 95% rename from src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java rename to src/main/java/com/soptie/server/persistence/adapter/routine/RoutineAdapter.java index 3af8c4b7..61ccff99 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/RoutineAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/routine/RoutineAdapter.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.adapter; +package com.soptie.server.persistence.adapter.routine; import java.util.List; diff --git a/src/main/java/com/soptie/server/temporary/TemporaryApi.java b/src/main/java/com/soptie/server/temporary/TemporaryApi.java index f5248d6c..777573dc 100644 --- a/src/main/java/com/soptie/server/temporary/TemporaryApi.java +++ b/src/main/java/com/soptie/server/temporary/TemporaryApi.java @@ -22,13 +22,13 @@ import com.soptie.server.domain.doll.DollType; import com.soptie.server.domain.memberroutine.MemberRoutine; import com.soptie.server.domain.routine.Routine; -import com.soptie.server.persistence.adapter.ChallengeAdapter; import com.soptie.server.persistence.adapter.MemberAdapter; -import com.soptie.server.persistence.adapter.MemberMissionAdapter; -import com.soptie.server.persistence.adapter.MemberRoutineAdapter; -import com.soptie.server.persistence.adapter.MissionAdapter; -import com.soptie.server.persistence.adapter.RoutineAdapter; import com.soptie.server.persistence.adapter.ThemeAdapter; +import com.soptie.server.persistence.adapter.mission.ChallengeAdapter; +import com.soptie.server.persistence.adapter.mission.MemberMissionAdapter; +import com.soptie.server.persistence.adapter.mission.MissionAdapter; +import com.soptie.server.persistence.adapter.routine.MemberRoutineAdapter; +import com.soptie.server.persistence.adapter.routine.RoutineAdapter; import com.soptie.server.persistence.entity.ThemeEntity; import com.soptie.server.persistence.entity.mission.ChallengeEntity; import com.soptie.server.persistence.repository.ChallengeRepository; From 6195e3920c9f0c2f04d69af32eb20f1c563fa710 Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 17 Nov 2024 00:05:15 +0900 Subject: [PATCH 8/9] fix: re-packaging --- .../server/persistence/adapter/mission/ChallengeAdapter.java | 2 +- .../persistence/adapter/mission/MemberMissionAdapter.java | 2 +- .../server/persistence/adapter/mission/MissionAdapter.java | 2 +- .../repository/{ => mission}/ChallengeRepository.java | 2 +- .../repository/{ => mission}/MemberMissionRepository.java | 2 +- .../persistence/repository/{ => mission}/MissionRepository.java | 2 +- src/main/java/com/soptie/server/temporary/TemporaryApi.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/com/soptie/server/persistence/repository/{ => mission}/ChallengeRepository.java (83%) rename src/main/java/com/soptie/server/persistence/repository/{ => mission}/MemberMissionRepository.java (93%) rename src/main/java/com/soptie/server/persistence/repository/{ => mission}/MissionRepository.java (84%) diff --git a/src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java index 9bccebde..0e96cafc 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/ChallengeAdapter.java @@ -7,7 +7,7 @@ import com.soptie.server.common.support.RepositoryAdapter; import com.soptie.server.domain.challenge.Challenge; import com.soptie.server.persistence.entity.mission.ChallengeEntity; -import com.soptie.server.persistence.repository.ChallengeRepository; +import com.soptie.server.persistence.repository.mission.ChallengeRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java index c914494a..d8ce342e 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/MemberMissionAdapter.java @@ -10,7 +10,7 @@ import com.soptie.server.domain.member.Member; import com.soptie.server.domain.membermission.MemberMission; import com.soptie.server.persistence.entity.mission.MemberMissionEntity; -import com.soptie.server.persistence.repository.MemberMissionRepository; +import com.soptie.server.persistence.repository.mission.MemberMissionRepository; import lombok.RequiredArgsConstructor; import lombok.val; diff --git a/src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java index cacda313..32436adf 100644 --- a/src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/MissionAdapter.java @@ -7,7 +7,7 @@ import com.soptie.server.common.support.RepositoryAdapter; import com.soptie.server.domain.challenge.Mission; import com.soptie.server.persistence.entity.mission.MissionEntity; -import com.soptie.server.persistence.repository.MissionRepository; +import com.soptie.server.persistence.repository.mission.MissionRepository; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java b/src/main/java/com/soptie/server/persistence/repository/mission/ChallengeRepository.java similarity index 83% rename from src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java rename to src/main/java/com/soptie/server/persistence/repository/mission/ChallengeRepository.java index 12122fb3..056dceb9 100644 --- a/src/main/java/com/soptie/server/persistence/repository/ChallengeRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/mission/ChallengeRepository.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.repository; +package com.soptie.server.persistence.repository.mission; import java.util.List; diff --git a/src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java b/src/main/java/com/soptie/server/persistence/repository/mission/MemberMissionRepository.java similarity index 93% rename from src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java rename to src/main/java/com/soptie/server/persistence/repository/mission/MemberMissionRepository.java index ce33f9d1..870ef748 100644 --- a/src/main/java/com/soptie/server/persistence/repository/MemberMissionRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/mission/MemberMissionRepository.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.repository; +package com.soptie.server.persistence.repository.mission; import java.util.List; import java.util.Optional; diff --git a/src/main/java/com/soptie/server/persistence/repository/MissionRepository.java b/src/main/java/com/soptie/server/persistence/repository/mission/MissionRepository.java similarity index 84% rename from src/main/java/com/soptie/server/persistence/repository/MissionRepository.java rename to src/main/java/com/soptie/server/persistence/repository/mission/MissionRepository.java index 1a3258d9..b8b2b6ba 100644 --- a/src/main/java/com/soptie/server/persistence/repository/MissionRepository.java +++ b/src/main/java/com/soptie/server/persistence/repository/mission/MissionRepository.java @@ -1,4 +1,4 @@ -package com.soptie.server.persistence.repository; +package com.soptie.server.persistence.repository.mission; import java.util.List; diff --git a/src/main/java/com/soptie/server/temporary/TemporaryApi.java b/src/main/java/com/soptie/server/temporary/TemporaryApi.java index 777573dc..5e1d373e 100644 --- a/src/main/java/com/soptie/server/temporary/TemporaryApi.java +++ b/src/main/java/com/soptie/server/temporary/TemporaryApi.java @@ -31,8 +31,8 @@ import com.soptie.server.persistence.adapter.routine.RoutineAdapter; import com.soptie.server.persistence.entity.ThemeEntity; import com.soptie.server.persistence.entity.mission.ChallengeEntity; -import com.soptie.server.persistence.repository.ChallengeRepository; import com.soptie.server.persistence.repository.ThemeRepository; +import com.soptie.server.persistence.repository.mission.ChallengeRepository; import com.soptie.server.temporary.dto.CreateMemberDailyRoutine; import com.soptie.server.temporary.dto.DailyRoutineThemesResponse; import com.soptie.server.temporary.dto.DailyRoutinesResponse; From e250f8e177799b7ef0775fb37ba546e1107bf212 Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 17 Nov 2024 00:10:15 +0900 Subject: [PATCH 9/9] add: added updating history --- .../membermission/MemberMissionService.java | 12 +++--------- .../adapter/mission/MissionHistoryAdapter.java | 18 ++++++++++++++++++ .../entity/mission/MissionHistoryEntity.java | 7 +++++++ .../mission/MissionHistoryRepository.java | 8 ++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/soptie/server/persistence/adapter/mission/MissionHistoryAdapter.java create mode 100644 src/main/java/com/soptie/server/persistence/repository/mission/MissionHistoryRepository.java diff --git a/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java b/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java index 9095f9c9..4cc83781 100644 --- a/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java +++ b/src/main/java/com/soptie/server/domain/membermission/MemberMissionService.java @@ -1,6 +1,5 @@ package com.soptie.server.domain.membermission; -import java.time.LocalDate; import java.util.Optional; import org.springframework.stereotype.Service; @@ -16,6 +15,7 @@ import com.soptie.server.persistence.adapter.mission.ChallengeAdapter; import com.soptie.server.persistence.adapter.mission.MemberMissionAdapter; import com.soptie.server.persistence.adapter.mission.MissionAdapter; +import com.soptie.server.persistence.adapter.mission.MissionHistoryAdapter; import lombok.RequiredArgsConstructor; import lombok.val; @@ -29,6 +29,7 @@ public class MemberMissionService { private final ChallengeAdapter challengeAdapter; private final MissionAdapter missionAdapter; private final MemberAdapter memberAdapter; + private final MissionHistoryAdapter missionHistoryAdapter; @Transactional public CreateMemberMissionResponse createMemberMission(long memberId, CreateMemberMissionRequest request) { @@ -69,14 +70,7 @@ public void achieveMemberMission(long memberId, long missionId) { memberMissionAdapter.update(memberMission); memberMissionAdapter.flush(); memberMissionAdapter.delete(memberMission); - } - - private void updateHistory(long memberRoutineId, boolean isAchievedToday) { - if (isAchievedToday) { - routineHistoryAdapter.deleteByRoutineIdAndCreatedAt(memberRoutineId, LocalDate.now()); - } else { - routineHistoryAdapter.save(memberRoutineId); - } + missionHistoryAdapter.save(memberMission.getId()); } public Optional getMemberMission(long memberId) { diff --git a/src/main/java/com/soptie/server/persistence/adapter/mission/MissionHistoryAdapter.java b/src/main/java/com/soptie/server/persistence/adapter/mission/MissionHistoryAdapter.java new file mode 100644 index 00000000..f33dc5c5 --- /dev/null +++ b/src/main/java/com/soptie/server/persistence/adapter/mission/MissionHistoryAdapter.java @@ -0,0 +1,18 @@ +package com.soptie.server.persistence.adapter.mission; + +import org.springframework.stereotype.Component; + +import com.soptie.server.persistence.entity.mission.MissionHistoryEntity; +import com.soptie.server.persistence.repository.mission.MissionHistoryRepository; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class MissionHistoryAdapter { + private final MissionHistoryRepository historyRepository; + + public void save(long memberMissionId) { + historyRepository.save(new MissionHistoryEntity(memberMissionId)); + } +} diff --git a/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java b/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java index da745b51..7bd39a43 100644 --- a/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java +++ b/src/main/java/com/soptie/server/persistence/entity/mission/MissionHistoryEntity.java @@ -4,9 +4,16 @@ import jakarta.persistence.Entity; import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(name = "mission_history", schema = "softie") public class MissionHistoryEntity extends BaseEntity { private long memberMissionId; + + public MissionHistoryEntity(long memberMissionId) { + this.memberMissionId = memberMissionId; + } } diff --git a/src/main/java/com/soptie/server/persistence/repository/mission/MissionHistoryRepository.java b/src/main/java/com/soptie/server/persistence/repository/mission/MissionHistoryRepository.java new file mode 100644 index 00000000..cc1a33f5 --- /dev/null +++ b/src/main/java/com/soptie/server/persistence/repository/mission/MissionHistoryRepository.java @@ -0,0 +1,8 @@ +package com.soptie.server.persistence.repository.mission; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.soptie.server.persistence.entity.mission.MissionHistoryEntity; + +public interface MissionHistoryRepository extends JpaRepository { +}