From d61e980f7997a4dbcdce9e04c59bc035cc950e38 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Mon, 4 Dec 2023 20:00:18 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20custom=20exception=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/NotFoundMemberException.java | 11 ----------- .../application/exception/OverDateException.java | 11 ----------- 2 files changed, 22 deletions(-) delete mode 100644 BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundMemberException.java delete mode 100644 BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/OverDateException.java diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundMemberException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundMemberException.java deleted file mode 100644 index 2cf927c4..00000000 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundMemberException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.blackcompany.eeos.attend.application.exception; - -import com.blackcompany.eeos.common.exception.BusinessException; -import org.springframework.http.HttpStatus; - -public class NotFoundMemberException extends BusinessException { - - public NotFoundMemberException(String message) { - super(message, HttpStatus.NOT_FOUND); - } -} diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/OverDateException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/OverDateException.java deleted file mode 100644 index fb77906d..00000000 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/OverDateException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.blackcompany.eeos.program.application.exception; - -import com.blackcompany.eeos.common.exception.BusinessException; -import org.springframework.http.HttpStatus; - -public class OverDateException extends BusinessException { - - public OverDateException(String message) { - super(message, HttpStatus.BAD_REQUEST); - } -} From 39be3ef5302eb9a3b1c5dcf1de74079c7b468166 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Mon, 4 Dec 2023 20:01:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat=20:=20=EA=B3=B5=ED=86=B5=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20response=EC=97=90=20custom=20error=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eeos/common/exception/BusinessException.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/BusinessException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/BusinessException.java index edad0f02..55643f10 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/BusinessException.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/BusinessException.java @@ -5,10 +5,11 @@ @Getter public class BusinessException extends RuntimeException { + private final String code; private final HttpStatus httpStatus; - public BusinessException(String message, HttpStatus httpStatus) { - super(message); + public BusinessException(String code, HttpStatus httpStatus) { + this.code = code; this.httpStatus = httpStatus; } } From 5df46f2bdc966b92beddd0f1502b08b082d67b35 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Mon, 4 Dec 2023 20:02:11 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat=20:=20=EC=B6=94=EA=B0=80=EB=90=9C=20cu?= =?UTF-8?q?stom=20error=20code=EC=97=90=20=EB=A7=9E=EA=B2=8C=20responseGen?= =?UTF-8?q?erator=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/GlobalExceptionHandler.java | 15 +++++++++------ .../presentation/respnose/ApiResponseBody.java | 1 + .../respnose/ApiResponseGenerator.java | 15 +++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/GlobalExceptionHandler.java b/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/GlobalExceptionHandler.java index 3e691b03..34354e82 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/GlobalExceptionHandler.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/common/exception/GlobalExceptionHandler.java @@ -15,12 +15,13 @@ @Slf4j @RestControllerAdvice public class GlobalExceptionHandler { + private static final String FAIL_CODE = "fail"; /** javax.validation.Valid 또는 @Validated binding error가 발생할 경우 */ @ExceptionHandler(BindException.class) protected ApiResponse handleBindException(BindException e) { log.error("handleBindException", e); - return ApiResponseGenerator.fail(e.getBindingResult(), HttpStatus.BAD_REQUEST); + return ApiResponseGenerator.fail(e.getBindingResult(), FAIL_CODE, HttpStatus.BAD_REQUEST); } /** 주로 @RequestParam enum으로 binding 못했을 경우 발생 */ @@ -28,7 +29,7 @@ protected ApiResponse handleBindException(BindException e) { protected ApiResponse handleMethodArgumentTypeMismatchException( MethodArgumentTypeMismatchException e) { log.error("handleMethodArgumentTypeMismatchException", e); - return ApiResponseGenerator.fail(e.getMessage(), HttpStatus.BAD_REQUEST); + return ApiResponseGenerator.fail(e.getMessage(), FAIL_CODE, HttpStatus.BAD_REQUEST); } /** 지원하지 않은 HTTP method 호출 할 경우 발생 */ @@ -36,27 +37,29 @@ protected ApiResponse handleMethodArgumentTypeMismatchException( protected ApiResponse handleHttpRequestMethodNotSupportedException( HttpRequestMethodNotSupportedException e) { log.error("handleHttpRequestMethodNotSupportedException", e); - return ApiResponseGenerator.fail(e.getMessage(), HttpStatus.METHOD_NOT_ALLOWED); + return ApiResponseGenerator.fail(e.getMessage(), FAIL_CODE, HttpStatus.METHOD_NOT_ALLOWED); } /** 비즈니스 로직 실행 중 오류 발생 */ @ExceptionHandler(value = {BusinessException.class}) protected ApiResponse handleConflict(BusinessException e) { log.error("BusinessException", e); - return ApiResponseGenerator.fail(e.getMessage(), e.getHttpStatus()); + return ApiResponseGenerator.fail(e.getMessage(), e.getCode(), e.getHttpStatus()); } /** 나머지 예외 발생 */ @ExceptionHandler(Exception.class) protected ApiResponse handleException(Exception e) { log.error("Exception", e); - return ApiResponseGenerator.fail(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + return ApiResponseGenerator.fail(e.getMessage(), FAIL_CODE, HttpStatus.INTERNAL_SERVER_ERROR); } @ExceptionHandler({MethodArgumentNotValidException.class}) protected ApiResponse handleMethodArgumentNotValidException( MethodArgumentNotValidException e) { return ApiResponseGenerator.fail( - e.getBindingResult().getFieldErrors().get(0).getDefaultMessage(), HttpStatus.BAD_REQUEST); + e.getBindingResult().getFieldErrors().get(0).getDefaultMessage(), + FAIL_CODE, + HttpStatus.BAD_REQUEST); } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseBody.java b/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseBody.java index 65cab509..be4cb422 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseBody.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseBody.java @@ -9,6 +9,7 @@ public class ApiResponseBody { @AllArgsConstructor public static class FailureBody implements Serializable { + private String status; private String code; private String message; } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseGenerator.java b/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseGenerator.java index 29bb9da2..fed6c7a4 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseGenerator.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/common/presentation/respnose/ApiResponseGenerator.java @@ -47,22 +47,21 @@ public static ApiResponse fail( } public static ApiResponse fail( - final String message, final HttpStatus status) { + final String message, final String code, final HttpStatus httpStatus) { return new ApiResponse<>( - new ApiResponseBody.FailureBody(String.valueOf(status.value()), message), status); + new ApiResponseBody.FailureBody(httpStatus.name(), code, message), httpStatus); } public static ApiResponse fail( - final String code, final String message, final HttpStatus status) { - return new ApiResponse<>(new ApiResponseBody.FailureBody(code, message), status); + final String status, final String code, final String message, final HttpStatus httpStatus) { + return new ApiResponse<>(new ApiResponseBody.FailureBody(status, code, message), httpStatus); } public static ApiResponse fail( - BindingResult bindingResult, final HttpStatus status) { + BindingResult bindingResult, final String code, final HttpStatus httpStatus) { return new ApiResponse<>( - new ApiResponseBody.FailureBody( - String.valueOf(status.value()), createErrorMessage(bindingResult)), - status); + new ApiResponseBody.FailureBody(httpStatus.name(), code, createErrorMessage(bindingResult)), + httpStatus); } private static String createErrorMessage(BindingResult bindingResult) { From 9b008960458a97d51dbabd1faec3d7e31a016fa4 Mon Sep 17 00:00:00 2001 From: kssumin <201566@jnu.ac.kr> Date: Mon, 4 Dec 2023 20:19:34 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor=20:=20=EB=B3=80=EA=B2=BD=EB=90=9C?= =?UTF-8?q?=20=EC=8B=A4=ED=8C=A8=20=EC=9D=91=EB=8B=B5=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20custom=20exception=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/NotFoundAttendException.java | 17 +++- .../NotFoundAttendStatusException.java | 23 +++++ .../exception/NotFoundStatusException.java | 11 --- .../NotSameBeforeAttendStatusException.java | 22 +++++ .../application/model/AttendStatus.java | 41 ++++----- .../application/service/AttendService.java | 87 ++++++++++--------- .../application/service/MemberService.java | 11 --- .../application/domain/ProgramStatus.java | 4 +- .../exception/NotFoundProgramException.java | 17 +++- .../application/service/ProgramService.java | 2 +- .../service/ProgramValidService.java | 2 +- 11 files changed, 142 insertions(+), 95 deletions(-) create mode 100644 BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendStatusException.java delete mode 100644 BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundStatusException.java create mode 100644 BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotSameBeforeAttendStatusException.java diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendException.java index 3c5390e2..f0860d95 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendException.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendException.java @@ -3,9 +3,20 @@ import com.blackcompany.eeos.common.exception.BusinessException; import org.springframework.http.HttpStatus; +/** + * 존재하지 않는 참석 정보일 때 발생하는 예외 + */ public class NotFoundAttendException extends BusinessException { + private static final String FAIL_CODE = "2004"; + private final Long programId; - public NotFoundAttendException() { - super("존재하지 않는 참석 정보입니다.", HttpStatus.NOT_FOUND); - } + public NotFoundAttendException(Long programId) { + super(FAIL_CODE, HttpStatus.NOT_FOUND); + this.programId = programId; + } + + @Override + public String getMessage() { + return String.format("%s 프로그램에 대한 참여 정보가 없습니다.", programId); + } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendStatusException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendStatusException.java new file mode 100644 index 00000000..76a3dc13 --- /dev/null +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundAttendStatusException.java @@ -0,0 +1,23 @@ +package com.blackcompany.eeos.attend.application.exception; + +import com.blackcompany.eeos.common.exception.BusinessException; +import org.springframework.http.HttpStatus; + +/** + * 존재하지 않는 참석 상태일 때 발생하는 예외 + */ +public class NotFoundAttendStatusException extends BusinessException { + private static final String FAIL_CODE = "2000"; + private final String attendStatus; + + public NotFoundAttendStatusException(String attendStatus) { + super(FAIL_CODE, HttpStatus.NOT_FOUND); + this.attendStatus = attendStatus; + } + + @Override + public String getMessage() { + return String.format("%s 참석 상태는 존재하지 않습니다.", attendStatus); + } + +} diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundStatusException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundStatusException.java deleted file mode 100644 index f4bad995..00000000 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotFoundStatusException.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.blackcompany.eeos.attend.application.exception; - -import com.blackcompany.eeos.common.exception.BusinessException; -import org.springframework.http.HttpStatus; - -public class NotFoundStatusException extends BusinessException { - - public NotFoundStatusException() { - super("존재하지 않는 상태입니다.", HttpStatus.NOT_FOUND); - } -} diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotSameBeforeAttendStatusException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotSameBeforeAttendStatusException.java new file mode 100644 index 00000000..0a7ceb20 --- /dev/null +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/exception/NotSameBeforeAttendStatusException.java @@ -0,0 +1,22 @@ +package com.blackcompany.eeos.attend.application.exception; + +import com.blackcompany.eeos.common.exception.BusinessException; +import org.springframework.http.HttpStatus; +/** + * 이전 참석상태가 일치하지 않을 때 발생하는 예외 + */ +public class NotSameBeforeAttendStatusException extends BusinessException { + private static final String FAIL_CODE = "2001"; + private final Long memberId; + + public NotSameBeforeAttendStatusException(Long memberId) { + super(FAIL_CODE, HttpStatus.NOT_FOUND); + this.memberId = memberId; + } + + @Override + public String getMessage() { + return String.format("%s 회원의 이전 상태가 올바르지 않습니다.", memberId); + } + +} diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/model/AttendStatus.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/model/AttendStatus.java index 5828f300..032f9b98 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/model/AttendStatus.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/model/AttendStatus.java @@ -1,31 +1,32 @@ package com.blackcompany.eeos.attend.application.model; -import com.blackcompany.eeos.attend.application.exception.NotFoundStatusException; +import com.blackcompany.eeos.attend.application.exception.NotFoundAttendStatusException; import java.util.Arrays; +import lombok.Getter; public enum AttendStatus { - ATTEND("attend"), - ABSENT("absent"), - NONE("none"); + ATTEND("attend"), + ABSENT("absent"), + NONE("none"); - private final String status; + private final String status; - AttendStatus(String status) { - this.status = status; - } + AttendStatus(String status) { + this.status = status; + } - public String getStatus() { - return status; - } + public String getStatus() { + return status; + } - public static AttendStatus findByAttendStatus(String status) { - return Arrays.stream(AttendStatus.values()) - .filter(attendStatus -> attendStatus.getStatus().equals(status)) - .findAny() - .orElseThrow(NotFoundStatusException::new); - } + public static AttendStatus findByAttendStatus(String status) { + return Arrays.stream(AttendStatus.values()) + .filter(attendStatus -> attendStatus.getStatus().equals(status)) + .findAny() + .orElseThrow(() -> new NotFoundAttendStatusException(status)); + } - public static boolean isSameAttendStatus(String source, AttendStatus actualStatus) { - return actualStatus.getStatus().equals(source); - } + public static boolean isSameAttendStatus(String source, AttendStatus actualStatus) { + return actualStatus.getStatus().equals(source); + } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/service/AttendService.java b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/service/AttendService.java index 74ccd8e7..7e2c4dec 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/service/AttendService.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/service/AttendService.java @@ -11,6 +11,7 @@ import com.blackcompany.eeos.attend.application.usecase.GetAttendantInfoUsecase; import com.blackcompany.eeos.attend.persistence.AttendEntity; import com.blackcompany.eeos.attend.persistence.AttendRepository; +import com.blackcompany.eeos.member.persistence.MemberEntity; import com.blackcompany.eeos.member.persistence.MemberRepository; import com.blackcompany.eeos.program.application.service.ProgramValidService; import java.util.List; @@ -24,58 +25,58 @@ @Transactional(readOnly = true) public class AttendService implements GetAttendantInfoUsecase, ChangeStatusUsecase { - private final AttendRepository attendRepository; + private final AttendRepository attendRepository; - private final MemberRepository memberRepository; - private final ProgramValidService programValidService; - private final AttendInfoConverter infoConverter; - private final AttendEntityConverter attendEntityConverter; + private final MemberRepository memberRepository; + private final ProgramValidService programValidService; + private final AttendInfoConverter infoConverter; + private final AttendEntityConverter attendEntityConverter; - @Override - public List findAttendInfo(final Long programId) { - programValidService.validate(programId); + @Override + public List findAttendInfo(final Long programId) { + programValidService.validate(programId); - return memberRepository.findMembersByProgramId(programId).stream() - .map(member -> infoConverter.from(member, getAttendStatus(member.getId(), programId))) - .collect(Collectors.toList()); - } + return memberRepository.findMembersByProgramId(programId).stream() + .map(member -> infoConverter.from(member, getAttend(member, programId))) + .collect(Collectors.toList()); + } - private AttendStatus getAttendStatus(final Long memberId, final Long programId) { - return attendRepository - .findByProgramIdAndMemberId(programId, memberId) - .map(AttendEntity::getStatus) - .orElseThrow(NotFoundAttendException::new); - } + private AttendStatus getAttend(final MemberEntity memberEntity, final Long programId) { + return attendRepository + .findByProgramIdAndMemberId(programId, memberEntity.getId()) + .map(AttendEntity::getStatus) + .orElseThrow(() -> new NotFoundAttendException(programId)); + } - @Override - public List findAttendInfo(final Long programId, final String status) { - programValidService.validate(programId); + @Override + public List findAttendInfo(final Long programId, final String status) { + programValidService.validate(programId); - AttendStatus attendStatus = AttendStatus.findByAttendStatus(status); + AttendStatus attendStatus = AttendStatus.findByAttendStatus(status); - List statusMember = - attendRepository.findAllByProgramIdAndStatus(programId, attendStatus).stream() - .map(AttendEntity::getMemberId) - .collect(Collectors.toList()); + List statusMember = + attendRepository.findAllByProgramIdAndStatus(programId, attendStatus).stream() + .map(AttendEntity::getMemberId) + .collect(Collectors.toList()); - return memberRepository.findMembersByProgramId(programId).stream() - .filter(member -> statusMember.contains(member.getId())) - .map(member -> infoConverter.from(member, status)) - .collect(Collectors.toList()); - } + return memberRepository.findMembersByProgramId(programId).stream() + .filter(member -> statusMember.contains(member.getId())) + .map(member -> infoConverter.from(member, status)) + .collect(Collectors.toList()); + } - @Transactional - @Override - public void changeStatus(final ChangeStatusRequest request, final Long programId) { - AttendModel model = - attendRepository - .findByProgramIdAndMemberId(programId, request.getMemberId()) - .map(attendEntityConverter::from) - .orElseThrow(NotFoundAttendException::new); + @Transactional + @Override + public void changeStatus(final ChangeStatusRequest request, final Long programId) { + AttendModel model = + attendRepository + .findByProgramIdAndMemberId(programId, request.getMemberId()) + .map(attendEntityConverter::from) + .orElseThrow(() -> new NotFoundAttendException(programId)); - model.isSame(request.getBeforeAttendStatus()); + model.isSame(request.getBeforeAttendStatus()); - model.changeStatus(request.getAfterAttendStatus()); - attendRepository.save(attendEntityConverter.toEntity(model)); - } + model.changeStatus(request.getAfterAttendStatus()); + attendRepository.save(attendEntityConverter.toEntity(model)); + } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/member/application/service/MemberService.java b/BE/eeos/src/main/java/com/blackcompany/eeos/member/application/service/MemberService.java index 0d49ce2c..fd5218ed 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/member/application/service/MemberService.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/member/application/service/MemberService.java @@ -1,9 +1,7 @@ package com.blackcompany.eeos.member.application.service; -import com.blackcompany.eeos.attend.application.exception.NotFoundMemberException; import com.blackcompany.eeos.member.application.model.MemberModel; import com.blackcompany.eeos.member.application.model.converter.MemberEntityConverter; -import com.blackcompany.eeos.member.persistence.MemberEntity; import com.blackcompany.eeos.member.persistence.MemberRepository; import java.util.List; import java.util.stream.Collectors; @@ -21,13 +19,4 @@ public List findAllMember() { .map(entityConverter::from) .collect(Collectors.toList()); } - - public MemberModel findMemberInfo(final Long memberId) { - MemberEntity entity = - memberRepository - .findById(memberId) - .orElseThrow(() -> new NotFoundMemberException("존재하지 않는 멤버입니다.")); - - return entityConverter.from(entity); - } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/domain/ProgramStatus.java b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/domain/ProgramStatus.java index 130c65fd..7ec6dd9a 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/domain/ProgramStatus.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/domain/ProgramStatus.java @@ -1,6 +1,6 @@ package com.blackcompany.eeos.program.application.domain; -import com.blackcompany.eeos.attend.application.exception.NotFoundStatusException; +import com.blackcompany.eeos.attend.application.exception.NotFoundAttendStatusException; import java.util.Arrays; public enum ProgramStatus { @@ -17,6 +17,6 @@ public static ProgramStatus getStatus(String source) { return Arrays.stream(ProgramStatus.values()) .filter(status -> status.status.equals(source)) .findAny() - .orElseThrow(NotFoundStatusException::new); + .orElseThrow(()-> new NotFoundAttendStatusException(source)); } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/NotFoundProgramException.java b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/NotFoundProgramException.java index 63a66390..f0b317dd 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/NotFoundProgramException.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/exception/NotFoundProgramException.java @@ -2,9 +2,20 @@ import com.blackcompany.eeos.common.exception.BusinessException; import org.springframework.http.HttpStatus; - +/** + * 존재하지 않는 프로그램일 때 발생하는 예외 + */ public class NotFoundProgramException extends BusinessException { - public NotFoundProgramException() { - super("존재하지 않는 프로그램입니다.", HttpStatus.NOT_FOUND); + private static final String FAIL_CODE = "1000"; + private final Long programId; + + public NotFoundProgramException(Long programId) { + super(FAIL_CODE, HttpStatus.NOT_FOUND); + this.programId = programId; + } + + @Override + public String getMessage() { + return String.format("존재하지 않는 프로그램입니다. programId : %d", programId); } } diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramService.java b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramService.java index 87f54ad7..8597f5a9 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramService.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramService.java @@ -57,7 +57,7 @@ public CommandProgramResponse create(CreateProgramRequest request) { @Override public GetProgramResponse getProgram(Long id) { ProgramEntity programEntity = - programRepository.findById(id).orElseThrow(NotFoundProgramException::new); + programRepository.findById(id).orElseThrow(() -> new NotFoundProgramException(id)); ProgramModel model = entityConverter.from(programEntity); return responseConverter.from(model, model.calculate()); diff --git a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramValidService.java b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramValidService.java index 872ad281..e03398e9 100644 --- a/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramValidService.java +++ b/BE/eeos/src/main/java/com/blackcompany/eeos/program/application/service/ProgramValidService.java @@ -13,7 +13,7 @@ public class ProgramValidService { public void validate(Long programId) { if (!programRepository.existsById(programId)) { - throw new NotFoundProgramException(); + throw new NotFoundProgramException(programId); } } }