diff --git a/src/main/java/com/jeju/nanaland/domain/common/dto/PostPreviewDto.java b/src/main/java/com/jeju/nanaland/domain/common/dto/PostPreviewDto.java index 36717cb9..567c49cf 100644 --- a/src/main/java/com/jeju/nanaland/domain/common/dto/PostPreviewDto.java +++ b/src/main/java/com/jeju/nanaland/domain/common/dto/PostPreviewDto.java @@ -1,5 +1,6 @@ package com.jeju.nanaland.domain.common.dto; +import com.fasterxml.jackson.annotation.JsonInclude; import com.querydsl.core.annotations.QueryProjection; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -21,6 +22,10 @@ public class PostPreviewDto { @Schema(description = "썸네일 이미지") private ImageFileDto firstImage; + @Schema(description = "축제 진행 여부") + @JsonInclude(JsonInclude.Include.NON_NULL) + private Boolean onGoing; + @QueryProjection public PostPreviewDto(Long id, String title, String originUrl, String thumbnailUrl) { this.id = id; @@ -33,6 +38,7 @@ public PostPreviewDto(PostPreviewDto postPreviewDto) { this.title = postPreviewDto.getTitle(); this.category = postPreviewDto.getCategory(); this.firstImage = postPreviewDto.getFirstImage(); + this.onGoing = postPreviewDto.getOnGoing(); } diff --git a/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java b/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java index cd0a2dc9..36870ee9 100644 --- a/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java +++ b/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java @@ -6,8 +6,10 @@ import com.jeju.nanaland.domain.common.service.PostService; import com.jeju.nanaland.domain.favorite.dto.FavoriteRequest; import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse.PreviewDto; import com.jeju.nanaland.domain.favorite.entity.Favorite; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; +import com.jeju.nanaland.domain.festival.repository.FestivalRepository; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.domain.member.entity.Member; import java.util.List; @@ -29,6 +31,7 @@ public class FavoriteService { private final FavoriteRepository favoriteRepository; private final PostService postService; + private final FestivalRepository festivalRepository; /** * 모든 카테고리의 찜리스트 조회 @@ -56,7 +59,10 @@ public FavoriteResponse.PreviewPageDto getAllFavorites(MemberInfoDto memberInfoD Category category = favorite.getCategory(); Long postId = favorite.getPost().getId(); PostPreviewDto postPreviewDto = postService.getPostPreviewDto(postId, category, language); - return new FavoriteResponse.PreviewDto(postPreviewDto); + if (category == Category.FESTIVAL) { + setFestivalOnGoingStatus(postPreviewDto); + } + return new PreviewDto(postPreviewDto); }) .collect(Collectors.toList()); @@ -92,6 +98,9 @@ public FavoriteResponse.PreviewPageDto getAllCategoryFavorites(MemberInfoDto mem .map(favorite -> CompletableFuture.supplyAsync(() -> { Long postId = favorite.getPost().getId(); PostPreviewDto postPreviewDto = postService.getPostPreviewDto(postId, category, language); + if (category == Category.FESTIVAL) { + setFestivalOnGoingStatus(postPreviewDto); + } return new FavoriteResponse.PreviewDto(postPreviewDto); })) .toList(); @@ -167,4 +176,9 @@ public FavoriteResponse.StatusDto toggleLikeStatus(MemberInfoDto memberInfoDto, .build(); } } + + private void setFestivalOnGoingStatus(PostPreviewDto postPreviewDto) { + Long id = postPreviewDto.getId(); + postPreviewDto.setOnGoing(festivalRepository.getFestivalOnGoingStatusById(id)); + } } diff --git a/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalCompositeDto.java b/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalCompositeDto.java index 3b4bb72e..91ab8171 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalCompositeDto.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalCompositeDto.java @@ -14,6 +14,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class FestivalCompositeDto extends CompositeDto { + private boolean onGoing; private String homepage; private String intro; private String fee; @@ -23,10 +24,12 @@ public class FestivalCompositeDto extends CompositeDto { @QueryProjection public FestivalCompositeDto(Long id, String originUrl, String thumbnailUrl, String contact, + boolean onGoing, String homepage, Language locale, String title, String content, String address, String addressTag, String time, String intro, String fee, LocalDate startDate, LocalDate endDate, String season) { super(id, originUrl, thumbnailUrl, contact, locale, title, content, address, addressTag, time); + this.onGoing = onGoing; this.homepage = homepage; this.intro = intro; this.fee = fee; diff --git a/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalResponse.java b/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalResponse.java index 7b4ddac3..36215509 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalResponse.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/dto/FestivalResponse.java @@ -58,6 +58,9 @@ public static class FestivalDetailDto { @Schema(description = "7대 자연 게시물 id") private Long id; + @Schema(description = "축제 진행 여부") + private boolean onGoing; + @Schema(description = "이미지 리스트") private List images; diff --git a/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepository.java b/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepository.java index 34fc2a11..e933549b 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepository.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepository.java @@ -1,9 +1,11 @@ package com.jeju.nanaland.domain.festival.repository; import com.jeju.nanaland.domain.festival.entity.Festival; +import io.lettuce.core.dynamic.annotation.Param; import java.time.LocalDate; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface FestivalRepository extends JpaRepository, FestivalRepositoryCustom { @@ -11,4 +13,7 @@ public interface FestivalRepository extends JpaRepository, List findAllByOnGoingAndEndDateBefore(boolean onGoing, LocalDate localDate); List findAllByEndDateBefore(LocalDate localDate); + + @Query("SELECT f.onGoing FROM Festival f WHERE f.id = :id") + Boolean getFestivalOnGoingStatusById(@Param("id") Long id); } diff --git a/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepositoryImpl.java b/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepositoryImpl.java index 09ccf90b..d4d94633 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepositoryImpl.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/repository/FestivalRepositoryImpl.java @@ -42,6 +42,7 @@ public FestivalCompositeDto findCompositeDtoById(Long id, Language language) { imageFile.originUrl, imageFile.thumbnailUrl, festival.contact, + festival.onGoing, festival.homepage, festivalTrans.language, festivalTrans.title, @@ -72,6 +73,7 @@ public FestivalCompositeDto findCompositeDtoByIdWithPessimisticLock(Long id, Lan imageFile.originUrl, imageFile.thumbnailUrl, festival.contact, + festival.onGoing, festival.homepage, festivalTrans.language, festivalTrans.title, @@ -107,6 +109,7 @@ public Page searchCompositeDtoByKeyword(String keyword, La imageFile.originUrl, imageFile.thumbnailUrl, festival.contact, + festival.onGoing, festival.homepage, festivalTrans.language, festivalTrans.title, @@ -183,6 +186,7 @@ public Page searchCompositeDtoByOnGoing(Language language, imageFile.originUrl, imageFile.thumbnailUrl, festival.contact, + festival.onGoing, festival.homepage, festivalTrans.language, festivalTrans.title, @@ -232,6 +236,7 @@ public Page searchCompositeDtoBySeason(Language language, imageFile.originUrl, imageFile.thumbnailUrl, festival.contact, + festival.onGoing, festival.homepage, festivalTrans.language, festivalTrans.title, @@ -279,6 +284,7 @@ public Page searchCompositeDtoByMonth(Language language, P imageFile.originUrl, imageFile.thumbnailUrl, festival.contact, + festival.onGoing, festival.homepage, festivalTrans.language, festivalTrans.title, diff --git a/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java b/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java index 1790d3d9..716ec7a7 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java @@ -169,6 +169,7 @@ public FestivalDetailDto getFestivalDetail(MemberInfoDto memberInfoDto, Long id, return FestivalDetailDto.builder() .id(compositeDtoById.getId()) + .onGoing(compositeDtoById.isOnGoing()) .addressTag(compositeDtoById.getAddressTag()) .title(compositeDtoById.getTitle()) .content(compositeDtoById.getContent()) @@ -262,7 +263,7 @@ private String formatLocalDateToStringWithoutDayOfWeek(MemberInfoDto memberInfoD LocalDate startDate, LocalDate endDate) { // - 을 . 으로 대체 - String nationalDateFormat = memberInfoDto.getLanguage().getDateFormat().replace("-", ". "); + String nationalDateFormat = memberInfoDto.getLanguage().getDateFormat().replace("-", "."); // yyyy 포맷을 yy로 변경 String finalDateFormat = nationalDateFormat.replace("yyyy", "yy"); diff --git a/src/test/java/com/jeju/nanaland/domain/favorite/service/FavoriteServiceTest.java b/src/test/java/com/jeju/nanaland/domain/favorite/service/FavoriteServiceTest.java index c0dd9e0e..cc6c340a 100644 --- a/src/test/java/com/jeju/nanaland/domain/favorite/service/FavoriteServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/favorite/service/FavoriteServiceTest.java @@ -19,6 +19,7 @@ import com.jeju.nanaland.domain.favorite.entity.Favorite; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; import com.jeju.nanaland.domain.festival.entity.Festival; +import com.jeju.nanaland.domain.festival.repository.FestivalRepository; import com.jeju.nanaland.domain.market.entity.Market; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.domain.member.entity.Member; @@ -61,6 +62,8 @@ class FavoriteServiceTest { FavoriteRepository favoriteRepository; @Mock PostService postService; + @Mock + FestivalRepository festivalRepository; Random random = new Random(); @@ -124,6 +127,7 @@ void getAllFavoritesTest() { when(postService.getPostPreviewDto(nullable(Long.class), any(Category.class), eq(Language.KOREAN))) .thenReturn(PostPreviewDto.builder().build()); + when(festivalRepository.getFestivalOnGoingStatusById(nullable(Long.class))).thenReturn(true); // when FavoriteResponse.PreviewPageDto result = favoriteService.getAllFavorites(memberInfoDto, 0, diff --git a/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java b/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java index 8c324c85..bcff37a0 100644 --- a/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java @@ -172,7 +172,7 @@ MemberInfoDto createMemberInfoDto(Member member, Language language) { FestivalCompositeDto createFestivalCompositeDto(Language locale, LocalDate startDate, LocalDate endDate) { - return new FestivalCompositeDto(1L, "url", "url", "contact", "home", + return new FestivalCompositeDto(1L, "url", "url", "contact", true, "home", locale, "title", "content", "address", "addressTag", "time", "intro", "fee", startDate, endDate, "봄");