Skip to content

Commit

Permalink
Merge pull request #351 from Team-Sopetit/fix/#530/sohyeon
Browse files Browse the repository at this point in the history
[FIX] 루틴/미션 달성 로직 수정
  • Loading branch information
thguss authored Nov 17, 2024
2 parents 852ed9f + e250f8e commit af7145a
Show file tree
Hide file tree
Showing 30 changed files with 174 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/soptie/server/domain/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
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 com.soptie.server.persistence.adapter.mission.MissionHistoryAdapter;

import lombok.RequiredArgsConstructor;
import lombok.val;
Expand All @@ -28,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) {
Expand Down Expand Up @@ -68,6 +70,7 @@ public void achieveMemberMission(long memberId, long missionId) {
memberMissionAdapter.update(memberMission);
memberMissionAdapter.flush();
memberMissionAdapter.delete(memberMission);
missionHistoryAdapter.save(memberMission.getId());
}

public Optional<GetMemberMissionResponse> getMemberMission(long memberId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,9 +17,10 @@
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;
import lombok.val;
Expand All @@ -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(
Expand Down Expand Up @@ -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.deleteByRoutineIdAndCreatedAt(memberRoutineId, LocalDate.now());
} else {
routineHistoryAdapter.save(memberRoutineId);
}
}

@Transactional
public void initAchievement() {
memberRoutineAdapter.initAllAchievement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.soptie.server.persistence.adapter;
package com.soptie.server.persistence.adapter.mission;

import java.util.List;

import com.soptie.server.common.exception.ExceptionCode;
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.repository.ChallengeRepository;
import com.soptie.server.persistence.entity.mission.ChallengeEntity;
import com.soptie.server.persistence.repository.mission.ChallengeRepository;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,8 +9,8 @@
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.repository.MemberMissionRepository;
import com.soptie.server.persistence.entity.mission.MemberMissionEntity;
import com.soptie.server.persistence.repository.mission.MemberMissionRepository;

import lombok.RequiredArgsConstructor;
import lombok.val;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.soptie.server.persistence.adapter;
package com.soptie.server.persistence.adapter.mission;

import java.util.List;

import com.soptie.server.common.exception.ExceptionCode;
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.repository.MissionRepository;
import com.soptie.server.persistence.entity.mission.MissionEntity;
import com.soptie.server.persistence.repository.mission.MissionRepository;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.soptie.server.persistence.adapter;
package com.soptie.server.persistence.adapter.routine;

import java.util.List;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.soptie.server.persistence.adapter;
package com.soptie.server.persistence.adapter.routine;

import java.util.List;

import com.soptie.server.common.exception.ExceptionCode;
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.soptie.server.persistence.entity;
package com.soptie.server.persistence.entity.mission;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.soptie.server.persistence.entity.mission;

import com.soptie.server.persistence.entity.BaseEntity;

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;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.soptie.server.persistence.entity;
package com.soptie.server.persistence.entity.routine;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.soptie.server.persistence.entity.routine;

import com.soptie.server.persistence.entity.BaseEntity;

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;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.soptie.server.persistence.repository;
package com.soptie.server.persistence.repository.mission;

import java.util.List;

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<ChallengeEntity, Long> {
List<ChallengeEntity> findByThemeId(long themeId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<MemberMissionEntity, Long> {
List<MemberMissionEntity> findByMemberIdAndMissionIdIn(long memberId, List<Long> missionIds);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MissionHistoryEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.soptie.server.persistence.repository;
package com.soptie.server.persistence.repository.mission;

import java.util.List;

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<MissionEntity, Long> {
List<MissionEntity> findByChallengeIdIn(List<Long> challengeIds);
Expand Down
Loading

0 comments on commit af7145a

Please sign in to comment.