-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
332 additions
and
6 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
17 changes: 17 additions & 0 deletions
17
src/main/java/javalab/umc7th_mission/config/QueryDSLConfig.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,17 @@ | ||
package javalab.umc7th_mission.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class QueryDSLConfig { | ||
private final EntityManager em; | ||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(em); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...va/javalab/umc7th_mission/repository/MemberMissionRepository/MemberMissionRepository.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,8 @@ | ||
package javalab.umc7th_mission.repository.MemberMissionRepository; | ||
|
||
import javalab.umc7th_mission.domain.mapping.MemberMission; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberMissionRepository extends JpaRepository<MemberMission, Long>, MemberMissionRepositoryCustom { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...alab/umc7th_mission/repository/MemberMissionRepository/MemberMissionRepositoryCustom.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 javalab.umc7th_mission.repository.MemberMissionRepository; | ||
|
||
|
||
import javalab.umc7th_mission.domain.enums.MissionStatus; | ||
import javalab.umc7th_mission.domain.mapping.MemberMission; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
import java.util.List; | ||
|
||
@Repository | ||
public interface MemberMissionRepositoryCustom { | ||
List<MemberMission> findChallengingMissionByMember(Long memberId, Pageable pageable); | ||
List<MemberMission> findCompletedMissionByMember(Long memberId, Pageable pageable); | ||
Long countCompletedMissionByMember(Long memberId, String regionName); | ||
} |
90 changes: 90 additions & 0 deletions
90
...avalab/umc7th_mission/repository/MemberMissionRepository/MemberMissionRepositoryImpl.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,90 @@ | ||
package javalab.umc7th_mission.repository.MemberMissionRepository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import ext.javalab.umc7th_mission.domain.QMember; | ||
import ext.javalab.umc7th_mission.domain.QMission; | ||
import ext.javalab.umc7th_mission.domain.QRegion; | ||
import ext.javalab.umc7th_mission.domain.QStore; | ||
import ext.javalab.umc7th_mission.domain.mapping.QMemberAddress; | ||
import ext.javalab.umc7th_mission.domain.mapping.QMemberMission; | ||
import ext.javalab.umc7th_mission.domain.mapping.QStoreAddress; | ||
import javalab.umc7th_mission.domain.enums.MissionStatus; | ||
import javalab.umc7th_mission.domain.mapping.MemberMission; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class MemberMissionRepositoryImpl implements MemberMissionRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
//멤버 id를 통해 현재 진행중인 미션을 보여주는 QueryDSL | ||
@Override | ||
public List<MemberMission> findChallengingMissionByMember(Long memberId, Pageable pageable) { | ||
QMemberMission memberMission = QMemberMission.memberMission; | ||
|
||
return queryFactory | ||
.selectFrom(memberMission) | ||
.where( | ||
memberMission.member.id.eq(memberId), | ||
memberMission.status.eq(MissionStatus.CHALLENGING) | ||
) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
} | ||
|
||
//멤버 id를 통해 완료된 미션을 보여주는 QueryDSL | ||
@Override | ||
public List<MemberMission> findCompletedMissionByMember(Long memberId, Pageable pageable) { | ||
QMemberMission memberMission = QMemberMission.memberMission; | ||
|
||
return queryFactory | ||
.selectFrom(memberMission) | ||
.where( | ||
memberMission.member.id.eq(memberId), | ||
memberMission.status.eq(MissionStatus.COMPLETE) | ||
) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
} | ||
|
||
|
||
//해당 지역의 완료된 미션의 개수를 보여주는 QueryDSL | ||
@Override | ||
public Long countCompletedMissionByMember(Long memberId, String regionName) { | ||
QMemberMission memberMission = QMemberMission.memberMission; | ||
QStoreAddress storeAddress = QStoreAddress.storeAddress; | ||
QMission mission = QMission.mission; | ||
QStore store = QStore.store; | ||
QRegion region = QRegion.region; | ||
|
||
Long regionId = queryFactory | ||
.select(region.id) | ||
.from(region) | ||
.where(region.name.eq(regionName)) | ||
.fetchOne(); | ||
|
||
if (regionId == null) { | ||
return Long.valueOf(0); | ||
} | ||
|
||
return queryFactory | ||
.select(memberMission.count()) | ||
.from(memberMission) | ||
.join(memberMission.mission, mission) | ||
.join(mission.store, store) | ||
.join(store.addressList, storeAddress) | ||
.where( | ||
memberMission.member.id.eq(memberId), | ||
memberMission.status.eq(MissionStatus.COMPLETE), | ||
storeAddress.region.id.eq(regionId) | ||
) | ||
.fetchOne(); | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/javalab/umc7th_mission/repository/MemberRepository/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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package javalab.umc7th_mission.repository.MemberRepository; | ||
|
||
import javalab.umc7th_mission.domain.Member; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Integer> { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/javalab/umc7th_mission/repository/MemberRepository/MemberRepositoryCustom.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,12 @@ | ||
package javalab.umc7th_mission.repository.MemberRepository; | ||
|
||
import javalab.umc7th_mission.domain.Member; | ||
import javalab.umc7th_mission.web.dto.MemberInfoDto; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface MemberRepositoryCustom { | ||
MemberInfoDto findMemberInfoById(Long memberId); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/javalab/umc7th_mission/repository/MemberRepository/MemberRepositoryImpl.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,32 @@ | ||
package javalab.umc7th_mission.repository.MemberRepository; | ||
|
||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import ext.javalab.umc7th_mission.domain.QMember; | ||
import javalab.umc7th_mission.domain.Member; | ||
import javalab.umc7th_mission.web.dto.MemberInfoDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class MemberRepositoryImpl implements MemberRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
//멤버의 정보를 Dto객체로 보여주는 QueryDSL | ||
@Override | ||
public MemberInfoDto findMemberInfoById(Long memberId) { | ||
QMember member = QMember.member; | ||
|
||
return queryFactory | ||
.select(Projections.constructor(MemberInfoDto.class, | ||
member.nickname, | ||
member.email, | ||
member.phoneNumber, | ||
member.point)) | ||
.from(member) | ||
.where(member.id.eq(memberId)) | ||
.fetchOne(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/javalab/umc7th_mission/repository/ReviewRepository/ReviewRepository.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,22 @@ | ||
package javalab.umc7th_mission.repository.ReviewRepository; | ||
|
||
import jakarta.transaction.Transactional; | ||
import javalab.umc7th_mission.domain.Review; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public interface ReviewRepository extends JpaRepository<Review, Integer> { | ||
|
||
@Modifying | ||
@Transactional | ||
@Query(value = "INSERT INTO Review (member_id, store_id, content, rating) VALUES (:memberId, :storeId, :content, :rating)", nativeQuery = true) | ||
void insertReview(@Param("memberId") Long memberId, | ||
@Param("storeId") Long storeId, | ||
@Param("content") String content, | ||
@Param("rating") BigDecimal rating | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/javalab/umc7th_mission/repository/ReviewRepository/ReviewRepositoryCustom.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,10 @@ | ||
package javalab.umc7th_mission.repository.ReviewRepository; | ||
|
||
import javalab.umc7th_mission.domain.Member; | ||
import javalab.umc7th_mission.domain.Store; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public interface ReviewRepositoryCustom { | ||
public Long save(Member member, Store store, String content, BigDecimal rating); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/javalab/umc7th_mission/repository/ReviewRepository/ReviewRepositoryImpl.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,28 @@ | ||
package javalab.umc7th_mission.repository.ReviewRepository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import ext.javalab.umc7th_mission.domain.QReview; | ||
import javalab.umc7th_mission.domain.Member; | ||
import javalab.umc7th_mission.domain.Review; | ||
import javalab.umc7th_mission.domain.Store; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ReviewRepositoryImpl implements ReviewRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
private final QReview review = QReview.review; | ||
|
||
//리뷰 작성 및 저장 | ||
@Override | ||
public Long save(Member member, Store store, String content, BigDecimal rating) { | ||
return queryFactory | ||
.insert(review) | ||
.columns(review.member, review.store, review.content, review.rating) | ||
.values(member, store, content, rating) | ||
.execute(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/javalab/umc7th_mission/repository/StoreRepository/StoreRepository.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,7 @@ | ||
package javalab.umc7th_mission.repository.StoreRepository; | ||
|
||
import javalab.umc7th_mission.domain.Store; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface StoreRepository extends JpaRepository<Store, Long>, StoreRepositoryCustom { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/javalab/umc7th_mission/repository/StoreRepository/StoreRepositoryCustom.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,9 @@ | ||
package javalab.umc7th_mission.repository.StoreRepository; | ||
|
||
import javalab.umc7th_mission.domain.Store; | ||
|
||
import java.util.List; | ||
|
||
public interface StoreRepositoryCustom { | ||
List<Store> dynamicQueryWithBooleanBuilder(String name, Float score); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/javalab/umc7th_mission/repository/StoreRepository/StoreRepositoryImpl.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,32 @@ | ||
package javalab.umc7th_mission.repository.StoreRepository; | ||
|
||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import ext.javalab.umc7th_mission.domain.QStore; | ||
import javalab.umc7th_mission.domain.Store; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class StoreRepositoryImpl implements StoreRepositoryCustom { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
private final QStore store = QStore.store; | ||
|
||
//예시 QueryDSL? | ||
@Override | ||
public List<Store> dynamicQueryWithBooleanBuilder(String name, Float score) { | ||
BooleanBuilder predicate = new BooleanBuilder(); | ||
|
||
if (name != null) { | ||
predicate.and(store.name.eq(name)); | ||
} | ||
|
||
return jpaQueryFactory | ||
.selectFrom(store) | ||
.where(predicate) | ||
.fetch(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/javalab/umc7th_mission/web/dto/MemberInfoDto.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,13 @@ | ||
package javalab.umc7th_mission.web.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class MemberInfoDto { | ||
private String nickname; | ||
private String email; | ||
private Integer points; | ||
private String phoneNumber; | ||
} |