Skip to content

Commit

Permalink
Merge pull request #518 from Travel-in-nanaland/refactor/#517-festiva…
Browse files Browse the repository at this point in the history
…l-response-ongoing

Refactor/#517 festival response ongoing
  • Loading branch information
Te-H0 authored Nov 25, 2024
2 parents 8c6e81c + a60aa14 commit 8f93d4b
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -33,6 +38,7 @@ public PostPreviewDto(PostPreviewDto postPreviewDto) {
this.title = postPreviewDto.getTitle();
this.category = postPreviewDto.getCategory();
this.firstImage = postPreviewDto.getFirstImage();
this.onGoing = postPreviewDto.getOnGoing();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +31,7 @@ public class FavoriteService {

private final FavoriteRepository favoriteRepository;
private final PostService postService;
private final FestivalRepository festivalRepository;

/**
* 모든 카테고리의 찜리스트 조회
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static class FestivalDetailDto {
@Schema(description = "7대 자연 게시물 id")
private Long id;

@Schema(description = "축제 진행 여부")
private boolean onGoing;

@Schema(description = "이미지 리스트")
private List<ImageFileDto> images;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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<Festival, Long>,
FestivalRepositoryCustom {

List<Festival> findAllByOnGoingAndEndDateBefore(boolean onGoing, LocalDate localDate);

List<Festival> findAllByEndDateBefore(LocalDate localDate);

@Query("SELECT f.onGoing FROM Festival f WHERE f.id = :id")
Boolean getFestivalOnGoingStatusById(@Param("id") Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,6 +73,7 @@ public FestivalCompositeDto findCompositeDtoByIdWithPessimisticLock(Long id, Lan
imageFile.originUrl,
imageFile.thumbnailUrl,
festival.contact,
festival.onGoing,
festival.homepage,
festivalTrans.language,
festivalTrans.title,
Expand Down Expand Up @@ -107,6 +109,7 @@ public Page<FestivalCompositeDto> searchCompositeDtoByKeyword(String keyword, La
imageFile.originUrl,
imageFile.thumbnailUrl,
festival.contact,
festival.onGoing,
festival.homepage,
festivalTrans.language,
festivalTrans.title,
Expand Down Expand Up @@ -183,6 +186,7 @@ public Page<FestivalCompositeDto> searchCompositeDtoByOnGoing(Language language,
imageFile.originUrl,
imageFile.thumbnailUrl,
festival.contact,
festival.onGoing,
festival.homepage,
festivalTrans.language,
festivalTrans.title,
Expand Down Expand Up @@ -232,6 +236,7 @@ public Page<FestivalCompositeDto> searchCompositeDtoBySeason(Language language,
imageFile.originUrl,
imageFile.thumbnailUrl,
festival.contact,
festival.onGoing,
festival.homepage,
festivalTrans.language,
festivalTrans.title,
Expand Down Expand Up @@ -279,6 +284,7 @@ public Page<FestivalCompositeDto> searchCompositeDtoByMonth(Language language, P
imageFile.originUrl,
imageFile.thumbnailUrl,
festival.contact,
festival.onGoing,
festival.homepage,
festivalTrans.language,
festivalTrans.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,8 @@ class FavoriteServiceTest {
FavoriteRepository favoriteRepository;
@Mock
PostService postService;
@Mock
FestivalRepository festivalRepository;

Random random = new Random();

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"봄");
Expand Down

0 comments on commit 8f93d4b

Please sign in to comment.