Skip to content

Commit

Permalink
[#22] feat: NanaAdditionalInfo 생성, InfoType 생성, nanaService 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-H0 committed Apr 19, 2024
1 parent 6dc05c6 commit 4f3fab5
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/main/java/com/jeju/nanaland/domain/nana/dto/NanaResponse.java
Original file line number Diff line number Diff line change
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,20 @@ 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;

}

@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 @@ -54,8 +56,11 @@ public NanaThumbnailDto getNanaThumbnails(Locale locale, int page, int size) {

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

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

Expand All @@ -69,6 +74,7 @@ public NanaResponse.NanaDetailDto getNanaDetail(Long id) {
.title(nanaContent.getTitle())
.imageUrl(nanaContent.getImageFile().getOriginUrl())
.content(nanaContent.getContent())
.additionalInfoList(getAdditionalInfoFromNanaContentEntity(nanaContent))
.build());

}
Expand All @@ -80,4 +86,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 4f3fab5

Please sign in to comment.