-
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.
Merge pull request #25 from CoolPeace-yanolza/feature/coupon/query-se…
…rvice 쿠폰 레포,서비스 추가 및 일간 리포트 구현
- Loading branch information
Showing
10 changed files
with
204 additions
and
3 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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/coolpeace/domain/coupon/dto/request/CouponDailyRequest.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 com.coolpeace.domain.coupon.dto.request; | ||
|
||
|
||
public record CouponDailyRequest( | ||
Long memberId, | ||
Long accommodationId | ||
) { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/coolpeace/domain/coupon/dto/response/CouponDailyResponse.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,19 @@ | ||
package com.coolpeace.domain.coupon.dto.response; | ||
|
||
import com.coolpeace.domain.coupon.entity.CouponDailyCondition; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CouponDailyResponse( | ||
CouponDailyCondition condition, | ||
List<String> couponTitles | ||
) { | ||
public static CouponDailyResponse from(CouponDailyCondition condition,List<String> couponTitles) { | ||
return new CouponDailyResponse(condition, couponTitles); | ||
} | ||
public static CouponDailyResponse from(CouponDailyCondition condition) { | ||
return new CouponDailyResponse(condition, Collections.emptyList()); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/coolpeace/domain/coupon/entity/CouponDailyCondition.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,14 @@ | ||
package com.coolpeace.domain.coupon.entity; | ||
|
||
public enum CouponDailyCondition { | ||
NO_REGISTER("등록된 쿠폰이 없음"), | ||
NO_EXPOSURE("노출중인 쿠폰이 없음"), | ||
EXPIRATION_3DAYS("곧 만료되는 쿠폰이 있음"), | ||
NO_CONDITION("아무 조건에 해당하지 않음"); | ||
|
||
private final String value; | ||
|
||
CouponDailyCondition(String value) { | ||
this.value = value; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/coolpeace/domain/coupon/entity/CouponStatus.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.coolpeace.domain.coupon.entity; | ||
|
||
public enum CouponStatus { | ||
EXPOSURE_ON("노출 ON"), | ||
EXPOSURE_OFF("노출 OFF"), | ||
EXPOSURE_WAIT("노출 대기중"), | ||
EXPOSURE_END("노출 종료"), | ||
DELETED("논리 삭제"); | ||
|
||
private final String value; | ||
|
||
CouponStatus(String value) { | ||
this.value = value; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/coolpeace/domain/coupon/repository/CouponRepository.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 com.coolpeace.domain.coupon.repository; | ||
|
||
import com.coolpeace.domain.accommodation.entity.Accommodation; | ||
import com.coolpeace.domain.coupon.entity.Coupon; | ||
import com.coolpeace.domain.member.entity.Member; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CouponRepository extends JpaRepository<Coupon,Long>,CouponRepositoryCustom { | ||
|
||
List<Coupon> findAllByMemberAndAccommodation(Member member, Accommodation accommodation); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/coolpeace/domain/coupon/repository/CouponRepositoryCustom.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,18 @@ | ||
package com.coolpeace.domain.coupon.repository; | ||
|
||
|
||
import com.coolpeace.domain.coupon.entity.Coupon; | ||
import java.util.List; | ||
|
||
public interface CouponRepositoryCustom { | ||
|
||
List<Coupon> exposureCoupons(Long memberId, Long accommodationId); | ||
|
||
Boolean noRegister(Long memberId,Long accommodationId); | ||
|
||
Boolean noExposure(Long memberId,Long accommodationId); | ||
|
||
List<Coupon> expiration3days(Long memberId,Long accommodationId); | ||
|
||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/coolpeace/domain/coupon/repository/CouponRepositoryImpl.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,62 @@ | ||
package com.coolpeace.domain.coupon.repository; | ||
|
||
import static com.coolpeace.domain.coupon.entity.QCoupon.coupon; | ||
|
||
import com.coolpeace.domain.accommodation.entity.Accommodation; | ||
import com.coolpeace.domain.coupon.entity.Coupon; | ||
import com.coolpeace.domain.coupon.entity.CouponStatus; | ||
import com.coolpeace.domain.member.entity.Member; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public class CouponRepositoryImpl implements CouponRepositoryCustom{ | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public CouponRepositoryImpl(EntityManager entityManager) { | ||
this.jpaQueryFactory = new JPAQueryFactory(entityManager); | ||
} | ||
|
||
|
||
@Override | ||
public List<Coupon> exposureCoupons(Long memberId, Long accommodationId) { | ||
return jpaQueryFactory.selectFrom(coupon) | ||
.where(coupon.member.id.eq(memberId) | ||
.and(coupon.accommodation.id.eq(accommodationId)) | ||
.and(coupon.couponStatus.eq(CouponStatus.EXPOSURE_ON))) | ||
.fetch(); | ||
} | ||
|
||
@Override | ||
public Boolean noRegister(Long memberId, Long accommodationId) { | ||
|
||
return jpaQueryFactory.selectFrom(coupon) | ||
.where(coupon.member.id.eq(memberId) | ||
.and(coupon.accommodation.id.eq(accommodationId)) | ||
.and(coupon.couponStatus.ne(CouponStatus.DELETED))) | ||
.fetch().isEmpty(); | ||
} | ||
|
||
@Override | ||
public Boolean noExposure(Long memberId, Long accommodationId) { | ||
|
||
return jpaQueryFactory.selectFrom(coupon) | ||
.where(coupon.member.id.eq(memberId) | ||
.and(coupon.accommodation.id.eq(accommodationId)) | ||
.and(coupon.couponStatus.eq(CouponStatus.EXPOSURE_ON))) | ||
.fetch().isEmpty(); | ||
} | ||
|
||
|
||
@Override | ||
public List<Coupon> expiration3days(Long memberId, Long accommodationId) { | ||
return jpaQueryFactory.selectFrom(coupon) | ||
.where(coupon.member.id.eq(memberId) | ||
.and(coupon.accommodation.id.eq(accommodationId)) | ||
.and(coupon.couponStatus.eq(CouponStatus.EXPOSURE_ON)) | ||
.and(coupon.endDate.before(LocalDateTime.now().plusDays(3)))) | ||
.fetch(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/coolpeace/domain/coupon/service/CouponQueryService.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,42 @@ | ||
package com.coolpeace.domain.coupon.service; | ||
|
||
import com.coolpeace.domain.coupon.dto.request.CouponDailyRequest; | ||
import com.coolpeace.domain.coupon.dto.response.CouponDailyResponse; | ||
import com.coolpeace.domain.coupon.entity.Coupon; | ||
import com.coolpeace.domain.coupon.entity.CouponDailyCondition; | ||
import com.coolpeace.domain.coupon.repository.CouponRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class CouponQueryService { | ||
|
||
private final CouponRepository couponRepository; | ||
|
||
/* 메소드 복잡도를 낮추는 방법 고안 중 */ | ||
public CouponDailyResponse dailyReport(CouponDailyRequest request) { | ||
Long memberId = request.memberId(); | ||
Long accommodationId = request.accommodationId(); | ||
|
||
if (couponRepository.noRegister(memberId, accommodationId)) { | ||
return CouponDailyResponse.from(CouponDailyCondition.NO_REGISTER); | ||
} | ||
if (couponRepository.noExposure(memberId, accommodationId)) { | ||
return CouponDailyResponse.from(CouponDailyCondition.NO_EXPOSURE); | ||
} | ||
|
||
List<Coupon> expiration3daysCoupons = couponRepository.expiration3days(memberId, accommodationId); | ||
if (!expiration3daysCoupons.isEmpty()) { | ||
return CouponDailyResponse.from(CouponDailyCondition.EXPIRATION_3DAYS, | ||
expiration3daysCoupons.stream().map(Coupon::getTitle).toList()); | ||
} | ||
|
||
List<Coupon> exposureCoupons = couponRepository.exposureCoupons(memberId, accommodationId); | ||
return CouponDailyResponse.from(CouponDailyCondition.NO_CONDITION, | ||
exposureCoupons.stream().map(Coupon::getTitle).toList()); | ||
} | ||
} |