-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: findByIdOrThrow 메서드 repository에 정의
related to: #18
- Loading branch information
1 parent
a1142fd
commit e909bdb
Showing
6 changed files
with
37 additions
and
49 deletions.
There are no files selected for viewing
9 changes: 5 additions & 4 deletions
9
src/main/java/com/_119/wepro/member/domain/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package com._119.wepro.member.domain.repository; | ||
|
||
import com._119.wepro.global.exception.RestApiException; | ||
import com._119.wepro.global.exception.errorcode.UserErrorCode; | ||
import com._119.wepro.member.domain.Member; | ||
import com._119.wepro.member.domain.OauthInfo; | ||
import io.lettuce.core.dynamic.annotation.Param; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Optional<Member> findByOauthInfo(OauthInfo oauthInfo); | ||
|
||
@Query("SELECT m FROM Member m WHERE m.oauthInfo.providerId = :providerId") | ||
Optional<Member> findByProviderId(@Param("providerId") String providerId); | ||
default Member findByIdOrThrow(Long memberId) { | ||
return findById(memberId).orElseThrow(() -> new RestApiException(UserErrorCode.USER_NOT_FOUND)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/_119/wepro/project/domain/repository/ProjectRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package com._119.wepro.project.domain.repository; | ||
|
||
import com._119.wepro.global.exception.RestApiException; | ||
import com._119.wepro.global.exception.errorcode.ProjectErrorCode; | ||
import com._119.wepro.project.domain.Project; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProjectRepository extends JpaRepository<Project, Long> { | ||
|
||
default Project findByIdOrThrow(Long projectId) { | ||
return findById(projectId).orElseThrow(() -> new RestApiException(ProjectErrorCode.PROJECT_NOT_FOUND)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/_119/wepro/review/domain/repository/ReviewFormRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package com._119.wepro.review.domain.repository; | ||
|
||
import com._119.wepro.global.exception.RestApiException; | ||
import com._119.wepro.global.exception.errorcode.ReviewErrorCode; | ||
import com._119.wepro.review.domain.ReviewForm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ReviewFormRepository extends JpaRepository<ReviewForm, Long> { | ||
|
||
default ReviewForm findByIdOrThrow(Long reviewFormId) { | ||
return findById(reviewFormId).orElseThrow(() -> new RestApiException(ReviewErrorCode.REVIEW_FORM_NOT_FOUND)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters