From 4dce4021616f4fabc675eb72eb4d9df55ce81b28 Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Sun, 26 Nov 2023 07:21:10 +0900 Subject: [PATCH] =?UTF-8?q?REFACTOR=20:=20Apply=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../program/service/ProgramService.java | 11 ++++--- .../user/controller/UserController.java | 2 +- .../domain/exception/apply/ApplyError.java | 31 +++++++++++++++++++ .../exception/apply/ApplyException.java | 9 ++++++ .../domain/exception/apply/ApplySuccess.java | 29 +++++++++++++++++ .../exception/{ => user}/UserError.java | 2 +- .../exception/{ => user}/UserException.java | 2 +- .../exception/{ => user}/UserSuccess.java | 2 +- .../sopkerton/user/service/UserService.java | 4 +-- 9 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyError.java create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyException.java create mode 100644 src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplySuccess.java rename src/main/java/org/sopt/sopkerton/user/domain/exception/{ => user}/UserError.java (91%) rename src/main/java/org/sopt/sopkerton/user/domain/exception/{ => user}/UserException.java (78%) rename src/main/java/org/sopt/sopkerton/user/domain/exception/{ => user}/UserSuccess.java (93%) diff --git a/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java index cb437da..e1007e2 100644 --- a/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java +++ b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java @@ -14,6 +14,8 @@ import org.sopt.sopkerton.program.infrastructure.ProgramRepository; import org.sopt.sopkerton.user.domain.Apply; import org.sopt.sopkerton.user.domain.enums.ApplyStatus; +import org.sopt.sopkerton.user.domain.exception.apply.ApplyError; +import org.sopt.sopkerton.user.domain.exception.apply.ApplyException; import org.sopt.sopkerton.user.infrastructure.ApplyRepository; import org.springframework.stereotype.Service; @@ -29,7 +31,7 @@ public class ProgramService { public List getProgramListByProgramType(String programType) { List programs = programRepository.findAllByProgramType(programType); - List programListResponses = programs.stream() + return programs.stream() .map(program -> new ProgramListResponse( program.getId(), program.getTitle(), @@ -40,13 +42,12 @@ public List getProgramListByProgramType(String programType) program.getType() )) .collect(Collectors.toList()); - return programListResponses; } public List getStatusDoneProgramList() { List programs = programRepository.findAllByStatus(Status.DONE); - List programListResponses = programs.stream() + return programs.stream() .map(program -> new ProgramListResponse( program.getId(), program.getTitle(), @@ -57,13 +58,13 @@ public List getStatusDoneProgramList() { program.getType() )) .collect(Collectors.toList()); - return programListResponses; } public Object getProgramDetail(Long userId, Long programId) { Program program = programRepository.findById(programId) .orElseThrow(() -> new ProgramException(ProgramError.PROGRAM_NOT_FOUND)); - Apply apply = applyRepository.findByUserIdAndProgramId(userId, programId).get(); + Apply apply = applyRepository.findByUserIdAndProgramId(userId, programId) + .orElseThrow(() -> new ApplyException(ApplyError.APPLY_NOT_FOUND)); boolean isApply = convertToIsApply(apply.getIsApply()); if (program.getType().equals(VOLUNTEER_TYPE)) { return new ProgramDetailResponse.VolunteerDetail( diff --git a/src/main/java/org/sopt/sopkerton/user/controller/UserController.java b/src/main/java/org/sopt/sopkerton/user/controller/UserController.java index 799e846..1ce013f 100644 --- a/src/main/java/org/sopt/sopkerton/user/controller/UserController.java +++ b/src/main/java/org/sopt/sopkerton/user/controller/UserController.java @@ -2,7 +2,7 @@ import lombok.RequiredArgsConstructor; import org.sopt.sopkerton.common.response.ApiResponse; -import org.sopt.sopkerton.user.domain.exception.UserSuccess; +import org.sopt.sopkerton.user.domain.exception.user.UserSuccess; import org.sopt.sopkerton.user.dto.response.DetailView; import org.sopt.sopkerton.user.dto.response.MainView; import org.sopt.sopkerton.user.service.UserService; diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyError.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyError.java new file mode 100644 index 0000000..ef1ef8e --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyError.java @@ -0,0 +1,31 @@ +package org.sopt.sopkerton.user.domain.exception.apply; + +import lombok.AllArgsConstructor; +import org.sopt.sopkerton.common.exception.base.ErrorBase; +import org.springframework.http.HttpStatus; + +@AllArgsConstructor +public enum ApplyError implements ErrorBase { + + APPLY_NOT_FOUND(HttpStatus.NOT_FOUND, "Can not found Apply.") + ; + + + private final HttpStatus status; + private final String errorMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getErrorMessage() { + return this.errorMessage; + } +} diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyException.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyException.java new file mode 100644 index 0000000..e250b82 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplyException.java @@ -0,0 +1,9 @@ +package org.sopt.sopkerton.user.domain.exception.apply; + +import org.sopt.sopkerton.common.exception.base.ExceptionBase; + +public class ApplyException extends ExceptionBase { + public ApplyException(ApplyError errorBase) { + super(errorBase); + } +} diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplySuccess.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplySuccess.java new file mode 100644 index 0000000..2f8e2d6 --- /dev/null +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/apply/ApplySuccess.java @@ -0,0 +1,29 @@ +package org.sopt.sopkerton.user.domain.exception.apply; + +import lombok.AllArgsConstructor; +import org.sopt.sopkerton.common.exception.base.SuccessBase; +import org.springframework.http.HttpStatus; + +@AllArgsConstructor +public enum ApplySuccess implements SuccessBase { + + ; + + private final HttpStatus status; + private final String successMessage; + + @Override + public int getHttpStatusCode() { + return this.status.value(); + } + + @Override + public HttpStatus getHttpStatus() { + return this.status; + } + + @Override + public String getSuccessMessage() { + return this.successMessage; + } +} diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserError.java similarity index 91% rename from src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java rename to src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserError.java index 3acdf3c..70d1a17 100644 --- a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.java +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserError.java @@ -1,4 +1,4 @@ -package org.sopt.sopkerton.user.domain.exception; +package org.sopt.sopkerton.user.domain.exception.user; import lombok.AllArgsConstructor; import org.sopt.sopkerton.common.exception.base.ErrorBase; diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserException.java similarity index 78% rename from src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java rename to src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserException.java index f17b0b6..ff518e9 100644 --- a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.java +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserException.java @@ -1,4 +1,4 @@ -package org.sopt.sopkerton.user.domain.exception; +package org.sopt.sopkerton.user.domain.exception.user; import org.sopt.sopkerton.common.exception.base.ExceptionBase; diff --git a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java b/src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserSuccess.java similarity index 93% rename from src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java rename to src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserSuccess.java index 0a72e31..c63103a 100644 --- a/src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.java +++ b/src/main/java/org/sopt/sopkerton/user/domain/exception/user/UserSuccess.java @@ -1,4 +1,4 @@ -package org.sopt.sopkerton.user.domain.exception; +package org.sopt.sopkerton.user.domain.exception.user; import lombok.AllArgsConstructor; import org.sopt.sopkerton.common.exception.base.SuccessBase; diff --git a/src/main/java/org/sopt/sopkerton/user/service/UserService.java b/src/main/java/org/sopt/sopkerton/user/service/UserService.java index a1cc704..1d13058 100644 --- a/src/main/java/org/sopt/sopkerton/user/service/UserService.java +++ b/src/main/java/org/sopt/sopkerton/user/service/UserService.java @@ -3,8 +3,8 @@ import lombok.RequiredArgsConstructor; import org.sopt.sopkerton.user.domain.User; import org.sopt.sopkerton.user.domain.enums.Gender; -import org.sopt.sopkerton.user.domain.exception.UserError; -import org.sopt.sopkerton.user.domain.exception.UserException; +import org.sopt.sopkerton.user.domain.exception.user.UserError; +import org.sopt.sopkerton.user.domain.exception.user.UserException; import org.sopt.sopkerton.user.dto.response.DetailView; import org.sopt.sopkerton.user.dto.response.MainView; import org.sopt.sopkerton.user.infrastructure.UserRepository;