Skip to content

Commit

Permalink
✨ Repository 작성 (#25)
Browse files Browse the repository at this point in the history
* ✨ 포트폴리오 Repository, Exception 작성

* ✨ 가능한 작업 Repository, Exception 작성

* ✨ 홍보 요청 내역 Repository, Exception 작성

* ✨ 홍보 내역 결과 Repository, Exception 작성

* ♻️ 메소드명 변경
  • Loading branch information
MinseoKangQ authored Nov 2, 2024
1 parent c5ab024 commit e8089dd
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/example/gather_back_end/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Portfolio, Long> {

default Portfolio getById(Long id) {
return findById(id).orElseThrow(PortfolioNotFoundException::new);
}

Optional<Portfolio> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -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<PromotionRequest, Long> {

default PromotionRequest getById(Long id) {
return findById(id).orElseThrow(PromotionRequestNotFoundException::new);
}
Optional<PromotionRequest> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -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<PromotionResult, Long> {

default PromotionResult getById(Long id) {
return findById(id).orElseThrow(PromotionResultNotFoundException::new);
}

Optional<PromotionResult> findById(Long id);
}
Original file line number Diff line number Diff line change
@@ -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<Work, Long> {

default Work getById(Long id) {
return findById(id).orElseThrow(WorkNotFoundException::new);
}

Optional<Work> findById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit e8089dd

Please sign in to comment.