Skip to content

Commit

Permalink
Merge pull request #92 from gutanbug/dev
Browse files Browse the repository at this point in the history
fix : 미션 인증글에 보너스 미션 인증 여부 true 일 때, 없으면 오류 터지게끔 수정
  • Loading branch information
gutanbug authored Apr 8, 2024
2 parents 0675154 + f1faf51 commit 432d198
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.renew.sw.mentoring.domain.mission.exception;

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

public class BonusMissionNotFoundException extends LocalizedMessageException {

public BonusMissionNotFoundException() {
super(HttpStatus.NOT_FOUND, "notfound.bonusMission");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface BonusMissionRepository extends JpaRepository<BonusMission, Long> {

@Query("select bm from BonusMission bm where bm.mission.id = :missionId")
List<BonusMission> findAllByMissionId(@Param("missionId") Long missionId);


@Query("select bm from BonusMission bm where bm.mission.id = :missionId ")
Optional<BonusMission> findByMissionId(@Param("missionId") Long missionId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.renew.sw.mentoring.domain.post.service;

import com.renew.sw.mentoring.domain.completedmission.repository.CompletedMissionRepository;
import com.renew.sw.mentoring.domain.mission.exception.BonusMissionNotFoundException;
import com.renew.sw.mentoring.domain.mission.exception.MissionNotFoundException;
import com.renew.sw.mentoring.domain.mission.repository.BonusMissionRepository;
import com.renew.sw.mentoring.domain.post.exception.AlreadyMissionBoardAcceptedException;
import com.renew.sw.mentoring.domain.post.exception.AlreadyMissionBoardException;
import com.renew.sw.mentoring.domain.post.exception.PostNotFoundException;
Expand Down Expand Up @@ -40,12 +42,15 @@ public class MissionBoardService {
private final UserRepository userRepository;
private final TeamRepository teamRepository;
private final CompletedMissionRepository completedMissionRepository;
private final BonusMissionRepository bonusMissionRepository;

public Long create(Long userId, RequestCreateMissionBoardDto dto) {
Team team = teamRepository.findByUserId(userId).orElseThrow(TeamNotFoundException::new);
if (completedMissionRepository.existsByTeamIdAndMissionId(team.getId(), dto.getMissionId()).isPresent() ||
repository.findByMissionIdAndUserId(dto.getMissionId(), userId).isPresent()) {
throw new AlreadyMissionBoardException();
} else if (dto.getIsBonusMissionSuccessful() && bonusMissionRepository.findByMissionId(dto.getMissionId()).isEmpty()) {
throw new BonusMissionNotFoundException();
}
return postService.create(repository, userId, dto);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/errors.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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.
notfound.comment=\uD574\uB2F9 \uB313\uAE00\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
notfound.bonusMission=\uD574\uB2F9 \uBCF4\uB108\uC2A4 \uBBF8\uC158\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\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.
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 @@ -24,6 +24,7 @@ notfound.team=Cannot find that team.
notfound.post=Cannot find that post.
notfound.mission=Cannot find that mission.
notfound.comment=Cannot find that comment.
notfound.bonusMission=Cannot find that bonus mission.

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 432d198

Please sign in to comment.