Skip to content

Commit

Permalink
Merge pull request #10 from kjungw1025/feat/missionReject
Browse files Browse the repository at this point in the history
feat: 관리자에 의한 미션 인증 글 승인 거부에 대한 기능 추가
  • Loading branch information
kjungw1025 authored Mar 20, 2024
2 parents 2701d5f + 47afbe6 commit d659325
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public void acceptMission(AppAuthentication auth,
adminService.acceptMission(auth.getUserRole(), missionBoardId);
}

/**
* 미션 인증 글 승인 거부
*/
@PatchMapping("/reject/mission/{missionBoardId}")
@AdminAuth
public void rejectMission(AppAuthentication auth,
@PathVariable Long missionBoardId) {
adminService.rejectMission(auth.getUserRole(), missionBoardId);
}

/**
* 승인 완료된 글 취소
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.renew.sw.mentoring.domain.mission.repository.MissionRepository;
import com.renew.sw.mentoring.domain.post.exception.AlreadyMissionBoardAcceptedException;
import com.renew.sw.mentoring.domain.post.exception.MissionBoardNotAcceptedException;
import com.renew.sw.mentoring.domain.post.exception.MissionBoardNotInProgressException;
import com.renew.sw.mentoring.domain.post.exception.PostNotFoundException;
import com.renew.sw.mentoring.domain.post.model.entity.dto.list.SummarizedMissionBoardDto;
import com.renew.sw.mentoring.domain.post.model.entity.type.MissionBoard;
Expand Down Expand Up @@ -102,27 +103,50 @@ public void acceptMission(UserRole userRole, Long missionBoardId) {
throw new AlreadyMissionBoardAcceptedException();
}

Team team = missionBoard.getUser().getTeam();
Mission mission = missionRepository.findById(missionBoard.getMissionId()).orElseThrow(MissionNotFoundException::new);
if (missionBoard.isBonusMissionSuccessful()) {
BonusMission bonusMission = bonusMissionRepository.findAllByMissionId(mission.getId()).get(0);

int totalScore = mission.getPoint() + bonusMission.getPoint();
team.addScore(totalScore);
teamRepository.save(team);
if (missionBoard.getRegisterStatus().equals(IN_PROGRESS)) {
Team team = missionBoard.getUser().getTeam();
Mission mission = missionRepository.findById(missionBoard.getMissionId()).orElseThrow(MissionNotFoundException::new);
if (missionBoard.isBonusMissionSuccessful()) {
BonusMission bonusMission = bonusMissionRepository.findAllByMissionId(mission.getId()).get(0);

int totalScore = mission.getPoint() + bonusMission.getPoint();
team.addScore(totalScore);
teamRepository.save(team);
} else {
team.addScore(mission.getPoint());
teamRepository.save(team);
}
missionBoard.changeRegisterStatus(ACCEPTED);
missionBoardRepository.save(missionBoard);

CompletedMission completedMission = CompletedMission.builder()
.team(team)
.mission(mission)
.isBonusSuccess(missionBoard.isBonusMissionSuccessful())
.build();
completedMissionRepository.save(completedMission);
} else {
team.addScore(mission.getPoint());
teamRepository.save(team);
throw new MissionBoardNotInProgressException();
}
missionBoard.changeRegisterStatus(ACCEPTED);
missionBoardRepository.save(missionBoard);
}

CompletedMission completedMission = CompletedMission.builder()
.team(team)
.mission(mission)
.isBonusSuccess(missionBoard.isBonusMissionSuccessful())
.build();
completedMissionRepository.save(completedMission);
/**
* 미션 인증 글 승인 거부
*/
@Transactional
public void rejectMission(UserRole userRole, Long missionBoardId) {
if (!userRole.isAdmin()) {
throw new NotGrantedException();
}

MissionBoard missionBoard = missionBoardRepository.findById(missionBoardId).orElseThrow(PostNotFoundException::new);

if (missionBoard.getRegisterStatus().equals(IN_PROGRESS)) {
missionBoard.changeRegisterStatus(REJECTED);
missionBoardRepository.save(missionBoard);
} else {
throw new MissionBoardNotInProgressException();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.http.HttpStatus;

public class MissionBoardNotAcceptedException extends LocalizedMessageException {
public MissionBoardNotAcceptedException() { super(HttpStatus.BAD_REQUEST, "faild.missionBoard"); }
public MissionBoardNotAcceptedException() { super(HttpStatus.BAD_REQUEST, "failed.mission-board.accepted"); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.renew.sw.mentoring.domain.post.exception;

import com.renew.sw.mentoring.global.error.exception.LocalizedMessageException;
import org.springframework.http.HttpStatus;

public class MissionBoardNotInProgressException extends LocalizedMessageException {
public MissionBoardNotInProgressException() { super(HttpStatus.BAD_REQUEST, "failed.mission-board.in-progress"); }
}
3 changes: 2 additions & 1 deletion src/main/resources/errors.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ notfound.team=\uD574\uB2F9 \uD300\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\u
notfound.post=\uD574\uB2F9 \uAC8C\uC2DC\uAE00\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
notfound.mission=\uD574\uB2F9 \uBBF8\uC158\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.

faild.mission-board=\uC2B9\uC778\uC774 \uC644\uB8CC\uB41C \uC778\uC99D \uAE00\uC774 \uC544\uB2D9\uB2C8\uB2E4.
faild.mission-board.accepted=\uC2B9\uC778\uC774 \uC644\uB8CC\uB41C \uBBF8\uC158 \uC778\uC99D \uAE00\uC774 \uC544\uB2D9\uB2C8\uB2E4.
faild.mission-board.in-progress=\uC2B9\uC778 \uB300\uAE30 \uC911\uC778 \uBBF8\uC158 \uC778\uC99D \uAE00\uC774 \uC544\uB2D9\uB2C8\uB2E4.
3 changes: 2 additions & 1 deletion src/main/resources/errors_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ notfound.team=Cannot find that team.
notfound.post=Cannot find that post.
notfound.mission=Cannot find that mission.

faild.mission-board=This is not an accepted mission board.
failed.mission-board.accepted=This is not an accepted mission board.
failed.mission-board.in-progress=This post is not pending approval.

0 comments on commit d659325

Please sign in to comment.