Skip to content

Commit

Permalink
Merge pull request #193 from Modagbul/main
Browse files Browse the repository at this point in the history
[release] 반복미션 점수 로직 버그 수정 및
  • Loading branch information
seungueonn authored Jan 6, 2024
2 parents 93c4f16 + d95b8e2 commit 86e4001
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;

}
Expand All @@ -99,8 +105,4 @@ public Boolean isDoneMission(Long memberId,Mission mission) {
return missionArchiveQueryService.findMyDoneArchives(memberId, mission.getId()) >= mission.getNumber();
}





}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -40,7 +38,7 @@ public MyMissionArchiveRes getMyArchive(String userSocialId, Long missionId) {
List<MissionArchiveRes> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
// 점수 반영 로직

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,7 +21,7 @@ public interface MissionArchiveCustomRepository {

Optional<List<MissionArchive>> findOthersArchives(Long memberId, Long missionId) ;

Optional<Long> findDonePeopleByMissionId(Long missionId);
Optional<Long> findDonePeopleBySingleMissionId(Long missionId);
Optional<Long> findDonePeopleByRepeatMissionId(Long missionId);
Optional<Long> findMyDoneCountByMissionId(Long missionId,Long memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public Optional<List<MissionArchive>> findOthersArchives(Long memberId, Long mis


@Override
public Optional<Long> findDonePeopleByMissionId(Long missionId) {
public Optional<Long> findDonePeopleBySingleMissionId(Long missionId) {

BooleanExpression dateInRange = createRepeatTypeConditionByArchive();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MissionArchive> findMyArchive(Long memberId, Long missionId) {

Expand All @@ -60,9 +57,6 @@ public List<MissionArchive> findOthersArchive(Long memberId, Long missionId) {
return missionArchiveRepository.findOthersArchives(memberId, missionId).orElseThrow(NotFoundMissionArchiveException::new);
}

public List<MissionArchive> findArchivesByMemberId(Long memberId) {
return missionArchiveRepository.findByMemberId(memberId).orElseThrow(NotFoundMissionArchiveException::new);
}

public Boolean isDone(Long memberId, Long missionId) {
Optional<List<MissionArchive>> byMemberId = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId);
Expand All @@ -73,18 +67,6 @@ public Boolean isDone(Long memberId, Long missionId) {
}
}

public Boolean isTodayDone(Long memberId, Long missionId) {
Optional<List<MissionArchive>> byMemberId = missionArchiveRepository.findArchivesByMissionIdAndMemberId(memberId, missionId);
if (byMemberId.isPresent()) {

return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}

// team의 mission id 들 가져와서 나의 mission archive 리턴

/**
* mission.getTeam() 팀의 단일미션 미션 인증 보드
*/
Expand All @@ -107,7 +89,7 @@ public List<RepeatMissionBoardRes> 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);
Expand All @@ -126,7 +108,7 @@ public List<MissionArchivePhotoRes> findTop5ArchivesByTeam(List<Long> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,40 @@ 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()));
}

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);
}

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 86e4001

Please sign in to comment.