Skip to content

Commit

Permalink
Merge pull request #57 from Travel-in-nanaland/feat/#22-nana-pick
Browse files Browse the repository at this point in the history
Feat/#22 nana pick
  • Loading branch information
heeeeeseok authored Apr 20, 2024
2 parents 0eb9e53 + b09ce0c commit ef4f453
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 17 deletions.
33 changes: 18 additions & 15 deletions src/main/java/com/jeju/nanaland/domain/nana/dto/NanaResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class NanaResponse {
public static class NanaThumbnailDto {

@Schema(description = "총 조회 개수")
private Long count;
private Long totalElements;

@Schema(description = "결과 데이터")
private List<NanaThumbnail> data;
Expand Down Expand Up @@ -59,12 +59,6 @@ public static class NanaDetailDto {
@Schema(description = "게시물 데이터")
private List<NanaDetail> nanaDetails;

@QueryProjection
public NanaDetailDto(String originUrl, String notice, List<NanaDetail> nanaDetails) {
this.originUrl = originUrl;
this.notice = notice;
this.nanaDetails = nanaDetails;
}
}

@Data
Expand All @@ -91,13 +85,22 @@ public static class NanaDetail {
@Schema(description = "게시물 설명")
public String content;

@QueryProjection
public NanaDetail(int number, String subTitle, String title, String imageUrl, String content) {
this.number = number;
this.subTitle = subTitle;
this.title = title;
this.imageUrl = imageUrl;
this.content = content;
}
public List<NanaAdditionalInfo> additionalInfoList;

public List<String> hashtags;

}

@Data
@Builder
@Schema(description = "나나's pick 각 게시글 부가 정보")
public static class NanaAdditionalInfo {

@Schema(description = "부가 정보 key 값 ex: 주차정보, 스페셜, 예약링크,,")
public String infoKey;

@Schema(description = "부가 정보 value 값")
public String infoValue;

}
}
26 changes: 26 additions & 0 deletions src/main/java/com/jeju/nanaland/domain/nana/entity/InfoType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jeju.nanaland.domain.nana.entity;

public enum InfoType {
ADDRESS("주소"),
PARKING("주차"),
SPECIAL("스페셜"),
AMENITY("편의시설"),
WEBSITE("홈페이지"),
RESERVATION_LINK("예약링크"),
AGE("이용연령"),
TIME("이용시간"),
FEE("이용요금"),
DATE("이용날짜"),
DESCRIPTION("소개");


private final String description;

InfoType(String description) {
this.description = description;
}

public String getDescription() {
return description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.jeju.nanaland.domain.nana.entity;

import com.jeju.nanaland.domain.common.entity.BaseEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@NoArgsConstructor
public class NanaAdditionalInfo extends BaseEntity {

@Enumerated(EnumType.STRING)
private InfoType infoType;

private String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotBlank;
import java.util.HashSet;
import java.util.Set;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -40,6 +44,13 @@ public class NanaContent extends BaseEntity {
@Column(columnDefinition = "TEXT")
private String content;

@ManyToMany
@JoinTable(name = "NANA_INFO_TYPE",
joinColumns = @JoinColumn(name = "nana_contet_id"),
inverseJoinColumns = @JoinColumn(name = "nana_additional_info_id")
)
private Set<NanaAdditionalInfo> infoList;

@Builder
public NanaContent(NanaTitle nanaTitle, ImageFile imageFile, int number, String subTitle,
String title, String content) {
Expand All @@ -49,5 +60,6 @@ public NanaContent(NanaTitle nanaTitle, ImageFile imageFile, int number, String
this.subTitle = subTitle;
this.title = title;
this.content = content;
this.infoList = new HashSet<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jeju.nanaland.domain.nana.dto.NanaResponse;
import com.jeju.nanaland.domain.nana.dto.NanaResponse.NanaThumbnail;
import com.jeju.nanaland.domain.nana.dto.NanaResponse.NanaThumbnailDto;
import com.jeju.nanaland.domain.nana.entity.NanaAdditionalInfo;
import com.jeju.nanaland.domain.nana.entity.NanaContent;
import com.jeju.nanaland.domain.nana.entity.NanaTitle;
import com.jeju.nanaland.domain.nana.repository.NanaContentRepository;
Expand All @@ -12,6 +13,7 @@
import com.jeju.nanaland.global.exception.BadRequestException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -47,28 +49,38 @@ public NanaThumbnailDto getNanaThumbnails(Locale locale, int page, int size) {

}
return NanaThumbnailDto.builder()
.count(resultDto.getTotalElements())
.totalElements(resultDto.getTotalElements())
.data(thumbnails)
.build();
}

//나나 상세 게시물
public NanaResponse.NanaDetailDto getNanaDetail(Long id) {
// nanaTitle 찾아서
NanaTitle nanaTitle = nanaTitleRepository.findNanaTitleById(id)
.orElseThrow(() -> new BadRequestException("존재하지 않는 Nana 컨텐츠 입니다."));

// nanaTitle에 맞는 게시물 조회
List<NanaContent> nanaContentList = nanaContentRepository.findAllByNanaTitleOrderByNumber(
nanaTitle);

List<NanaResponse.NanaDetail> nanaDetails = new ArrayList<>();

for (NanaContent nanaContent : nanaContentList) {

// TODO hashtag 기능 구현 시 꼭 수정하기!!!!
List<String> tmp = new ArrayList<>();
tmp.add("ex1");
tmp.add("ex2");
nanaDetails.add(
NanaResponse.NanaDetail.builder()
.number(nanaContent.getNumber())
.subTitle(nanaContent.getSubTitle())
.title(nanaContent.getTitle())
.imageUrl(nanaContent.getImageFile().getOriginUrl())
.content(nanaContent.getContent())
.additionalInfoList(getAdditionalInfoFromNanaContentEntity(nanaContent))
.hashtags(tmp)
.build());

}
Expand All @@ -80,4 +92,23 @@ public NanaResponse.NanaDetailDto getNanaDetail(Long id) {
.build();

}
}

// nanaContent의 AdditionalInfo dto로 바꾸기
public List<NanaResponse.NanaAdditionalInfo> getAdditionalInfoFromNanaContentEntity(
NanaContent nanaContent) {
Set<NanaAdditionalInfo> eachInfoList = nanaContent.getInfoList();

// 순서 보장 위해 List 형으로 바꾸고
List<NanaAdditionalInfo> nanaAdditionalInfos = new ArrayList<>(eachInfoList);

//DTO 형태로 변환
List<NanaResponse.NanaAdditionalInfo> result = new ArrayList<>();
for (NanaAdditionalInfo info : nanaAdditionalInfos) {
result.add(NanaResponse.NanaAdditionalInfo.builder()
.infoKey(info.getInfoType().getDescription())
.infoValue(info.getDescription())
.build());
}
return result;
}
}

0 comments on commit ef4f453

Please sign in to comment.