From f21335f44a4d747c3ef898398ffa94349f8d2e71 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Wed, 20 Mar 2024 22:40:11 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EC=88=98?= =?UTF-8?q?=EB=9D=BD=EB=90=9C=20=EB=AF=B8=EC=85=98=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EA=B8=80=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/AlreadyMissionBoardAcceptedException.java | 8 ++++++++ src/main/resources/errors.properties | 1 + src/main/resources/errors_en_US.properties | 1 + 3 files changed, 10 insertions(+) create mode 100644 src/main/java/com/renew/sw/mentoring/domain/post/exception/AlreadyMissionBoardAcceptedException.java diff --git a/src/main/java/com/renew/sw/mentoring/domain/post/exception/AlreadyMissionBoardAcceptedException.java b/src/main/java/com/renew/sw/mentoring/domain/post/exception/AlreadyMissionBoardAcceptedException.java new file mode 100644 index 0000000..e0703f7 --- /dev/null +++ b/src/main/java/com/renew/sw/mentoring/domain/post/exception/AlreadyMissionBoardAcceptedException.java @@ -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"); } +} diff --git a/src/main/resources/errors.properties b/src/main/resources/errors.properties index fc17cd3..616e59e 100644 --- a/src/main/resources/errors.properties +++ b/src/main/resources/errors.properties @@ -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. diff --git a/src/main/resources/errors_en_US.properties b/src/main/resources/errors_en_US.properties index 85d4bad..09b6377 100644 --- a/src/main/resources/errors_en_US.properties +++ b/src/main/resources/errors_en_US.properties @@ -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. From fdba54c09462e5dab400126baab71c987622590a Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Wed, 20 Mar 2024 22:40:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EA=B4=80=EB=A6=AC=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EA=B8=80=20=EC=8A=B9=EC=9D=B8=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminController.java | 10 +++++ .../domain/admin/service/AdminService.java | 42 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/main/java/com/renew/sw/mentoring/domain/admin/controller/AdminController.java b/src/main/java/com/renew/sw/mentoring/domain/admin/controller/AdminController.java index 3cbf3bb..507ed76 100644 --- a/src/main/java/com/renew/sw/mentoring/domain/admin/controller/AdminController.java +++ b/src/main/java/com/renew/sw/mentoring/domain/admin/controller/AdminController.java @@ -70,6 +70,16 @@ public ResponsePage unapprovedList(AppAuthentication return new ResponsePage<>(unapprovedList); } + /** + * 미션 인증 글 승인 + */ + @PatchMapping("/accept/mission/{missionBoardId}") + @AdminAuth + public void acceptMission(AppAuthentication auth, + @PathVariable Long missionBoardId) { + adminService.acceptMission(auth.getUserRole(), missionBoardId); + } + /** * 승인 완료된 글 취소 */ diff --git a/src/main/java/com/renew/sw/mentoring/domain/admin/service/AdminService.java b/src/main/java/com/renew/sw/mentoring/domain/admin/service/AdminService.java index f58828b..4019a0e 100644 --- a/src/main/java/com/renew/sw/mentoring/domain/admin/service/AdminService.java +++ b/src/main/java/com/renew/sw/mentoring/domain/admin/service/AdminService.java @@ -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; @@ -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); + } + /** * 승인 완료된 글 취소 */ @@ -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);