Skip to content

Commit

Permalink
Merge pull request #48 from SUIN-BUNDANG-LINE/SBL-94-invalid-access-v…
Browse files Browse the repository at this point in the history
…alidation

[SBL-94] 유효하지 않은 접근을 할 경우 예외를 발생시키도록 구현
  • Loading branch information
JeongHunHui authored Aug 13, 2024
2 parents e95c574 + bc02576 commit b081e4d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sbl.sulmun2yong.drawing.exception

import com.sbl.sulmun2yong.global.error.BusinessException
import com.sbl.sulmun2yong.global.error.ErrorCode

class InvalidDrawingBoardAccessException : BusinessException(ErrorCode.INVALID_DRAWING_BOARD_ACCESS)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.sbl.sulmun2yong.drawing.dto.response.DrawingBoardResponse
import com.sbl.sulmun2yong.drawing.dto.response.DrawingResultResponse
import com.sbl.sulmun2yong.drawing.exception.AlreadyParticipatedDrawingException
import com.sbl.sulmun2yong.drawing.exception.FinishedDrawingException
import com.sbl.sulmun2yong.drawing.exception.InvalidDrawingBoardAccessException
import com.sbl.sulmun2yong.global.data.PhoneNumber
import com.sbl.sulmun2yong.survey.adapter.ParticipantAdapter
import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter
Expand All @@ -28,6 +29,11 @@ class DrawingBoardService(
private val drawingHistoryAdapter: DrawingHistoryAdapter,
) {
fun getDrawingBoard(surveyId: UUID): DrawingBoardResponse {
val surveyStatus = surveyAdapter.getSurvey(surveyId).status
// 설문이 시작되지 않았거나, 종료된 경우 접근 불가
if (surveyStatus == SurveyStatus.NOT_STARTED || surveyStatus == SurveyStatus.CLOSED) {
throw InvalidDrawingBoardAccessException()
}
val drawingBoard = drawingBoardAdapter.getBySurveyId(surveyId)
return DrawingBoardResponse.of(drawingBoard)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum class ErrorCode(
INVALID_REWARD(HttpStatus.BAD_REQUEST, "SV0011", "유효하지 않은 리워드 정보 입니다."),
INVALID_PARTICIPANT(HttpStatus.BAD_REQUEST, "SV0012", "유효하지 않은 참여자입니다."),
INVALID_SECTION_IDS(HttpStatus.BAD_REQUEST, "SV0013", "유효하지 않은 섹션 ID입니다."),
SURVEY_CLOSED(HttpStatus.BAD_REQUEST, "SV0014", "이미 마감된 설문입니다."),
SURVEY_CLOSED(HttpStatus.BAD_REQUEST, "SV0014", "응답을 받지 않는 설문입니다."),
INVALID_UPDATE_SURVEY(HttpStatus.BAD_REQUEST, "SV0015", "설문 정보 갱신에 실패했습니다."),
INVALID_SURVEY_ACCESS(HttpStatus.FORBIDDEN, "SV0016", "설문 접근 권한이 없습니다."),
ALREADY_PARTICIPATED(HttpStatus.BAD_REQUEST, "SV0017", "이미 참여한 설문입니다."),
Expand All @@ -38,6 +38,7 @@ enum class ErrorCode(
ALREADY_PARTICIPATED_DRAWING(HttpStatus.BAD_REQUEST, "DR0005", "이미 참여한 추첨입니다."),
FINISHED_DRAWING(HttpStatus.BAD_REQUEST, "DR0005", "이미 마감된 추첨입니다."),
INVALID_DRAWING_HISTORY(HttpStatus.BAD_REQUEST, "DR0006", "유효하지 않은 추첨 기록입니다."),
INVALID_DRAWING_BOARD_ACCESS(HttpStatus.BAD_REQUEST, "DR0007", "이미 종료되었거나, 접근할 수 없는 설문입니다."),

// OAuth2 (OA)
PROVIDER_NOT_FOUND(HttpStatus.NOT_FOUND, "OA0001", "지원하지 않는 소셜 로그인입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.sbl.sulmun2yong.survey.service

import com.sbl.sulmun2yong.drawing.adapter.DrawingBoardAdapter
import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter
import com.sbl.sulmun2yong.survey.domain.SurveyStatus
import com.sbl.sulmun2yong.survey.dto.request.SurveySortType
import com.sbl.sulmun2yong.survey.dto.response.SurveyInfoResponse
import com.sbl.sulmun2yong.survey.dto.response.SurveyListResponse
import com.sbl.sulmun2yong.survey.dto.response.SurveyProgressInfoResponse
import com.sbl.sulmun2yong.survey.exception.InvalidSurveyAccessException
import org.springframework.stereotype.Service
import java.util.UUID

Expand All @@ -32,12 +34,14 @@ class SurveyInfoService(

fun getSurveyInfo(surveyId: UUID): SurveyInfoResponse {
val survey = surveyAdapter.getSurvey(surveyId)
if (survey.status == SurveyStatus.NOT_STARTED) throw InvalidSurveyAccessException()
val drawingBoard = drawingBoardAdapter.getBySurveyId(surveyId)
return SurveyInfoResponse.of(survey, drawingBoard.selectedTicketCount)
}

fun getSurveyProgressInfo(surveyId: UUID): SurveyProgressInfoResponse? {
val survey = surveyAdapter.getSurvey(surveyId)
if (survey.status != SurveyStatus.IN_PROGRESS) throw InvalidSurveyAccessException()
return SurveyProgressInfoResponse.of(survey)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SurveyResponseService(
}

val survey = surveyAdapter.getSurvey(surveyId)
if (survey.status == SurveyStatus.CLOSED) {
if (survey.status != SurveyStatus.IN_PROGRESS) {
throw SurveyClosedException()
}
val surveyResponse = surveyResponseRequest.toDomain(surveyId)
Expand Down

0 comments on commit b081e4d

Please sign in to comment.