Skip to content

Commit

Permalink
Merge pull request #250 from Modagbul/main
Browse files Browse the repository at this point in the history
  • Loading branch information
seungueonn authored Feb 14, 2024
2 parents 06740bd + 50f37b8 commit f66be44
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +49,8 @@ public class MissionArchiveDeleteUseCase {
private final MissionStateDeleteService missionStateDeleteService;
private final MissionStateQueryService missionStateQueryService;

private final TeamScoreUpdateUseCase teamScoreUpdateUseCase;

private final UpdateUtils updateUtils;


Expand All @@ -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();
Expand All @@ -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();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -42,15 +44,11 @@ public List<MissionArchive> findMyArchive(Long memberId, Long missionId) {
return optional.get();
}
}
public List<MissionArchive> findOneMyArchive(Long memberId, Long missionId, Long count) {
public MissionArchive findOneMyArchive(Long memberId, Long missionId, Long count) {

Optional<List<MissionArchive>> optional = missionArchiveRepository.findMyArchives(memberId, missionId);
List<MissionArchive> 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<MissionArchive> findOthersArchive(Long memberId, Long missionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +28,7 @@ public class TeamScoreUpdateUseCase {
/**
* 매번 미션 인증 시 점수 적립
*/
public void gainScoreOfArchive(Mission mission) {
public void gainScoreOfArchive(Mission mission, ScoreStatus scoreStatus) {


Team team = mission.getTeam();
Expand All @@ -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());

}

Expand Down Expand Up @@ -68,7 +68,6 @@ public void gainScoreOfBonus(Mission mission) {
} else {
teamScore.updateScore(BONUS_SCORE_REPEAT_MISSION);
}
teamScore.updateLevel();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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개까지 생성할 수 있습니다."),
Expand Down

0 comments on commit f66be44

Please sign in to comment.