Skip to content

Commit

Permalink
Merge pull request #67 from lotteon2/hotfix
Browse files Browse the repository at this point in the history
✏️ 시작일과 종료일 기준으로 쿠폰의 유효성 판단
  • Loading branch information
nowgnas authored Jan 19, 2024
2 parents 44b911d + 8464338 commit 3fbd541
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Coupon> findAllValidateCouponsByStoreId(Long storeId, LocalDate now)
.selectFrom(coupon)
.where(
coupon.store.id.eq(storeId),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand Down Expand Up @@ -82,7 +82,7 @@ public List<CouponWithIssueStatusDto> findStoreCouponsForUser(Long userId, Long
.from(coupon)
.where(
coupon.store.id.eq(storeId),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand All @@ -106,7 +106,7 @@ public List<CouponWithAvailabilityDto> findAvailableCoupons(Long totalAmount, Lo
coupon.store.id.eq(storeId),
issuedCoupon.id.userId.eq(userId),
issuedCoupon.isUsed.isFalse(),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand All @@ -129,7 +129,7 @@ public List<CouponDto> findMyValidCoupons(Long userId, LocalDate now) {
.where(
issuedCoupon.id.userId.eq(userId),
issuedCoupon.isUsed.isFalse(),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetch();
Expand All @@ -145,14 +145,15 @@ public Integer findMyValidCouponCount(Long userId, LocalDate now) {
.where(
issuedCoupon.id.userId.eq(userId),
issuedCoupon.isUsed.isFalse(),
isCouponUnexpired(now),
isValidDate(now),
coupon.isDeleted.isFalse()
)
.fetchFirst());
}

private BooleanExpression isCouponUnexpired(LocalDate now) {
return coupon.endDate.after(now).or(coupon.endDate.eq(now));
private BooleanExpression isValidDate(LocalDate now) {
return coupon.startDate.before(now).or(coupon.startDate.eq(now))
.and(coupon.endDate.after(now).or(coupon.endDate.eq(now)));
}

}
4 changes: 4 additions & 0 deletions src/test/java/kr/bb/store/domain/RedisContainerTestEnv.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package kr.bb.store.domain;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers;

@Testcontainers
@SpringBootTest
@ActiveProfiles("test")
public class RedisContainerTestEnv {
static final String REDIS_IMAGE = "redis:6-alpine";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
import org.testcontainers.junit.jupiter.Testcontainers;

import javax.persistence.EntityManager;
import java.util.List;
Expand All @@ -26,8 +24,6 @@

import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers
@SpringBootTest
class CargoFacadeTest extends RedisContainerTestEnv {
@Autowired
private CargoFacade cargoFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.junit.jupiter.Testcontainers;

import javax.persistence.EntityManager;
import java.util.List;
Expand All @@ -27,8 +25,6 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;

@Testcontainers
@SpringBootTest
class CargoServiceTest extends RedisContainerTestEnv {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.time.LocalDate;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Testcontainers
@SpringBootTest
@Transactional
class CouponCreatorTest extends RedisContainerTestEnv {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
import kr.bb.store.domain.coupon.exception.ExpiredCouponException;
import kr.bb.store.domain.coupon.repository.CouponRepository;
import kr.bb.store.domain.coupon.repository.IssuedCouponRepository;
import kr.bb.store.util.RedisOperation;
import kr.bb.store.util.RedisUtils;
import kr.bb.store.domain.store.entity.Store;
import kr.bb.store.domain.store.repository.StoreRepository;
import kr.bb.store.util.RedisOperation;
import kr.bb.store.util.RedisUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.junit.jupiter.Testcontainers;

import javax.persistence.EntityManager;
import java.time.LocalDate;
Expand All @@ -27,8 +25,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Testcontainers
@SpringBootTest
@Transactional
class CouponIssuerTest extends RedisContainerTestEnv {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.junit.jupiter.Testcontainers;

import javax.persistence.EntityManager;
import java.time.LocalDate;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Testcontainers
@SpringBootTest
@Transactional
class CouponManagerTest extends RedisContainerTestEnv {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
Expand All @@ -24,7 +23,6 @@

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@Transactional
class CouponReaderTest extends RedisContainerTestEnv {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
import kr.bb.store.domain.coupon.exception.UnAuthorizedCouponException;
import kr.bb.store.domain.coupon.repository.CouponRepository;
import kr.bb.store.domain.coupon.repository.IssuedCouponRepository;
import kr.bb.store.util.RedisUtils;
import kr.bb.store.util.RedisOperation;
import kr.bb.store.domain.store.entity.Store;
import kr.bb.store.domain.store.repository.StoreRepository;
import kr.bb.store.util.RedisOperation;
import kr.bb.store.util.RedisUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -32,8 +30,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Testcontainers
@SpringBootTest
class CouponServiceTest extends RedisContainerTestEnv {
@Autowired
private CouponService couponService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import static org.assertj.core.api.Assertions.assertThat;


class QuestionReaderTest extends BasicIntegrationTestEnv {
@Autowired
private QuestionReader questionReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import static org.assertj.core.api.Assertions.assertThat;


class QuestionServiceTest extends BasicIntegrationTestEnv {
@Autowired
private QuestionService questionService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.List;
Expand All @@ -37,8 +35,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;

@SpringBootTest
@Transactional
class StoreFacadeTest extends BasicIntegrationTestEnv {
@Autowired
private StoreFacade storeFacade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@SpringBootTest
@Transactional
class GugunReaderTest extends BasicIntegrationTestEnv {
@Autowired
private GugunReader gugunReader;
Expand Down

0 comments on commit 3fbd541

Please sign in to comment.