Skip to content

Commit

Permalink
feat: 축제기간이 지난 축제는 인기 축제로 반환되지 않도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
BGuga committed May 16, 2024
1 parent 7351ae4 commit 4a47d1e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.festago.festival.dto.FestivalV1Response;
import com.festago.festival.dto.PopularFestivalsV1Response;
import com.festago.festival.repository.PopularFestivalV1QueryDslRepository;
import java.time.Clock;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -14,9 +16,10 @@
public class PopularFestivalV1QueryService {

private final PopularFestivalV1QueryDslRepository popularFestivalRepository;
private final Clock clock;

public PopularFestivalsV1Response findPopularFestivals() {
List<FestivalV1Response> popularFestivals = popularFestivalRepository.findPopularFestivals();
List<FestivalV1Response> popularFestivals = popularFestivalRepository.findPopularFestivals(LocalDate.now(clock));
return new PopularFestivalsV1Response(
"요즘 뜨는 축제",
popularFestivals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.festago.festival.dto.FestivalV1Response;
import com.festago.festival.dto.QFestivalV1Response;
import com.festago.festival.dto.QSchoolV1Response;
import java.time.LocalDate;
import java.util.List;
import org.springframework.stereotype.Repository;

Expand All @@ -24,7 +25,7 @@ public PopularFestivalV1QueryDslRepository() {
/**
* 아직 명확한 추천 축제 기준이 없으므로 생성 시간(식별자) 내림차순으로 반환하도록 함
*/
public List<FestivalV1Response> findPopularFestivals() {
public List<FestivalV1Response> findPopularFestivals(LocalDate now) {
return select(new QFestivalV1Response(
festival.id,
festival.name,
Expand All @@ -38,7 +39,8 @@ public List<FestivalV1Response> findPopularFestivals() {
festivalQueryInfo.artistInfo)
)
.from(festival)
.where(festivalQueryInfo.artistInfo.ne("[]"))
.where(festivalQueryInfo.artistInfo.ne("[]")
.and(festival.festivalDuration.endDate.goe(now)))
.innerJoin(school).on(school.id.eq(festival.school.id))
.innerJoin(festivalQueryInfo).on(festivalQueryInfo.festivalId.eq(festival.id))
.orderBy(festival.id.desc())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.festago.support.fixture.FestivalFixture;
import com.festago.support.fixture.FestivalQueryInfoFixture;
import com.festago.support.fixture.SchoolFixture;
import java.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand Down Expand Up @@ -47,26 +48,31 @@ class PopularFestivalV1QueryServiceIntegrationTest extends ApplicationIntegratio
Festival 여덟번째로_저장된_축제;
Festival 아홉번째로_저장된_공연없는_축제;
Festival 열번째로_저장된_공연없는_축제;
Festival 열한번쨰로_저장된_기간이_지난_축제;

@BeforeEach
void setUp() {
대학교 = schoolRepository.save(SchoolFixture.builder().build());

첫번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
두번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
세번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
네번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
다섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
여섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
일곱번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
여덟번째로_저장된_축제 = createFestivalWithFilledFestivalInfo();
아홉번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo();
열번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo();
LocalDate startDate = LocalDate.now();;
LocalDate endDate = startDate.plusDays(3);

첫번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
두번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
세번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
네번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
다섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
여섯번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
일곱번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
여덟번째로_저장된_축제 = createFestivalWithFilledFestivalInfo(startDate, endDate);
아홉번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo(startDate, endDate);
열번째로_저장된_공연없는_축제 = createFestivalWithEmptyFestivalInfo(startDate, endDate);
열한번쨰로_저장된_기간이_지난_축제 = createFestivalWithFilledFestivalInfo(startDate.minusDays(10L), endDate.minusDays(13L));
}

private Festival createFestivalWithFilledFestivalInfo() {
Festival festival = festivalRepository.save(FestivalFixture.builder().school(대학교).build());
festivalInfoRepository.save(makeBaseFixture(festival)
private Festival createFestivalWithFilledFestivalInfo(LocalDate startDate, LocalDate endDate) {
Festival festival = festivalRepository.save(makeBaseFestivalFixture(startDate, endDate));
festivalInfoRepository.save(makeBaseFestivalInfoFixture(festival)
.artistInfo("""
{
notEmpty
Expand All @@ -76,14 +82,22 @@ private Festival createFestivalWithFilledFestivalInfo() {
return festival;
}

private FestivalQueryInfoFixture makeBaseFixture(Festival festival) {
private Festival makeBaseFestivalFixture(LocalDate startDate, LocalDate endDate) {
return FestivalFixture.builder()
.school(대학교)
.startDate(startDate)
.endDate(endDate)
.build();
}

private FestivalQueryInfoFixture makeBaseFestivalInfoFixture(Festival festival) {
return FestivalQueryInfoFixture.builder()
.festivalId(festival.getId());
}

private Festival createFestivalWithEmptyFestivalInfo() {
Festival festival = festivalRepository.save(FestivalFixture.builder().school(대학교).build());
festivalInfoRepository.save(makeBaseFixture(festival)
private Festival createFestivalWithEmptyFestivalInfo(LocalDate startDate, LocalDate endDate) {
Festival festival = festivalRepository.save(makeBaseFestivalFixture(startDate, endDate));
festivalInfoRepository.save(makeBaseFestivalInfoFixture(festival)
.build());
return festival;
}
Expand All @@ -106,4 +120,17 @@ private Festival createFestivalWithEmptyFestivalInfo() {
두번째로_저장된_축제.getId()
);
}

@Test
void 축제_기간이_끝난_축제는_반환되지_않는다() {
// when
var expect = popularQueryService.findPopularFestivals().content();

// then
assertThat(expect)
.map(FestivalV1Response::id)
.doesNotContain(
열한번쨰로_저장된_기간이_지난_축제.getId()
);
}
}

0 comments on commit 4a47d1e

Please sign in to comment.