Skip to content

Commit

Permalink
Merge branch 'main' into feat/BSVR-232
Browse files Browse the repository at this point in the history
# Conflicts:
#	usecase/src/main/java/org/depromeet/spot/usecase/service/review/ReadReviewService.java
#	usecase/src/main/java/org/depromeet/spot/usecase/service/review/scrap/ReviewScrapService.java
  • Loading branch information
wjdwnsdnjs13 committed Aug 26, 2024
2 parents d6e30e6 + f743b8f commit d4bbaf3
Show file tree
Hide file tree
Showing 28 changed files with 416 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.depromeet.spot.application.review.dto.request.MyReviewRequest;
import org.depromeet.spot.application.review.dto.response.BaseReviewResponse;
import org.depromeet.spot.application.review.dto.response.BlockReviewListResponse;
import org.depromeet.spot.application.review.dto.response.MemberInfoOnMyReviewResponse;
import org.depromeet.spot.application.review.dto.response.MyRecentReviewResponse;
import org.depromeet.spot.application.review.dto.response.MyReviewListResponse;
import org.depromeet.spot.application.review.dto.response.ReviewMonthsResponse;
import org.depromeet.spot.domain.review.Review.ReviewType;
import org.depromeet.spot.domain.review.ReviewYearMonth;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase.BlockReviewListResult;
Expand Down Expand Up @@ -41,6 +43,7 @@ public class ReadReviewController {
@GetMapping("/stadiums/{stadiumId}/blocks/{blockCode}/reviews")
@Operation(summary = "특정 야구장의 특정 블록에 대한 리뷰 목록을 조회한다.")
public BlockReviewListResponse findReviewsByBlockId(
@Parameter(hidden = true) Long memberId,
@PathVariable("stadiumId")
@NotNull
@Positive
Expand All @@ -52,6 +55,7 @@ public BlockReviewListResponse findReviewsByBlockId(

BlockReviewListResult result =
readReviewUsecase.findReviewsByStadiumIdAndBlockCode(
memberId,
stadiumId,
blockCode,
request.rowNumber(),
Expand All @@ -65,16 +69,38 @@ public BlockReviewListResponse findReviewsByBlockId(
result, request.rowNumber(), request.seatNumber(), request.year(), request.month());
}

@CurrentMember
@ResponseStatus(HttpStatus.OK)
@GetMapping("/reviews/recentReview")
@Operation(summary = "자신이 작성한 가장 최근 리뷰 1개를 조회한다.")
public MyRecentReviewResponse findMyRecentReview(@Parameter(hidden = true) Long memberId) {

MyRecentReviewResult result = readReviewUsecase.findLastReviewByMemberId(memberId);
return MyRecentReviewResponse.from(result);
}

@CurrentMember
@ResponseStatus(HttpStatus.OK)
@GetMapping("/reviews/months")
@Operation(summary = "리뷰가 작성된 년도와 월 정보를 조회한다.")
public ReviewMonthsResponse findReviewMonths(@Parameter(hidden = true) Long memberId) {
public ReviewMonthsResponse findReviewMonths(
@Parameter(hidden = true) Long memberId,
@Parameter(description = "리뷰 타입: VIEW/FEED") ReviewType reviewType) {

List<ReviewYearMonth> yearMonths = readReviewUsecase.findReviewMonths(memberId);
List<ReviewYearMonth> yearMonths = readReviewUsecase.findReviewMonths(memberId, reviewType);
return ReviewMonthsResponse.from(yearMonths);
}

@CurrentMember
@ResponseStatus(HttpStatus.OK)
@GetMapping("/reviews/userInfo")
@Operation(summary = "사용자의 리뷰 관련 정보를 조회한다.")
public MemberInfoOnMyReviewResponse findMemberInfoOnMyReview(
@Parameter(hidden = true) Long memberId) {
return MemberInfoOnMyReviewResponse.from(
readReviewUsecase.findMemberInfoOnMyReview(memberId));
}

@CurrentMember
@ResponseStatus(HttpStatus.OK)
@GetMapping("/reviews")
Expand All @@ -92,20 +118,11 @@ public MyReviewListResponse findMyReviews(
request.month(),
request.cursor(),
request.sortBy(),
request.size());
request.size(),
request.reviewType());
return MyReviewListResponse.from(result, request.year(), request.month());
}

@CurrentMember
@ResponseStatus(HttpStatus.OK)
@GetMapping("/reviews/recentReview")
@Operation(summary = "자신이 작성한 가장 최근 리뷰 1개를 조회한다.")
public MyRecentReviewResponse findMyRecentReview(@Parameter(hidden = true) Long memberId) {

MyRecentReviewResult result = readReviewUsecase.findLastReviewByMemberId(memberId);
return MyRecentReviewResponse.from(result);
}

@CurrentMember
@ResponseStatus(HttpStatus.OK)
@GetMapping("/reviews/{reviewId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;

import org.depromeet.spot.domain.review.Review.ReviewType;
import org.depromeet.spot.domain.review.Review.SortCriteria;

import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -12,4 +13,5 @@ public record MyReviewRequest(
@Min(1) @Max(12) @Parameter(description = "월 (1-12)") Integer month,
@Parameter(description = "다음 페이지 커서") String cursor,
@Parameter(description = "정렬 기준", example = "DATE_TIME") SortCriteria sortBy,
@Parameter(description = "페이지 크기") Integer size) {}
@Parameter(description = "페이지 크기") Integer size,
@Parameter(description = "리뷰 타입: VIEW/FEED") ReviewType reviewType) {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public record BaseReviewResponse(
List<KeywordResponse> keywords,
int likesCount,
int scrapsCount,
ReviewType reviewType) {
ReviewType reviewType,
boolean isLiked,
boolean isScrapped) {

public static BaseReviewResponse from(CreateReviewResult result) {
Review review = result.review();
Expand Down Expand Up @@ -59,7 +61,9 @@ public static BaseReviewResponse from(CreateReviewResult result) {
.toList(),
review.getLikesCount(),
review.getScrapsCount(),
review.getReviewType());
review.getReviewType(),
review.isLiked(),
review.isScrapped());
}

public static BaseReviewResponse from(Review review) {
Expand Down Expand Up @@ -89,7 +93,9 @@ public static BaseReviewResponse from(Review review) {
.collect(Collectors.toList()),
review.getLikesCount(),
review.getScrapsCount(),
review.getReviewType());
review.getReviewType(),
review.isLiked(),
review.isScrapped());
}

public record StadiumResponse(Long id, String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.depromeet.spot.application.review.dto.response;

import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase.MemberInfoOnMyReviewResult;

import lombok.Builder;

@Builder
public record MemberInfoOnMyReviewResponse(
Long userId,
String profileImageUrl,
Integer level,
String levelTitle,
String nickname,
Long reviewCount,
Long totalLikes,
Long teamId,
String teamName) {
public static MemberInfoOnMyReviewResponse from(MemberInfoOnMyReviewResult result) {
return MemberInfoOnMyReviewResponse.builder()
.userId(result.userId())
.profileImageUrl(result.profileImageUrl())
.level(result.level())
.levelTitle(result.levelTitle())
.nickname(result.nickname())
.reviewCount(result.reviewCount())
.totalLikes(result.totalLikes())
.teamId(result.teamId())
.teamName(result.teamName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@

import org.depromeet.spot.application.review.dto.response.BlockReviewListResponse.BlockFilter;
import org.depromeet.spot.domain.review.Review;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase.MemberInfoOnMyReviewResult;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase.MyReviewListResult;

public record MyReviewListResponse(
MemberInfoOnMyReviewResult memberInfoOnMyReview,
List<MyReviewResponse> reviews,
String nextCursor,
boolean hasNext,
BlockFilter filter) {
List<MyReviewResponse> reviews, String nextCursor, boolean hasNext, BlockFilter filter) {

public static MyReviewListResponse from(
MyReviewListResult result, Integer year, Integer month) {
Expand All @@ -22,12 +17,7 @@ public static MyReviewListResponse from(
result.reviews().stream().map(MyReviewResponse::from).collect(Collectors.toList());
BlockFilter filter = new BlockFilter(null, null, year, month);

return new MyReviewListResponse(
result.memberInfoOnMyReviewResult(),
reviews,
result.nextCursor(),
result.hasNext(),
filter);
return new MyReviewListResponse(reviews, result.nextCursor(), result.hasNext(), filter);
}

public record MyReviewResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import org.depromeet.spot.usecase.port.in.review.scrap.ReviewScrapUsecase.MyScrapListResult;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -51,8 +49,8 @@ public boolean toggleScrap(
description = "stadiumId, months, good, bad로 필터링 가능하다.")
public MyScrapListResponse findMyReviews(
@Parameter(hidden = true) Long memberId,
@RequestBody @Valid MyScrapRequest request,
@ModelAttribute @Valid PageRequest pageRequest) {
@Valid MyScrapRequest request,
@Valid PageRequest pageRequest) {

MyScrapListResult result =
reviewScrapUsecase.findMyScrappedReviews(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public enum SortCriteria {

public static final int DEFAULT_LIKE_COUNT = 0;
public static final int DEFAULT_SCRAPS_COUNT = 0;
public boolean isLiked;
public boolean isScrapped;

@Builder
public Review(
Expand Down Expand Up @@ -142,6 +144,11 @@ public void setDeletedAt(LocalDateTime now) {
this.deletedAt = now;
}

public void setLikedAndScrapped(boolean liked, boolean scraped) {
this.isLiked = liked;
this.isScrapped = scraped;
}

public Review withLimitedImages(int limit) {
List<ReviewImage> limitedImages =
this.images.stream().limit(limit).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.depromeet.spot.domain.review;

public record ReviewCount(long reviewCount, long totalLikes) {}
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ public List<ReviewEntity> findAllByUserId(
Integer month,
String cursor,
SortCriteria sortBy,
int size) {
int size,
ReviewType reviewType) {

BooleanBuilder builder = new BooleanBuilder();
builder.and(reviewEntity.member.id.eq(userId));
builder.and(eqYear(year));
builder.and(eqMonth(month));
builder.and(reviewEntity.deletedAt.isNull());
builder.and(reviewEntity.reviewType.eq(reviewType));

OrderSpecifier<?>[] orderBy = getOrderBy(sortBy);
BooleanExpression cursorCondition = getCursorCondition(sortBy, cursor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.time.LocalDateTime;
import java.util.List;

import org.depromeet.spot.domain.review.Review.ReviewType;
import org.depromeet.spot.domain.review.ReviewCount;
import org.depromeet.spot.domain.review.ReviewYearMonth;
import org.depromeet.spot.infrastructure.jpa.review.entity.ReviewEntity;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -17,9 +19,20 @@ public interface ReviewJpaRepository extends JpaRepository<ReviewEntity, Long> {
"SELECT new org.depromeet.spot.domain.review.ReviewYearMonth(YEAR(r.dateTime), MONTH(r.dateTime)) "
+ "FROM ReviewEntity r WHERE r.member.id = :memberId "
+ "AND r.deletedAt IS NULL "
+ "AND r.reviewType = :reviewType "
+ "GROUP BY YEAR(r.dateTime), MONTH(r.dateTime) "
+ "ORDER BY YEAR(r.dateTime) DESC, MONTH(r.dateTime) DESC")
List<ReviewYearMonth> findReviewMonthsByMemberId(@Param("memberId") Long memberId);
List<ReviewYearMonth> findReviewMonthsByMemberId(
@Param("memberId") Long memberId, @Param("reviewType") ReviewType reviewType);

@Query(
"SELECT new org.depromeet.spot.domain.review.ReviewCount("
+ "COUNT(r), "
+ "COALESCE(SUM(CASE WHEN r.reviewType = :viewType THEN r.likesCount ELSE 0 END), 0)) "
+ "FROM ReviewEntity r "
+ "WHERE r.member.id = :memberId AND r.deletedAt IS NULL")
ReviewCount countAndSumLikesByMemberId(
@Param("memberId") Long memberId, @Param("viewType") ReviewType viewType);

@Modifying
@Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.depromeet.spot.domain.review.Review;
import org.depromeet.spot.domain.review.Review.ReviewType;
import org.depromeet.spot.domain.review.Review.SortCriteria;
import org.depromeet.spot.domain.review.ReviewCount;
import org.depromeet.spot.domain.review.ReviewYearMonth;
import org.depromeet.spot.infrastructure.jpa.review.entity.ReviewEntity;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase.LocationInfo;
Expand Down Expand Up @@ -55,6 +56,11 @@ public long countByUserId(Long id) {
return reviewJpaRepository.countByMemberIdAndDeletedAtIsNull(id);
}

@Override
public ReviewCount countAndSumLikesByUserId(Long id) {
return reviewJpaRepository.countAndSumLikesByMemberId(id, ReviewType.VIEW);
}

@Override
public List<Review> findByStadiumIdAndBlockCode(
Long stadiumId,
Expand Down Expand Up @@ -88,15 +94,17 @@ public List<Review> findAllByUserId(
Integer month,
String cursor,
SortCriteria sortBy,
Integer size) {
Integer size,
ReviewType reviewType) {
List<ReviewEntity> reviewEntities =
reviewCustomRepository.findAllByUserId(userId, year, month, cursor, sortBy, size);
reviewCustomRepository.findAllByUserId(
userId, year, month, cursor, sortBy, size, reviewType);
return reviewEntities.stream().map(ReviewEntity::toDomain).toList();
}

@Override
public List<ReviewYearMonth> findReviewMonthsByMemberId(Long memberId) {
return reviewJpaRepository.findReviewMonthsByMemberId(memberId);
public List<ReviewYearMonth> findReviewMonthsByMemberId(Long memberId, ReviewType reviewType) {
return reviewJpaRepository.findReviewMonthsByMemberId(memberId, reviewType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.depromeet.spot.infrastructure.jpa.review.repository.like;

import java.util.List;

import org.depromeet.spot.infrastructure.jpa.review.entity.like.ReviewLikeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ReviewLikeJpaRepository extends JpaRepository<ReviewLikeEntity, Long> {

Expand All @@ -12,4 +16,9 @@ public interface ReviewLikeJpaRepository extends JpaRepository<ReviewLikeEntity,

@Modifying
void deleteByMemberIdAndReviewId(long memberId, long reviewId);

@Query(
"SELECT r.reviewId FROM ReviewLikeEntity r WHERE r.memberId = :memberId AND r.reviewId IN :reviewIds")
List<Long> findReviewIdsByMemberIdAndReviewIdIn(
@Param("memberId") Long memberId, @Param("reviewIds") List<Long> reviewIds);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.depromeet.spot.infrastructure.jpa.review.repository.like;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.depromeet.spot.domain.review.like.ReviewLike;
import org.depromeet.spot.infrastructure.jpa.review.entity.like.ReviewLikeEntity;
import org.depromeet.spot.usecase.port.out.review.ReviewLikeRepository;
Expand Down Expand Up @@ -33,4 +37,12 @@ public void save(ReviewLike like) {
ReviewLikeEntity entity = ReviewLikeEntity.from(like);
reviewLikeJpaRepository.save(entity);
}

@Override
public Map<Long, Boolean> existsByMemberIdAndReviewIds(Long memberId, List<Long> reviewIds) {
List<Long> likedReviewIds =
reviewLikeJpaRepository.findReviewIdsByMemberIdAndReviewIdIn(memberId, reviewIds);
return reviewIds.stream()
.collect(Collectors.toMap(reviewId -> reviewId, likedReviewIds::contains));
}
}
Loading

0 comments on commit d4bbaf3

Please sign in to comment.