From e8089ddb6e86114fa61e8dcd7fa84352c7a374dc Mon Sep 17 00:00:00 2001 From: Minseo Kang Date: Sat, 2 Nov 2024 16:53:04 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Repository=20=EC=9E=91=EC=84=B1=20(?= =?UTF-8?q?#25)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: 포트폴리오 Repository, Exception 작성 * :sparkles: 가능한 작업 Repository, Exception 작성 * :sparkles: 홍보 요청 내역 Repository, Exception 작성 * :sparkles: 홍보 내역 결과 Repository, Exception 작성 * :recycle: 메소드명 변경 --- .../example/gather_back_end/domain/User.java | 2 +- .../exception/PortfolioErrorCode.java | 18 ++++++++++++++++++ .../exception/PortfolioNotFoundException.java | 10 ++++++++++ .../exception/PromotionRequestErrorCode.java | 18 ++++++++++++++++++ .../PromotionRequestNotFoundException.java | 10 ++++++++++ .../exception/PromotionResultErrorCode.java | 18 ++++++++++++++++++ .../PromotionResultNotFoundException.java | 11 +++++++++++ .../repository/PortfolioRepository.java | 17 +++++++++++++++++ .../repository/PromotionRequestRepository.java | 16 ++++++++++++++++ .../repository/PromotionResultRepository.java | 17 +++++++++++++++++ .../repository/WorkRepository.java | 17 +++++++++++++++++ .../service/CustomOAuth2UserServiceImpl.java | 2 +- .../work/exception/WorkErrorCode.java | 18 ++++++++++++++++++ .../work/exception/WorkNotFoundException.java | 10 ++++++++++ 14 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioErrorCode.java create mode 100644 src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioNotFoundException.java create mode 100644 src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestErrorCode.java create mode 100644 src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestNotFoundException.java create mode 100644 src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultErrorCode.java create mode 100644 src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultNotFoundException.java create mode 100644 src/main/java/org/example/gather_back_end/repository/PortfolioRepository.java create mode 100644 src/main/java/org/example/gather_back_end/repository/PromotionRequestRepository.java create mode 100644 src/main/java/org/example/gather_back_end/repository/PromotionResultRepository.java create mode 100644 src/main/java/org/example/gather_back_end/repository/WorkRepository.java create mode 100644 src/main/java/org/example/gather_back_end/work/exception/WorkErrorCode.java create mode 100644 src/main/java/org/example/gather_back_end/work/exception/WorkNotFoundException.java diff --git a/src/main/java/org/example/gather_back_end/domain/User.java b/src/main/java/org/example/gather_back_end/domain/User.java index 78f3000..c30ab0b 100644 --- a/src/main/java/org/example/gather_back_end/domain/User.java +++ b/src/main/java/org/example/gather_back_end/domain/User.java @@ -80,7 +80,7 @@ private User(Long id, String username, String name, String email, String role, S this.nickname = nickname; } - public static User createAllUserInfo(String username, String name, String email, String role, String nickname) { + public static User createUserInfo(String username, String name, String email, String role, String nickname) { return User.builder() .username(username) .name(name) diff --git a/src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioErrorCode.java b/src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioErrorCode.java new file mode 100644 index 0000000..535efda --- /dev/null +++ b/src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioErrorCode.java @@ -0,0 +1,18 @@ +package org.example.gather_back_end.portfolio.exception; + +import static org.example.gather_back_end.util.constant.StaticValue.NOT_FOUND; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.example.gather_back_end.util.exception.BaseErrorCode; + +@Getter +@AllArgsConstructor +public enum PortfolioErrorCode implements BaseErrorCode { + + PORTFOLIO_NOT_FOUND_EXCEPTION(NOT_FOUND, "PORTFOLIO_404", "존재하지 않는 포트폴리오입니다."); + + private final int httpStatus; + private final String code; + private final String message; +} diff --git a/src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioNotFoundException.java b/src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioNotFoundException.java new file mode 100644 index 0000000..c463466 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/portfolio/exception/PortfolioNotFoundException.java @@ -0,0 +1,10 @@ +package org.example.gather_back_end.portfolio.exception; + +import org.example.gather_back_end.util.exception.BaseException; + +public class PortfolioNotFoundException extends BaseException { + + public PortfolioNotFoundException() { + super(PortfolioErrorCode.PORTFOLIO_NOT_FOUND_EXCEPTION); + } +} diff --git a/src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestErrorCode.java b/src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestErrorCode.java new file mode 100644 index 0000000..b61a168 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestErrorCode.java @@ -0,0 +1,18 @@ +package org.example.gather_back_end.promotionrequest.exception; + +import static org.example.gather_back_end.util.constant.StaticValue.NOT_FOUND; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.example.gather_back_end.util.exception.BaseErrorCode; + +@Getter +@AllArgsConstructor +public enum PromotionRequestErrorCode implements BaseErrorCode { + + PROMOTION_REQUEST_NOT_FOUND_EXCEPTION(NOT_FOUND, "PROMOTION_REQUEST_404", "존재하지 않는 홍보 요청 내역입니다."); + + private final int httpStatus; + private final String code; + private final String message; +} diff --git a/src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestNotFoundException.java b/src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestNotFoundException.java new file mode 100644 index 0000000..f2d06eb --- /dev/null +++ b/src/main/java/org/example/gather_back_end/promotionrequest/exception/PromotionRequestNotFoundException.java @@ -0,0 +1,10 @@ +package org.example.gather_back_end.promotionrequest.exception; + +import org.example.gather_back_end.util.exception.BaseException; + +public class PromotionRequestNotFoundException extends BaseException { + + public PromotionRequestNotFoundException() { + super(PromotionRequestErrorCode.PROMOTION_REQUEST_NOT_FOUND_EXCEPTION); + } +} diff --git a/src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultErrorCode.java b/src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultErrorCode.java new file mode 100644 index 0000000..6f4a4a4 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultErrorCode.java @@ -0,0 +1,18 @@ +package org.example.gather_back_end.promotionresult.exception; + +import static org.example.gather_back_end.util.constant.StaticValue.NOT_FOUND; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.example.gather_back_end.util.exception.BaseErrorCode; + +@Getter +@AllArgsConstructor +public enum PromotionResultErrorCode implements BaseErrorCode { + + PROMOTION_RESULT_NOT_FOUND_EXCEPTION(NOT_FOUND, "PROMOTION_RESULT_404", "존재하지 않는 홍보 요청 결과 내역입니다."); + + private final int httpStatus; + private final String code; + private final String message; +} diff --git a/src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultNotFoundException.java b/src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultNotFoundException.java new file mode 100644 index 0000000..95edcd4 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/promotionresult/exception/PromotionResultNotFoundException.java @@ -0,0 +1,11 @@ +package org.example.gather_back_end.promotionresult.exception; + +import org.example.gather_back_end.util.exception.BaseException; + +public class PromotionResultNotFoundException extends BaseException { + + public PromotionResultNotFoundException() { + super(PromotionResultErrorCode.PROMOTION_RESULT_NOT_FOUND_EXCEPTION); + } + +} diff --git a/src/main/java/org/example/gather_back_end/repository/PortfolioRepository.java b/src/main/java/org/example/gather_back_end/repository/PortfolioRepository.java new file mode 100644 index 0000000..56d754e --- /dev/null +++ b/src/main/java/org/example/gather_back_end/repository/PortfolioRepository.java @@ -0,0 +1,17 @@ +package org.example.gather_back_end.repository; + +import java.util.Optional; +import org.example.gather_back_end.domain.Portfolio; +import org.example.gather_back_end.portfolio.exception.PortfolioNotFoundException; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PortfolioRepository extends JpaRepository { + + default Portfolio getById(Long id) { + return findById(id).orElseThrow(PortfolioNotFoundException::new); + } + + Optional findById(Long id); +} diff --git a/src/main/java/org/example/gather_back_end/repository/PromotionRequestRepository.java b/src/main/java/org/example/gather_back_end/repository/PromotionRequestRepository.java new file mode 100644 index 0000000..44beee7 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/repository/PromotionRequestRepository.java @@ -0,0 +1,16 @@ +package org.example.gather_back_end.repository; + +import java.util.Optional; +import org.example.gather_back_end.domain.PromotionRequest; +import org.example.gather_back_end.promotionrequest.exception.PromotionRequestNotFoundException; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PromotionRequestRepository extends JpaRepository { + + default PromotionRequest getById(Long id) { + return findById(id).orElseThrow(PromotionRequestNotFoundException::new); + } + Optional findById(Long id); +} diff --git a/src/main/java/org/example/gather_back_end/repository/PromotionResultRepository.java b/src/main/java/org/example/gather_back_end/repository/PromotionResultRepository.java new file mode 100644 index 0000000..c730c53 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/repository/PromotionResultRepository.java @@ -0,0 +1,17 @@ +package org.example.gather_back_end.repository; + +import java.util.Optional; +import org.example.gather_back_end.domain.PromotionResult; +import org.example.gather_back_end.promotionresult.exception.PromotionResultNotFoundException; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PromotionResultRepository extends JpaRepository { + + default PromotionResult getById(Long id) { + return findById(id).orElseThrow(PromotionResultNotFoundException::new); + } + + Optional findById(Long id); +} diff --git a/src/main/java/org/example/gather_back_end/repository/WorkRepository.java b/src/main/java/org/example/gather_back_end/repository/WorkRepository.java new file mode 100644 index 0000000..74d8e7b --- /dev/null +++ b/src/main/java/org/example/gather_back_end/repository/WorkRepository.java @@ -0,0 +1,17 @@ +package org.example.gather_back_end.repository; + +import java.util.Optional; +import org.example.gather_back_end.domain.Work; +import org.example.gather_back_end.work.exception.WorkNotFoundException; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface WorkRepository extends JpaRepository { + + default Work getById(Long id) { + return findById(id).orElseThrow(WorkNotFoundException::new); + } + + Optional findById(Long id); +} diff --git a/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java b/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java index 16e7fd1..7668b40 100644 --- a/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java +++ b/src/main/java/org/example/gather_back_end/util/jwt/service/CustomOAuth2UserServiceImpl.java @@ -67,7 +67,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic if (existData == null) { - userRepository.save(User.createAllUserInfo( + userRepository.save(User.createUserInfo( username, oAuth2Response.getName(), oAuth2Response.getEmail(), diff --git a/src/main/java/org/example/gather_back_end/work/exception/WorkErrorCode.java b/src/main/java/org/example/gather_back_end/work/exception/WorkErrorCode.java new file mode 100644 index 0000000..092bc74 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/work/exception/WorkErrorCode.java @@ -0,0 +1,18 @@ +package org.example.gather_back_end.work.exception; + +import static org.example.gather_back_end.util.constant.StaticValue.NOT_FOUND; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.example.gather_back_end.util.exception.BaseErrorCode; + +@Getter +@AllArgsConstructor +public enum WorkErrorCode implements BaseErrorCode { + + WORK_NOT_FOUND_EXCEPTION(NOT_FOUND, "WORK_404", "존재하지 않는 작업입니다."); + + private final int httpStatus; + private final String code; + private final String message; +} diff --git a/src/main/java/org/example/gather_back_end/work/exception/WorkNotFoundException.java b/src/main/java/org/example/gather_back_end/work/exception/WorkNotFoundException.java new file mode 100644 index 0000000..a135b11 --- /dev/null +++ b/src/main/java/org/example/gather_back_end/work/exception/WorkNotFoundException.java @@ -0,0 +1,10 @@ +package org.example.gather_back_end.work.exception; + +import org.example.gather_back_end.util.exception.BaseException; + +public class WorkNotFoundException extends BaseException { + + public WorkNotFoundException() { + super(WorkErrorCode.WORK_NOT_FOUND_EXCEPTION); + } +}