Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] #172 PlaceDetailInfo에 Review 좋아요, 싫어요수를 반영했어요 #183

Merged
merged 10 commits into from
Nov 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import team7.inplace.place.domain.Place;
import team7.inplace.place.persistence.PlaceRepository;
import team7.inplace.placeMessage.application.command.PlaceMessageCommand;
import team7.inplace.review.persistence.ReviewRepository;
import team7.inplace.security.util.AuthorizationUtil;
import team7.inplace.user.domain.User;
import team7.inplace.user.persistence.UserRepository;
Expand All @@ -46,6 +47,8 @@ public class PlaceService {

private final LikedPlaceRepository likedPlaceRepository;

private final ReviewRepository reviewRepository;

public Page<PlaceInfo> getPlacesWithinRadius(
PlacesCoordinateCommand placesCoordinateCommand,
PlacesFilterParamsCommand placesFilterParamsCommand) {
Expand Down Expand Up @@ -133,7 +136,11 @@ public PlaceDetailInfo getPlaceDetailInfo(Long placeId) {
video = videos.get(0);
}
Influencer influencer = (video != null) ? video.getInfluencer() : null;
return PlaceDetailInfo.from(place, influencer, video, isLikedPlace(place.getId()));

Integer numOfLikes = reviewRepository.countByPlaceIdAndIsLikedTrue(placeId);
Integer numOfDislikes = reviewRepository.countByPlaceIdAndIsLikedFalse(placeId);
dong-yxxn marked this conversation as resolved.
Show resolved Hide resolved
return PlaceDetailInfo.from(place, influencer, video, isLikedPlace(place.getId()),
numOfLikes, numOfDislikes);
}

public List<Long> createPlaces(List<Create> placeCommands) {
Expand Down
109 changes: 51 additions & 58 deletions src/main/java/team7/inplace/place/application/dto/PlaceDetailInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,38 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.time.LocalDateTime;
import java.util.List;
dong-yxxn marked this conversation as resolved.
Show resolved Hide resolved
import team7.inplace.influencer.domain.Influencer;
import team7.inplace.place.domain.Menu;
import team7.inplace.place.domain.OpenTime;
import team7.inplace.place.domain.Place;
import team7.inplace.video.domain.Video;

import java.time.LocalDateTime;
import java.util.List;

public record PlaceDetailInfo(
PlaceInfo placeInfo,
JsonNode facilityInfo,
MenuInfos menuInfos,
OpenHour openHour,
PlaceLikes placeLikes,
String videoUrl
PlaceInfo placeInfo,
JsonNode facilityInfo,
MenuInfos menuInfos,
OpenHour openHour,
PlaceLikes placeLikes,
String videoUrl
) {

public static PlaceDetailInfo from(Place place, Influencer influencer, Video video,
boolean isLiked) {
boolean isLiked, int numOfLikes, int numOfDislikes) {
String influencerName = (influencer != null) ? influencer.getName() : "";
String videoUrl = (video != null) ? video.getVideoUrl() : "";

return new PlaceDetailInfo(
PlaceInfo.of(place, influencerName, isLiked),
facilityTree(place.getFacility()),
MenuInfos.of(
place.getMenuboardphotourlList(),
place.getMenus(),
place.getMenuUpdatedAt()),
OpenHour.of(place.getOpenPeriods(), place.getOffDays()),
PlaceLikes.of(isLiked),
videoUrl
PlaceInfo.of(place, influencerName, isLiked),
facilityTree(place.getFacility()),
MenuInfos.of(
place.getMenuboardphotourlList(),
place.getMenus(),
place.getMenuUpdatedAt()),
OpenHour.of(place.getOpenPeriods(), place.getOffDays()),
PlaceLikes.of(numOfLikes, numOfDislikes),
videoUrl
);
}

Expand All @@ -58,86 +57,80 @@ private static JsonNode facilityTree(String facility) {
}

public record MenuInfos(
List<String> menuImgUrls,
List<MenuInfo> menuList,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
LocalDateTime timeExp
List<String> menuImgUrls,
List<MenuInfo> menuList,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
LocalDateTime timeExp
) {

public static MenuInfos of(
List<String> menuImgUrls,
List<Menu> menus,
LocalDateTime menuUpdatedAt) {
List<String> menuImgUrls,
List<Menu> menus,
LocalDateTime menuUpdatedAt) {

List<MenuInfo> menuList = menus.stream()
.map(menu -> new MenuInfo(menu.getPrice(), menu.isRecommend(),
menu.getMenuName(), menu.getMenuImgUrl(), menu.getDescription()))
.toList();
.map(menu -> new MenuInfo(menu.getPrice(), menu.isRecommend(),
menu.getMenuName(), menu.getMenuImgUrl(), menu.getDescription()))
.toList();

return new MenuInfos(menuImgUrls, menuList, menuUpdatedAt);
}

public record MenuInfo(
String price,
Boolean recommend,
String menuName,
String menuImgUrl,
String description
String price,
Boolean recommend,
String menuName,
String menuImgUrl,
String description
) {

}
}

public record OpenHour(
List<Period> periodList,
List<OffDay> offdayList
List<Period> periodList,
List<OffDay> offdayList
) {

public static OpenHour of(List<OpenTime> openTimes,
List<team7.inplace.place.domain.OffDay> closeTimes
List<team7.inplace.place.domain.OffDay> closeTimes
) {
List<Period> periods = openTimes.stream()
.map(time -> new Period(time.getTimeName(), time.getTimeSE(), time.getDayOfWeek()))
.toList();
.map(time -> new Period(time.getTimeName(), time.getTimeSE(), time.getDayOfWeek()))
.toList();

List<OffDay> offDays = closeTimes.stream()
.map(closeTime -> new OffDay(closeTime.getHolidayName(), closeTime.getWeekAndDay(),
closeTime.getTemporaryHolidays()))
.toList();
.map(closeTime -> new OffDay(closeTime.getHolidayName(), closeTime.getWeekAndDay(),
closeTime.getTemporaryHolidays()))
.toList();

return new OpenHour(periods, offDays);
}

public record Period(
String timeName,
String timeSE,
String dayOfWeek
String timeName,
String timeSE,
String dayOfWeek
) {

}

public record OffDay(
String holidayName,
String weekAndDay,
String temporaryHolidays
String holidayName,
String weekAndDay,
String temporaryHolidays
) {

}
}

public record PlaceLikes(
Integer like,
Integer dislike
Integer like,
Integer dislike
) {

public static PlaceLikes of(Boolean likes) {
if (likes == null) {
return new PlaceLikes(0, 0);
}
if (likes) {
return new PlaceLikes(1, 0);
}
return new PlaceLikes(0, 1);
public static PlaceLikes of(Integer numOfLikes, Integer numOfDislikes) {
return new PlaceLikes(numOfLikes, numOfDislikes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {

Page<Review> findByPlaceId(Long placeId, Pageable pageable);

Integer countByPlaceIdAndIsLikedTrue(Long placeId);

Integer countByPlaceIdAndIsLikedFalse(Long placeId);

@Query("SELECT r FROM Review r JOIN FETCH r.place WHERE r.user.id = :userId")
Page<Review> findByUserIdWithPlace(Long userId, Pageable pageable);
}
Loading