-
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.
Showing
12 changed files
with
98 additions
and
41 deletions.
There are no files selected for viewing
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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/drinkeg/drinkeg/repository/TastingNoteRepositoryCustom.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.drinkeg.drinkeg.repository; | ||
|
||
import com.drinkeg.drinkeg.domain.TastingNote; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface TastingNoteRepositoryCustom { | ||
|
||
Optional<TastingNote> findTastingNoteWithWineAndNoseById(Long tastingNoteId); | ||
|
||
Optional<TastingNote> findTastingNoteWithNoseById(Long tastingNoteId); | ||
|
||
List<TastingNote> findTastingNotesWithWineAndNoseByUsername(String username); | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/drinkeg/drinkeg/repository/TastingNoteRepositoryImpl.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.drinkeg.drinkeg.repository; | ||
|
||
import com.drinkeg.drinkeg.domain.QMember; | ||
import com.drinkeg.drinkeg.domain.TastingNote; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.drinkeg.drinkeg.domain.QMember.member; | ||
import static com.drinkeg.drinkeg.domain.QTastingNote.tastingNote; | ||
import static com.drinkeg.drinkeg.domain.QTastingNoteNose.tastingNoteNose; | ||
import static com.drinkeg.drinkeg.domain.QWine.wine; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class TastingNoteRepositoryImpl implements TastingNoteRepositoryCustom{ | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Optional<TastingNote> findTastingNoteWithWineAndNoseById(Long tastingNoteId) { | ||
return Optional.ofNullable( | ||
queryFactory.selectFrom(tastingNote) | ||
.leftJoin(tastingNote.wine, wine).fetchJoin() | ||
.leftJoin(tastingNote.noseList, tastingNoteNose).fetchJoin() | ||
.where(tastingNote.id.eq(tastingNoteId)) | ||
.fetchOne() | ||
); | ||
} | ||
@Override | ||
public Optional<TastingNote> findTastingNoteWithNoseById(Long tastingNoteId) { | ||
return Optional.ofNullable( | ||
queryFactory.selectFrom(tastingNote) | ||
.leftJoin(tastingNote.noseList, tastingNoteNose).fetchJoin() | ||
.where(tastingNote.id.eq(tastingNoteId)) | ||
.fetchOne() | ||
); | ||
} | ||
|
||
@Override | ||
public List<TastingNote> findTastingNotesWithWineAndNoseByUsername(String username) { | ||
return queryFactory.selectFrom(tastingNote) | ||
.leftJoin(tastingNote.member, member).fetchJoin() | ||
.leftJoin(tastingNote.wine, wine).fetchJoin() | ||
.leftJoin(tastingNote.noseList, tastingNoteNose).fetchJoin() | ||
.where(member.username.eq(username)) | ||
.fetch(); | ||
} | ||
} |
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
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
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