diff --git a/src/main/java/com/m9d/sroom/common/error/DuplicationException.java b/src/main/java/com/m9d/sroom/common/error/DuplicationException.java index d50591aa..3ea57b25 100644 --- a/src/main/java/com/m9d/sroom/common/error/DuplicationException.java +++ b/src/main/java/com/m9d/sroom/common/error/DuplicationException.java @@ -6,7 +6,7 @@ @Getter public abstract class DuplicationException extends RuntimeException { - private final int statusCode = HttpStatus.NOT_FOUND.value(); + private final int statusCode = HttpStatus.BAD_REQUEST.value(); private String message; public DuplicationException(String message) { diff --git a/src/main/java/com/m9d/sroom/common/error/NotMatchException.java b/src/main/java/com/m9d/sroom/common/error/NotMatchException.java index 372bf200..88793788 100644 --- a/src/main/java/com/m9d/sroom/common/error/NotMatchException.java +++ b/src/main/java/com/m9d/sroom/common/error/NotMatchException.java @@ -7,7 +7,7 @@ @Getter public abstract class NotMatchException extends RuntimeException { - private final int statusCode = HttpStatus.NOT_FOUND.value(); + private final int statusCode = HttpStatus.BAD_REQUEST.value(); private String message; public NotMatchException(String message) { diff --git a/src/main/java/com/m9d/sroom/material/FeedbackService.java b/src/main/java/com/m9d/sroom/material/FeedbackService.java index c9ef9846..2bb166be 100644 --- a/src/main/java/com/m9d/sroom/material/FeedbackService.java +++ b/src/main/java/com/m9d/sroom/material/FeedbackService.java @@ -1,12 +1,12 @@ package com.m9d.sroom.material; import com.m9d.sroom.common.entity.MaterialFeedbackEntity; -import com.m9d.sroom.common.entity.QuizEntity; -import com.m9d.sroom.common.entity.SummaryEntity; import com.m9d.sroom.common.repository.materialfeedback.MaterialFeedbackRepository; import com.m9d.sroom.common.repository.quiz.QuizRepository; import com.m9d.sroom.common.repository.summary.SummaryRepository; import com.m9d.sroom.material.dto.response.FeedbackInfo; +import com.m9d.sroom.material.exception.FeedbackUnavailableException; +import com.m9d.sroom.material.exception.MaterialFeedbackDuplicateException; import com.m9d.sroom.material.exception.QuizNotFoundException; import com.m9d.sroom.material.exception.SummaryNotFoundException; import com.m9d.sroom.material.model.MaterialType; @@ -34,15 +34,17 @@ public FeedbackInfo feedback(Long memberId, MaterialType materialType, Long mate boolean satisfactory) { FeedbackInfo feedbackInfo = getFeedbackInfo(memberId, materialType, materialId); - if (feedbackInfo.isHasFeedback() || !available) { - feedbackInfo.setAvailable(false); - return feedbackInfo; + if (feedbackInfo.isHasFeedback()) { + throw new MaterialFeedbackDuplicateException(); + } else if (!available) { + throw new FeedbackUnavailableException(); } else { MaterialFeedbackEntity feedbackEntity = feedbackRepository.save( MaterialFeedbackEntity.createForSave(memberId, materialType, materialId, satisfactory)); updateFeedbackCount(materialType, materialId, satisfactory); return FeedbackInfo.createSubmittedInfo(feedbackEntity); } + } public FeedbackInfo getFeedbackInfo(Long memberId, MaterialType materialType, Long materialId) { diff --git a/src/main/java/com/m9d/sroom/material/exception/FeedbackUnavailableException.java b/src/main/java/com/m9d/sroom/material/exception/FeedbackUnavailableException.java new file mode 100644 index 00000000..be209bdb --- /dev/null +++ b/src/main/java/com/m9d/sroom/material/exception/FeedbackUnavailableException.java @@ -0,0 +1,12 @@ +package com.m9d.sroom.material.exception; + +import com.m9d.sroom.common.error.NotMatchException; + +public class FeedbackUnavailableException extends NotMatchException { + + private static final String MESSAGE = "수정된 요약본은 사용자 피드백이 불가합니다."; + + public FeedbackUnavailableException() { + super(MESSAGE); + } +} diff --git a/src/main/java/com/m9d/sroom/material/exception/MaterialFeedbackDuplicateException.java b/src/main/java/com/m9d/sroom/material/exception/MaterialFeedbackDuplicateException.java new file mode 100644 index 00000000..5373ae0f --- /dev/null +++ b/src/main/java/com/m9d/sroom/material/exception/MaterialFeedbackDuplicateException.java @@ -0,0 +1,12 @@ +package com.m9d.sroom.material.exception; + +import com.m9d.sroom.common.error.DuplicationException; + +public class MaterialFeedbackDuplicateException extends DuplicationException { + + private static final String MESSAGE = "이미 피드백된 강의자료입니다."; + + public MaterialFeedbackDuplicateException() { + super(MESSAGE); + } +}