Skip to content

Commit

Permalink
Merge pull request #69 from gutanbug/dev
Browse files Browse the repository at this point in the history
�feat #65 : 관리자를 통한 미션 인증글 승인 기능 추가
  • Loading branch information
kjungw1025 authored Mar 20, 2024
2 parents a2dc2ed + 261b62c commit 2701d5f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public ResponsePage<SummarizedMissionBoardDto> unapprovedList(AppAuthentication
return new ResponsePage<>(unapprovedList);
}

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

/**
* 승인 완료된 글 취소
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.renew.sw.mentoring.domain.admin.exception.AlreadyStudentIdException;
import com.renew.sw.mentoring.domain.admin.request.RequestCreateAdminDto;
import com.renew.sw.mentoring.domain.completedmission.model.entity.CompletedMission;
import com.renew.sw.mentoring.domain.completedmission.repository.CompletedMissionRepository;
import com.renew.sw.mentoring.domain.mission.exception.MissionNotFoundException;
import com.renew.sw.mentoring.domain.mission.model.entity.BonusMission;
import com.renew.sw.mentoring.domain.mission.model.entity.Mission;
import com.renew.sw.mentoring.domain.mission.repository.BonusMissionRepository;
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.PostNotFoundException;
import com.renew.sw.mentoring.domain.post.model.entity.dto.list.SummarizedMissionBoardDto;
Expand Down Expand Up @@ -85,6 +87,44 @@ public void createAdmin(RequestCreateAdminDto dto) {
}
}

/**
* 미션 인증 글 승인
*/
@Transactional
public void acceptMission(UserRole userRole, Long missionBoardId) {
if (!userRole.isAdmin()) {
throw new NotGrantedException();
}

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

if (missionBoard.getRegisterStatus().equals(ACCEPTED)) {
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);
} 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);
}

/**
* 승인 완료된 글 취소
*/
Expand All @@ -107,8 +147,10 @@ public void cancelMission(UserRole userRole, Long missionBoardId) {

int totalScore = mission.getPoint() + bonusMission.getPoint();
team.addScore(-totalScore);
teamRepository.save(team);
} else {
team.addScore(-mission.getPoint());
teamRepository.save(team);
}
missionBoard.changeRegisterStatus(REJECTED);
missionBoardRepository.save(missionBoard);
Expand Down
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 AlreadyMissionBoardAcceptedException extends LocalizedMessageException {
public AlreadyMissionBoardAcceptedException() { super(HttpStatus.BAD_REQUEST, "already.mission-board.accepted"); }
}
1 change: 1 addition & 0 deletions src/main/resources/errors.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ unexpected=\uC608\uAE30\uCE58 \uBABB\uD55C \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588
already.nickname=\uC774\uBBF8 \uC0AC\uC6A9\uC911\uC778 \uB2C9\uB124\uC784\uC785\uB2C8\uB2E4.
already.team=\uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uD300\uC785\uB2C8\uB2E4.
already.student.id=\uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uD559\uBC88\uC785\uB2C8\uB2E4.
already.mission-board.accepted=\uC774\uBBF8 \uC2B9\uC778\uB41C \uBBF8\uC158 \uC778\uC99D \uAE00\uC785\uB2C8\uB2E4.

notfound.user=\uD574\uB2F9 \uC720\uC800\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
notfound.team=\uD574\uB2F9 \uD300\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/errors_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ unexpected=An unexpected error occurred.
already.nickname=The nickname is already in use.
already.team=The team already exists.
already.student.id=The student ID is already in use.
already.mission-board.accepted=This is a mission certificated post that has already been approved.

notfound.user=Cannot find that user.
notfound.team=Cannot find that team.
Expand Down

0 comments on commit 2701d5f

Please sign in to comment.