Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ public ResponseEntity<?> saveList(@RequestBody List<ContentRequest> requests) {
}

@GetMapping("/placedetail")
public ResponseEntity<PlaceDetailResponse> getPlaceDetail(@RequestParam int contentId, @AuthenticationPrincipal String principal){
public ResponseEntity<PlaceDetailResponse> getPlaceDetail(
@RequestParam int contentId,
@AuthenticationPrincipal String principal,
@RequestParam int contentTypeId){

String userId = null;
if (StringUtils.hasText(principal) && NumberUtils.isCreatable(principal)) {
userId = principal;
}

PlaceDetailResponse placeDetailResponse = contentService.getPlaceDetail(contentId,userId);
PlaceDetailResponse placeDetailResponse = contentService.getPlaceDetail(contentId,userId,contentTypeId);
return ResponseEntity.ok(placeDetailResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ ResponseEntity<PlaceDetailResponse> getPlaceDetail(
@RequestParam int contentId,

@Parameter(hidden = true)
@AuthenticationPrincipal String principal
@AuthenticationPrincipal String principal,

@Parameter(description = "컨텐츠 카테고리 ID", required = true)
@RequestParam int contentTypeId
);

@Operation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.swyp.catsgotogedog.content.domain.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.swyp.catsgotogedog.content.domain.entity.Content;
import com.swyp.catsgotogedog.pet.domain.entity.PetGuide;
import com.swyp.catsgotogedog.pet.domain.response.PetGuideResponse;
import lombok.Builder;

import java.util.List;
import java.util.Map;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

@JsonInclude(NON_NULL)
@Builder
public record PlaceDetailResponse(
int contentId,
Expand All @@ -31,7 +36,9 @@ public record PlaceDetailResponse(
String overview,
List<ContentImageResponse> detailImage,
PetGuide petGuide,
String restDate) {
String restDate,
Map<String, Object> additionalInformation
) {

public static PlaceDetailResponse from(
Content c,
Expand All @@ -42,7 +49,9 @@ public static PlaceDetailResponse from(
int totalView,
List<ContentImageResponse> detailImage,
PetGuide petGuide,
String restDate){
String restDate,
Map<String, Object> additionalInformation
){

return PlaceDetailResponse.builder()
.contentId(c.getContentId())
Expand All @@ -68,6 +77,7 @@ public static PlaceDetailResponse from(
.detailImage(detailImage)
.petGuide(petGuide)
.restDate(restDate)
.additionalInformation(additionalInformation)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import com.swyp.catsgotogedog.content.domain.entity.batch.information.FestivalInformation;

public interface FestivalInformationRepository extends JpaRepository<FestivalInformation, Integer> {
FestivalInformation findByContent_ContentId(int contentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
import com.swyp.catsgotogedog.content.domain.entity.batch.information.LodgeInformation;

public interface LodgeInformationRepository extends JpaRepository<LodgeInformation, Integer> {
LodgeInformation findByContent_ContentId(int contentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public interface RestaurantInformationRepository extends JpaRepository<Restauran
WHERE r.content.contentId IN :contentIds
""")
List<RestDateProjection> findRestDateByContentIdIn(List<Integer> contentIds);

RestaurantInformation findByContent_ContentId(int contentId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface SightsInformationRepository extends JpaRepository<SightsInforma
""")
List<RestDateProjection> findRestDateByContentIdIn(List<Integer> contentIds);

SightsInformation findByContent_ContentId(int contentId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import com.swyp.catsgotogedog.User.domain.entity.User;
import com.swyp.catsgotogedog.User.repository.UserRepository;
import com.swyp.catsgotogedog.content.domain.entity.*;
import com.swyp.catsgotogedog.content.domain.entity.batch.information.FestivalInformation;
import com.swyp.catsgotogedog.content.domain.entity.batch.information.LodgeInformation;
import com.swyp.catsgotogedog.content.domain.entity.batch.information.RestaurantInformation;
import com.swyp.catsgotogedog.content.domain.entity.batch.information.SightsInformation;
import com.swyp.catsgotogedog.content.domain.request.ContentRequest;
import com.swyp.catsgotogedog.content.domain.response.ContentImageResponse;
import com.swyp.catsgotogedog.content.domain.response.LastViewHistoryResponse;
Expand All @@ -23,8 +27,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Optional;
import java.util.*;

import static java.time.LocalDateTime.now;

Expand All @@ -43,6 +46,10 @@ public class ContentService {
private final VisitHistoryRepository visitHistoryRepository;
private final PetGuideRepository petGuideRepository;
private final LastViewHistoryRepository lastViewHistoryRepository;
private final LodgeInformationRepository lodgeInformationRepository;
private final RestaurantInformationRepository restaurantInformationRepository;
private final SightsInformationRepository sightsInformationRepository;
private final FestivalInformationRepository festivalInformationRepository;

private final ContentSearchService contentSearchService;

Expand All @@ -66,16 +73,15 @@ public void saveContent(ContentRequest request){
contentElasticRepository.save(ContentDocument.from(content));
}

public PlaceDetailResponse getPlaceDetail(int contentId, String userId){
public PlaceDetailResponse getPlaceDetail(int contentId, String userId, int contentTypeId){

// 카테고리 공통
viewTotalRepository.upsertAndIncrease(contentId);

if(userId != null){
recordView(userId, contentId);
}

Content content = contentRepository.findByContentId(contentId);

double avg = contentSearchService.getAverageScore(contentId);

boolean wishData = (userId != null) ? contentSearchService.getWishData(userId, contentId) : false;
Expand All @@ -87,14 +93,28 @@ public PlaceDetailResponse getPlaceDetail(int contentId, String userId){
int totalView = viewTotalRepository.findTotalViewByContentId(contentId)
.orElse(0);

List<ContentImageResponse> detailImage = getDetailImage(contentId);

PetGuide petGuide = getPetGuide(contentId)
.orElse(null);

List<ContentImageResponse> detailImage = getDetailImage(contentId);

String restDate = contentSearchService.getRestDate(contentId);

return PlaceDetailResponse.from(content,avg,wishData,wishCnt,visited,totalView,detailImage,petGuide,restDate);
Content content = contentRepository.findByContentId(contentId);

Map<String, Object> additional = getAdditionalInfo(contentId,contentTypeId);

return PlaceDetailResponse.from(
content,
avg,
wishData,
wishCnt,
visited,
totalView,
detailImage,
petGuide,
restDate,
additional);
}

public boolean checkWish(String userId, int contentId){
Expand Down Expand Up @@ -255,4 +275,142 @@ private Content validateContent(int contentId) {
.orElseThrow(() -> new CatsgotogedogException(ErrorCode.CONTENT_NOT_FOUND));
}

private Map<String, Object> getAdditionalInfo(int contentId, int contentTypeId) {
return switch (contentTypeId) {
case 15 -> getFestivalInfo(contentId);
case 32 -> getLodgeInfo(contentId);
case 39 -> getRestaurantInfo(contentId);
case 12 -> getSightsInfo(contentId);
default -> Map.of();
};
}

private Map<String, Object> getFestivalInfo(int contentId) {
var e = festivalInformationRepository.findByContent_ContentId(contentId);

if (e == null) return Map.of("type", "FESTIVAL");

var m = new HashMap<String, Object>();

m.put("type", "FESTIVAL");
m.put("festivalId", e.getFestivalId());
m.put("ageLimit", e.getAgeLimit());
m.put("bookingPlace", e.getBookingPlace());
m.put("discountInfo", e.getDiscountInfo());
m.put("eventStartDate", e.getEventStartDate());
m.put("eventEndDate", e.getEventEndDate());
m.put("eventHomepage", e.getEventHomepage());
m.put("eventPlace", e.getEventPlace());
m.put("placeInfo", e.getPlaceInfo());
m.put("playTime", e.getPlayTime());
m.put("program", e.getProgram());
m.put("spendTime", e.getSpendTime());
m.put("organizer", e.getOrganizer());
m.put("organizerTel", e.getOrganizerTel());
m.put("supervisor", e.getSupervisor());
m.put("supervisorTel", e.getSupervisorTel());
m.put("subEvent", e.getSubEvent());
m.put("feeInfo", e.getFeeInfo());

return m;
}

private Map<String, Object> getLodgeInfo(int contentId) {
var e = lodgeInformationRepository.findByContent_ContentId(contentId);

if (e == null) return Map.of("type", "LODGE");

var m = new HashMap<String, Object>();

m.put("type", "LODGE");
m.put("lodgeId", e.getLodgeId());
m.put("capacityCount", e.getCapacityCount());
m.put("goodstay", e.getGoodstay());
m.put("benikia", e.getBenikia());
m.put("checkInTime", e.getCheckInTime());
m.put("checkOutTime", e.getCheckOutTime());
m.put("cooking", e.getCooking());
m.put("foodplace", e.getFoodplace());
m.put("hanok", e.getHanok());
m.put("information", e.getInformation());
m.put("parking", e.getParking());
m.put("pickupService", e.getPickupService());
m.put("roomCount", e.getRoomCount());
m.put("reservationInfo", e.getReservationInfo());
m.put("reservationUrl", e.getReservationUrl());
m.put("roomType", e.getRoomType());
m.put("scale", e.getScale());
m.put("subFacility", e.getSubFacility());
m.put("barbecue", e.getBarbecue());
m.put("beauty", e.getBeauty());
m.put("beverage", e.getBeverage());
m.put("bicycle", e.getBicycle());
m.put("campfire", e.getCampfire());
m.put("fitness", e.getFitness());
m.put("karaoke", e.getKaraoke());
m.put("publicBath", e.getPublicBath());
m.put("publicPcRoom", e.getPublicPcRoom());
m.put("sauna", e.getSauna());
m.put("seminar", e.getSeminar());
m.put("sports", e.getSports());
m.put("refundRegulation", e.getRefundRegulation());

return m;
}

private Map<String, Object> getRestaurantInfo(int contentId) {
var e = restaurantInformationRepository.findByContent_ContentId(contentId);

if (e == null) return Map.of("type", "RESTAURANT");

var m = new HashMap<String, Object>();

m.put("type", "RESTAURANT");
m.put("restaurantId", e.getRestaurantId());
m.put("chkCreditcard", e.getChkCreditcard());
m.put("discountInfo", e.getDiscountInfo());
m.put("signatureMenu", e.getSignatureMenu());
m.put("information", e.getInformation());
m.put("kidsFacility", e.getKidsFacility());
m.put("openDate", e.getOpenDate());
m.put("openTime", e.getOpenTime());
m.put("takeout", e.getTakeout());
m.put("parking", e.getParking());
m.put("reservation", e.getReservation());
m.put("restDate", e.getRestDate());
m.put("scale", e.getScale());
m.put("seat", e.getSeat());
m.put("smoking", e.getSmoking());
m.put("treatMenu", e.getTreatMenu());

return m;
}

private Map<String, Object> getSightsInfo(int contentId) {
var e = sightsInformationRepository.findByContent_ContentId(contentId);

if (e == null) return Map.of("type", "SIGHTS");

var m = new HashMap<String, Object>();

m.put("type", "SIGHTS");
m.put("sightsId", e.getSightsId());
m.put("contentTypeId", e.getContentTypeId());
m.put("accomCount", e.getAccomCount());
m.put("chkCreditcard", e.getChkCreditcard());
m.put("expAgeRange", e.getExpAgeRange());
m.put("expGuide", e.getExpGuide());
m.put("infoCenter", e.getInfoCenter());
m.put("openDate", e.getOpenDate());
m.put("parking", e.getParking());
m.put("restDate", e.getRestDate());
m.put("useSeason", e.getUseSeason());
m.put("useTime", e.getUseTime());
m.put("heritage1", e.getHeritage1());
m.put("heritage2", e.getHeritage2());
m.put("heritage3", e.getHeritage3());

return m;
}

}