diff --git a/src/main/java/com/moing/backend/domain/mission/application/service/MissionUpdateUseCase.java b/src/main/java/com/moing/backend/domain/mission/application/service/MissionUpdateUseCase.java index bd10ef8e..37a42829 100644 --- a/src/main/java/com/moing/backend/domain/mission/application/service/MissionUpdateUseCase.java +++ b/src/main/java/com/moing/backend/domain/mission/application/service/MissionUpdateUseCase.java @@ -42,7 +42,7 @@ public MissionCreateRes updateMission(String userSocialId, Long missionId, Missi * 미션 생성자 확인 */ - if (!(memberId.equals(mission.getMakerId()) || memberId.equals(team.getLeaderId()))) { + if (!((memberId.equals(mission.getMakerId())) || memberId.equals(team.getLeaderId())) ) { throw new NoAccessUpdateMission(); } mission.updateMission(missionReq); @@ -55,10 +55,11 @@ public MissionReadRes updateMissionStatus(String userSocialId, Long missionId) { Member member = memberGetService.getMemberBySocialId(userSocialId); + Long memberId = member.getMemberId(); Mission findMission = missionQueryService.findMissionById(missionId); Team team = findMission.getTeam(); - if (findMission.getMakerId().equals(member.getMemberId())) { + if ((memberId.equals(findMission.getMakerId())) || memberId.equals(team.getLeaderId()) ) { findMission.updateStatus(MissionStatus.END); findMission.updateDueTo(LocalDateTime.now()); } else { 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 6ea5bda6..4d4ba925 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 @@ -19,6 +19,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.TeamScoreUpdateUseCase; +import com.moing.backend.domain.teamScore.domain.entity.ScoreStatus; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -31,14 +32,10 @@ public class MissionArchiveCreateUseCase { private final MissionArchiveSaveService missionArchiveSaveService; private final MissionArchiveQueryService missionArchiveQueryService; - private final MissionArchiveDeleteService missionArchiveDeleteService; - - private final MissionHeartQueryService missionHeartQueryService; private final MissionQueryService missionQueryService; private final MemberGetService memberGetService; - private final MissionStateSaveService missionStateSaveService; private final MissionStateUseCase missionStateUseCase; private final TeamScoreUpdateUseCase teamScoreUpdateUseCase; @@ -96,7 +93,7 @@ public MissionArchiveRes createArchive(String userSocialId, Long missionId, Miss gainBonusScore(mission, newArchive); } // TODO : 미션 인증 1회당 점수 - teamScoreUpdateUseCase.gainScoreOfArchive(mission); + teamScoreUpdateUseCase.gainScoreOfArchive(mission, ScoreStatus.PLUS); return missionArchiveRes; } @@ -113,13 +110,11 @@ private void gainBonusScore(Mission mission, MissionArchive missionArchive) { if (isAbleToFinishOnceMission(mission)) { mission.updateStatus(MissionStatus.SUCCESS); teamScoreUpdateUseCase.gainScoreOfBonus(mission); - log.info("isAbleToFinishOnceMission"); } } else { if (isAbleToFinishRepeatMission(mission, missionArchive)) { teamScoreUpdateUseCase.gainScoreOfBonus(mission); - log.info("isAbleToFinishRepeatMission"); } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java index a66bc217..cb577f8a 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/application/service/MissionArchiveDeleteUseCase.java @@ -23,6 +23,8 @@ import com.moing.backend.domain.missionState.domain.service.MissionStateQueryService; import com.moing.backend.domain.missionState.domain.service.MissionStateSaveService; import com.moing.backend.domain.team.domain.entity.Team; +import com.moing.backend.domain.teamScore.application.service.TeamScoreUpdateUseCase; +import com.moing.backend.domain.teamScore.domain.entity.ScoreStatus; import com.moing.backend.global.utils.UpdateUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -47,6 +49,8 @@ public class MissionArchiveDeleteUseCase { private final MissionStateDeleteService missionStateDeleteService; private final MissionStateQueryService missionStateQueryService; + private final TeamScoreUpdateUseCase teamScoreUpdateUseCase; + private final UpdateUtils updateUtils; @@ -55,10 +59,11 @@ public Long deleteArchive(String userSocialId, Long missionId,Long count) { Member member = memberGetService.getMemberBySocialId(userSocialId); Long memberId = member.getMemberId(); + Mission mission = missionQueryService.findMissionById(missionId); Team team = mission.getTeam(); - MissionArchive deleteArchive = missionArchiveQueryService.findOneMyArchive(memberId, missionId,count).get(0); + MissionArchive deleteArchive = missionArchiveQueryService.findOneMyArchive(memberId, missionId,count); MissionState missionState = missionStateQueryService.findMissionState(member, mission); LocalDateTime createdDate = deleteArchive.getCreatedDate(); @@ -77,6 +82,8 @@ public Long deleteArchive(String userSocialId, Long missionId,Long count) { missionArchiveDeleteService.deleteMissionArchive(deleteArchive); missionStateDeleteService.deleteMissionState(missionState); + teamScoreUpdateUseCase.gainScoreOfArchive(mission, ScoreStatus.MINUS); + return deleteArchive.getId(); } 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 68d24a01..700897c5 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 @@ -1,5 +1,6 @@ package com.moing.backend.domain.missionArchive.domain.service; +import com.moing.backend.domain.member.domain.repository.MemberRepository; import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes; import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes; @@ -26,6 +27,7 @@ public class MissionArchiveQueryService { private final MissionRepository missionRepository; private final MissionArchiveRepository missionArchiveRepository; private final TeamMemberRepository teamMemberRepository; + private final MemberRepository memberRepository; public MissionArchive findByMissionArchiveId(Long missionArchiveId) { return missionArchiveRepository.findById(missionArchiveId).orElseThrow(NotFoundMissionArchiveException::new); @@ -42,15 +44,11 @@ public List findMyArchive(Long memberId, Long missionId) { return optional.get(); } } - public List findOneMyArchive(Long memberId, Long missionId, Long count) { + public MissionArchive findOneMyArchive(Long memberId, Long missionId, Long count) { - Optional> optional = missionArchiveRepository.findMyArchives(memberId, missionId); + List missionArchives = missionArchiveRepository.findMyArchives(memberId, missionId).orElseThrow(NotFoundMissionArchiveException::new); + return missionArchives.stream().filter( m -> m.getCount().equals(count)).findFirst().orElseThrow(NotFoundMissionArchiveException::new); - if (optional.isPresent() && optional.get().size() == 0) { - return new ArrayList<>(); - } else { - return optional.get(); - } } public List findOthersArchive(Long memberId, Long missionId) { diff --git a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java index 6e54b28b..04c88904 100644 --- a/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java +++ b/src/main/java/com/moing/backend/domain/teamScore/application/service/TeamScoreUpdateUseCase.java @@ -5,6 +5,7 @@ import com.moing.backend.domain.mission.domain.entity.constant.MissionType; import com.moing.backend.domain.mission.domain.service.MissionQueryService; import com.moing.backend.domain.team.domain.entity.Team; +import com.moing.backend.domain.teamScore.domain.entity.ScoreStatus; import com.moing.backend.domain.teamScore.domain.entity.TeamScore; import com.moing.backend.domain.teamScore.domain.service.TeamScoreQueryService; import lombok.RequiredArgsConstructor; @@ -27,7 +28,7 @@ public class TeamScoreUpdateUseCase { /** * 매번 미션 인증 시 점수 적립 */ - public void gainScoreOfArchive(Mission mission) { + public void gainScoreOfArchive(Mission mission, ScoreStatus scoreStatus) { Team team = mission.getTeam(); @@ -36,8 +37,7 @@ public void gainScoreOfArchive(Mission mission) { Integer numOfMember = team.getNumOfMember(); Long gainScore = calculateScoreByArchive(numOfMember); - teamScore.updateScore(gainScore); - teamScore.updateLevel(); + teamScore.updateScore(gainScore * scoreStatus.getValue()); } @@ -68,7 +68,6 @@ public void gainScoreOfBonus(Mission mission) { } else { teamScore.updateScore(BONUS_SCORE_REPEAT_MISSION); } - teamScore.updateLevel(); } diff --git a/src/main/java/com/moing/backend/domain/teamScore/domain/entity/ScoreStatus.java b/src/main/java/com/moing/backend/domain/teamScore/domain/entity/ScoreStatus.java new file mode 100644 index 00000000..3471cae4 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/teamScore/domain/entity/ScoreStatus.java @@ -0,0 +1,11 @@ +package com.moing.backend.domain.teamScore.domain.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ScoreStatus { + PLUS(1L), MINUS(-1L); + private final Long value; +} diff --git a/src/main/java/com/moing/backend/domain/teamScore/domain/entity/TeamScore.java b/src/main/java/com/moing/backend/domain/teamScore/domain/entity/TeamScore.java index 62531629..d0a4395d 100644 --- a/src/main/java/com/moing/backend/domain/teamScore/domain/entity/TeamScore.java +++ b/src/main/java/com/moing/backend/domain/teamScore/domain/entity/TeamScore.java @@ -34,17 +34,51 @@ public TeamScore(Team team, Long score,Long level) { } public void updateScore(Long score) { + + int newStep = getStep(this.level, this.score + score); + this.score += score; + + if (this.score < 0) { // 점수 차감 / score down + level down + this.updateLevel(ScoreStatus.MINUS); + } + else { // 점수 획득. score up / score down + level up + + if ((40 + (newStep * 15L) <= this.score)) { // score down + level up + this.updateLevel(ScoreStatus.PLUS); + + } else { // score up +// this.score += score; + } + } + + } - public void updateLevel() { - final int[] steps = {1, 2, 25, 45, 70, 120}; + public int getStep(Long level, Long score) { + final int[] steps = {1, 2, 26, 46, 71, 121}; + + int index = 0; + for (int i = 5; i > 0; i--) { + if (steps[i-1] <= this.level && this.level < steps[i]) { + index=i-1; + break; + + } + } + return index; + + } + + public void updateLevel(ScoreStatus sign) { + final int[] steps = {1, 2, 26, 46, 71, 121}; + + this.level += sign.getValue(); for (int i = 5; i > 0; i--) { if (steps[i-1] <= this.level && this.level <= steps[i]) { - if ((40 + ((i-1) * 15)) <= score) { - this.level+=1; - this.score -= (40 + ((i-1) * 15)); + if ((40 + ((i-1) * 20)) <= score || score < 0) { + this.score -= sign.getValue() * (40 + ((i-1) * 20)); this.team.updateLevelOfFire(); return; } diff --git a/src/main/java/com/moing/backend/global/response/ErrorCode.java b/src/main/java/com/moing/backend/global/response/ErrorCode.java index 86c82168..4478309a 100644 --- a/src/main/java/com/moing/backend/global/response/ErrorCode.java +++ b/src/main/java/com/moing/backend/global/response/ErrorCode.java @@ -27,8 +27,8 @@ public enum ErrorCode { //미션 관련 에러코드 NO_ACCESS_CREATE_MISSION("M0001", "소모임장만 미션을 생성할 수 있습니다."), - NO_ACCESS_UPDATE_MISSION("M0001", "미션 생성자만 미션을 수정할 수 있습니다."), - NO_ACCESS_DELETE_MISSION("M0001", "미션 생성자만 미션을 삭제할 수 있습니다."), + NO_ACCESS_UPDATE_MISSION("M0001", "미션 생성자 또는 소모임장만 미션을 수정할 수 있습니다."), + NO_ACCESS_DELETE_MISSION("M0001", "미션 생성자 또는 소모임장만 미션을 삭제할 수 있습니다."), NOT_FOUND_MISSION("M0002", "미션을 찾을 수 없습니다."), NOT_FOUND_END_MISSION("M0003", "기한이 지난 미션을 찾을 수 없습니다."), NO_MORE_CREATE_MISSION("M0004", "반복미션은 2개까지 생성할 수 있습니다."),