diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java index 97dc7273..2cc3df06 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveCreateUseCase.java @@ -10,7 +10,6 @@ import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; -import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveDeleteService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveSaveService; @@ -21,6 +20,7 @@ import com.moing.backend.domain.missionHeart.domain.service.MissionHeartQueryService; import com.moing.backend.domain.team.domain.entity.Team; import com.moing.backend.domain.teamScore.application.service.TeamScoreLogicUseCase; +import com.moing.backend.global.utils.BaseService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -48,15 +48,12 @@ public MissionArchiveRes createArchive(String userSocialId, Long missionId, Miss Member member = memberGetService.getMemberBySocialId(userSocialId); Long memberId = member.getMemberId(); + Mission mission = missionQueryService.findMissionById(missionId); Team team = mission.getTeam(); MissionArchive newArchive = MissionArchiveMapper.mapToMissionArchive(missionReq, member, mission); - // 단일 미션인 경우 미션 인증 시도 시 ongoing 으로 변경 - if (mission.getType() == MissionType.ONCE && mission.getStatus() == MissionStatus.WAIT) { - mission.updateStatus(MissionStatus.ONGOING); - } // 인증 완료한 미션인지 확인 if (isDoneMission(memberId,mission)) { throw new NoMoreMissionArchiveException(); @@ -66,30 +63,39 @@ public MissionArchiveRes createArchive(String userSocialId, Long missionId, Miss // 반복 미션일 경우 if (mission.getType() == MissionType.REPEAT) { - // 예정된 반복미션 접근 제한 + // 아직 열리지 않은 반복미션 접근 제한 if (mission.getStatus() == MissionStatus.WAIT) { throw new NotYetMissionArchiveException(); } + // 당일 1회 인증만 가능 - if(!missionArchiveQueryService.findDoneTodayArchive(memberId,missionId)) - newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId)+1); - else + if (missionArchiveQueryService.isAbleToArchiveToday(memberId, missionId)) { throw new NoMoreMissionArchiveException(); + } else { + newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId) + 1); + } missionStateUseCase.updateMissionState(member, mission, newArchive); missionArchiveRes = MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive), memberId); + } + + // 한번 미션일 경우 + else { + + // 미션 생성 후 처음 미션 인증 시도 시 ongoing 으로 변경 + if(mission.getStatus() == MissionStatus.WAIT) { + mission.updateStatus(MissionStatus.ONGOING); + } - } else { newArchive.updateCount(missionArchiveQueryService.findMyDoneArchives(memberId, missionId)+1); missionStateUseCase.updateMissionState(member, mission, newArchive); missionArchiveRes = MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive), memberId); + + // 인증 후 n/n명 인증 성공 리턴값 업데이트 missionArchiveRes.updateCount(missionArchiveQueryService.findDoneSingleArchives(missionId)); } - -// missionStateUseCase.updateMissionState(member, mission, newArchive); -// missionArchiveRes = MissionArchiveMapper.mapToMissionArchiveRes(missionArchiveSaveService.save(newArchive), memberId); return missionArchiveRes; } @@ -99,8 +105,4 @@ public Boolean isDoneMission(Long memberId,Mission mission) { return missionArchiveQueryService.findMyDoneArchives(memberId, mission.getId()) >= mission.getNumber(); } - - - - } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveReadUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveReadUseCase.java index 763726a7..0ac0ccf0 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveReadUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveReadUseCase.java @@ -1,6 +1,5 @@ package com.moing.backend.domain.missionArchive.application.service; -import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; import com.moing.backend.domain.mission.domain.entity.Mission; import com.moing.backend.domain.mission.domain.entity.constant.MissionType; @@ -9,7 +8,6 @@ import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper; import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; import com.moing.backend.domain.team.domain.entity.Team; -import com.moing.backend.domain.team.domain.repository.TeamRepository; import com.moing.backend.domain.team.domain.service.TeamGetService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -40,7 +38,7 @@ public MyMissionArchiveRes getMyArchive(String userSocialId, Long missionId) { List missionArchiveRes = MissionArchiveMapper.mapToMissionArchiveResList(missionArchiveQueryService.findMyArchive(memberId, missionId), memberId); myMissionArchiveRes.updateArchives(missionArchiveRes); - myMissionArchiveRes.updateTodayStatus(missionArchiveQueryService.findDoneTodayArchive(memberId, missionId)); + myMissionArchiveRes.updateTodayStatus(missionArchiveQueryService.isAbleToArchiveToday(memberId, missionId)); return myMissionArchiveRes; diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java index 60a84e88..b306f349 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveUpdateUseCase.java @@ -46,7 +46,7 @@ public class MissionArchiveUpdateUseCase { private final MissionStateUseCase missionStateUseCase; - // 미션 재인증 (수정하기도 포함됨) + // 미션 재인증 (수정하기도 포함됨) -> 사용하지 않음 public MissionArchiveRes updateArchive(String userSocialId, Long missionId, MissionArchiveReq missionReq) { Member member = memberGetService.getMemberBySocialId(userSocialId); @@ -58,13 +58,12 @@ public MissionArchiveRes updateArchive(String userSocialId, Long missionId, Miss if (mission.getWay() == MissionWay.PHOTO && missionArchiveQueryService.isDone(memberId, missionId)) { //s3삭제 - } MissionArchive updateArchive = missionArchiveQueryService.findMyArchive(memberId, missionId).get(0); // 단일 미션 && 미션 종료 직전인지 확인 - if (mission.getType() == MissionType.ONCE && missionStateUseCase.isAbleToEnd(missionId)) { + if (mission.getType() == MissionType.ONCE && missionStateUseCase.isAbleToEnd(mission)) { mission.updateStatus(MissionStatus.SUCCESS); // 점수 반영 로직 diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java index ac242d4c..fd2ffc8d 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepository.java @@ -8,7 +8,6 @@ import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes; import com.moing.backend.domain.missionArchive.application.dto.res.MyArchiveStatus; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; -import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; import org.springframework.stereotype.Repository; import java.util.List; @@ -22,7 +21,7 @@ public interface MissionArchiveCustomRepository { Optional> findOthersArchives(Long memberId, Long missionId) ; - Optional findDonePeopleByMissionId(Long missionId); + Optional findDonePeopleBySingleMissionId(Long missionId); Optional findDonePeopleByRepeatMissionId(Long missionId); Optional findMyDoneCountByMissionId(Long missionId,Long memberId); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index 331c3f57..9c63483e 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -199,7 +199,7 @@ public Optional> findOthersArchives(Long memberId, Long mis @Override - public Optional findDonePeopleByMissionId(Long missionId) { + public Optional findDonePeopleBySingleMissionId(Long missionId) { BooleanExpression dateInRange = createRepeatTypeConditionByArchive(); diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java index 2e46966e..0aa1ea1b 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/service/MissionArchiveQueryService.java @@ -31,9 +31,6 @@ public MissionArchive findByMissionArchiveId(Long missionArchiveId) { return missionArchiveRepository.findById(missionArchiveId).orElseThrow(NotFoundMissionArchiveException::new); } - public MissionArchive findArchive(Long memberId, Long missionId) { - return missionArchiveRepository.findByMissionIdAndMemberId(memberId, missionId).orElseThrow(NotFoundMissionArchiveException::new); - } public List findMyArchive(Long memberId, Long missionId) { @@ -60,9 +57,6 @@ public List findOthersArchive(Long memberId, Long missionId) { return missionArchiveRepository.findOthersArchives(memberId, missionId).orElseThrow(NotFoundMissionArchiveException::new); } - public List findArchivesByMemberId(Long memberId) { - return missionArchiveRepository.findByMemberId(memberId).orElseThrow(NotFoundMissionArchiveException::new); - } public Boolean isDone(Long memberId, Long missionId) { Optional> byMemberId = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId); @@ -73,18 +67,6 @@ public Boolean isDone(Long memberId, Long missionId) { } } - public Boolean isTodayDone(Long memberId, Long missionId) { - Optional> byMemberId = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId); - if (byMemberId.isPresent()) { - - return Boolean.TRUE; - } else { - return Boolean.FALSE; - } - } - - // team의 mission id 들 가져와서 나의 mission archive 리턴 - /** * mission.getTeam() 팀의 단일미션 미션 인증 보드 */ @@ -107,7 +89,7 @@ public List findMyRepeatMissionArchives(Long memberId, Lo public Long findDoneSingleArchives(Long missionId) { - return missionArchiveRepository.findDonePeopleByMissionId(missionId).orElseThrow(NotFoundMissionArchiveException::new); + return missionArchiveRepository.findDonePeopleBySingleMissionId(missionId).orElseThrow(NotFoundMissionArchiveException::new); } public Long findDoneRepeatArchives(Long missionId) { return missionArchiveRepository.findDonePeopleByRepeatMissionId(missionId).orElseThrow(NotFoundMissionArchiveException::new); @@ -126,7 +108,7 @@ public List findTop5ArchivesByTeam(List teamIds) { return missionArchiveRepository.findTop5ArchivesByTeam(teamIds).orElse(null); } - public boolean findDoneTodayArchive(Long memberId, Long missionId) { + public boolean isAbleToArchiveToday(Long memberId, Long missionId) { return missionArchiveRepository.findMyArchivesToday(memberId, missionId); } diff --git a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java b/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java index 9c9ed7a1..e101d818 100644 --- a/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionState/application/service/MissionStateUseCase.java @@ -36,27 +36,17 @@ public class MissionStateUseCase { private final TeamScoreLogicUseCase teamScoreLogicUseCase; - public boolean isAbleToEnd(Long missionId) { + /* + 모든 모임원이 미션을 완료했는지 여부 확인 + */ + public boolean isAbleToEnd(Mission mission) { - Mission mission = missionQueryService.findMissionById(missionId); Long total = totalPeople(mission); Long done = donePeople(mission); return done >= total; } - public boolean isAbleToScoreUp(Long missionId) { - - Mission mission = missionQueryService.findMissionById(missionId); - Long total = totalPeople(mission); - Long done = donePeople(mission); - - log.info("done/total -> "+ done+ total); - - return done >= total; - - } - public Long donePeople(Mission mission) { return Long.valueOf(missionStateQueryService.stateCountByMissionId(mission.getId())); @@ -64,19 +54,22 @@ public Long donePeople(Mission mission) { public Long totalPeople(Mission mission) { return Long.valueOf(mission.getTeam().getNumOfMember()); - } public void updateMissionState(Member member, Mission mission, MissionArchive missionArchive) { - // 마지막 인증 시 - if (mission.getType().equals(MissionType.ONCE) && isAbleToEnd(mission.getId())) { - mission.updateStatus(MissionStatus.SUCCESS); - } + MissionType missionType = mission.getType(); + Long missionId = mission.getId(); + missionStateSaveService.saveMissionState(member,mission, missionArchive.getStatus()); - if (isAbleToScoreUp(mission.getId())) { - teamScoreLogicUseCase.updateTeamScore(mission.getId()); + if (missionType == MissionType.ONCE) { + + if (isAbleToEnd(mission)) { + mission.updateStatus(MissionStatus.SUCCESS); + teamScoreLogicUseCase.updateTeamScore(missionId); + } + } } diff --git a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java index 10b9e4b4..15f67329 100644 --- a/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionState/domain/repository/MissionStateCustomRepositoryImpl.java @@ -38,9 +38,9 @@ public int getCountsByMissionId(Long missionId) { LocalDate startOfWeek = now.with(TemporalAdjusters.previousOrSame(firstDayOfWeek)); LocalDate endOfWeek = startOfWeek.plusDays(6); // 한 주의 마지막일을 일요일로 설정 - BooleanExpression repeatTypeCondition = missionState.mission.type.eq(MissionType.REPEAT) + BooleanExpression repeatTypeCondition = (missionState.mission.type.eq(MissionType.REPEAT) .and(missionState.createdDate.goe(startOfWeek.atStartOfDay())) - .and(missionState.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1))); + .and(missionState.createdDate.loe(endOfWeek.atStartOfDay().plusDays(1).minusNanos(1)))).or(missionState.mission.type.eq(MissionType.ONCE)); // 기본 조건 BooleanExpression baseCondition = missionState.mission.id.eq(missionId);