Skip to content

Commit

Permalink
Merge pull request #131 from oduck-team/feature/130
Browse files Browse the repository at this point in the history
작성한 리뷰 목록에 애니 제목 추가 #130
  • Loading branch information
hanyMK authored Dec 1, 2023
2 parents 1b5f335 + 4ee4922 commit 5ebef65
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.oduck.api.domain.member.service.MemberService;
import io.oduck.api.domain.review.dto.ShortReviewReqDto;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewResWithTitle;
import io.oduck.api.domain.review.service.ShortReviewService;
import io.oduck.api.global.common.OrderDirection;
import io.oduck.api.global.common.SliceResponse;
Expand Down Expand Up @@ -87,11 +88,11 @@ public ResponseEntity<?> getBookmarksCount(
public ResponseEntity<?> getShortReviews(
@PathVariable("id") @Positive Long id,
@RequestParam(required = false) String cursor,
@RequestParam(required = false, defaultValue = "created_at") ShortReviewReqDto.Sort sort,
@RequestParam(required = false, defaultValue = "created_at") ShortReviewReqDto.SortForProfile sort,
@RequestParam(required = false, defaultValue = "DESC") OrderDirection order,
@RequestParam(required = false, defaultValue = "10") @Min(1) @Max(100) int size
) {
SliceResponse<ShortReviewRes> res = shortReviewService.getShortReviewsByMemberId(id, cursor, sort, order, size);
SliceResponse<ShortReviewResWithTitle> res = shortReviewService.getShortReviewsByMemberId(id, cursor, sort, order, size);
return ResponseEntity.ok(res);
}

Expand Down
22 changes: 5 additions & 17 deletions src/main/java/io/oduck/api/domain/member/dto/MemberDslDto.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
package io.oduck.api.domain.member.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

// TODO: VO로 변경 할지 논의 필요
public class MemberDslDto {
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ProfileWithoutActivity {
private Long memberId;
private String name;
private String description;
private String thumbnail;
private String backgroundImage;
private Long point;

@Builder
public ProfileWithoutActivity(Long memberId, String name, String description, String thumbnail,
String backgroundImage, Long point) {
this.memberId = memberId;
this.name = name;
this.description = description;
this.thumbnail = thumbnail;
this.backgroundImage = backgroundImage;
this.point = point;
}
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class MemberActivity {
private Long reviews;
private Long likes;

@Builder
public MemberActivity(Long reviews, Long likes) {
this.reviews = reviews;
this.likes = likes;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.oduck.api.domain.review.dto;

import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -34,4 +36,20 @@ public ShortReviewDsl(Long reviewId, Long animeId, String name, String thumbnail
this.createdAt = createdAt;
}
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ShortReviewDslWithTitle {
private Long reviewId;
private Long animeId;
private String title;
private String thumbnail;
private Integer score;
private String content;
private Boolean isSpoiler;
private Long likeCount;
private LocalDateTime createdAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ public enum Sort{

private final String sort;
}

@Getter
@AllArgsConstructor
public enum SortForProfile{
//제목, 최신순, 평점 높은순
CREATED_AT("createdAt"),
TITLE("title"),
SCORE("score");

private final String sort;
}
}
77 changes: 62 additions & 15 deletions src/main/java/io/oduck/api/domain/review/dto/ShortReviewResDto.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package io.oduck.api.domain.review.dto;

import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDsl;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDslWithTitle;
import io.oduck.api.global.common.EntityBased;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
public class ShortReviewResDto {;

public class ShortReviewResDto {

;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public static class ShortReviewRes implements EntityBased {

private Long reviewId;
private Long animeId;
private String name;
Expand All @@ -29,22 +34,22 @@ public static class ShortReviewRes implements EntityBased {

//카운트가 없으면 hasLike false
@Builder
public static ShortReviewRes of(ShortReviewDsl shortReviewDsl){
public static ShortReviewRes of(ShortReviewDsl shortReviewDsl) {
Boolean isLike = shortReviewDsl.getLikeCount() != null;
Long likeCount = isLike ? shortReviewDsl.getLikeCount() : 0L ;
Long likeCount = isLike ? shortReviewDsl.getLikeCount() : 0L;
return ShortReviewRes
.builder()
.reviewId(shortReviewDsl.getReviewId())
.animeId(shortReviewDsl.getAnimeId())
.name(shortReviewDsl.getName())
.thumbnail(shortReviewDsl.getThumbnail())
.score(shortReviewDsl.getScore())
.content(shortReviewDsl.getContent())
.isSpoiler(shortReviewDsl.getIsSpoiler())
.isLike(isLike)
.likeCount(likeCount)
.createdAt(shortReviewDsl.getCreatedAt())
.build();
.builder()
.reviewId(shortReviewDsl.getReviewId())
.animeId(shortReviewDsl.getAnimeId())
.name(shortReviewDsl.getName())
.thumbnail(shortReviewDsl.getThumbnail())
.score(shortReviewDsl.getScore())
.content(shortReviewDsl.getContent())
.isSpoiler(shortReviewDsl.getIsSpoiler())
.isLike(isLike)
.likeCount(likeCount)
.createdAt(shortReviewDsl.getCreatedAt())
.build();
}

@Override
Expand All @@ -57,11 +62,53 @@ public String bringCursor(String property) {
}
}

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public static class ShortReviewResWithTitle implements EntityBased {

private Long reviewId;
private Long animeId;
private String title;
private String thumbnail;
private Integer score;
private String content;
private Boolean isSpoiler;
private Long likeCount;
private LocalDateTime createdAt;

public static ShortReviewResWithTitle of(ShortReviewDslWithTitle shortReviewDsl) {
return ShortReviewResWithTitle
.builder()
.reviewId(shortReviewDsl.getReviewId())
.animeId(shortReviewDsl.getAnimeId())
.title(shortReviewDsl.getTitle())
.thumbnail(shortReviewDsl.getThumbnail())
.score(shortReviewDsl.getScore())
.content(shortReviewDsl.getContent())
.isSpoiler(shortReviewDsl.getIsSpoiler())
.likeCount(shortReviewDsl.getLikeCount())
.createdAt(shortReviewDsl.getCreatedAt())
.build();
}

@Override
public String bringCursor(String property) {
return switch (property) {
case "title" -> this.title + ", " + this.createdAt.toString();
case "score" -> this.score.toString() + ", " + this.createdAt.toString();
default -> this.createdAt.toString();
};
}
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ShortReviewCountRes {

private Long count;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.oduck.api.domain.review.repository;

import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDsl;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDslWithTitle;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;

public interface ShortReviewRepositoryCustom {

Slice<ShortReviewDsl> selectShortReviews(Long animeId, String cursor, Pageable pageable);
Slice<ShortReviewDsl> selectShortReviewsByMemberId(Long memberId, String cursor, Pageable pageable);
Slice<ShortReviewDslWithTitle> selectShortReviewsByMemberId(Long memberId, String cursor, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDsl;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDslWithTitle;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -67,17 +68,17 @@ public Slice<ShortReviewDsl> selectShortReviews(Long animeId, String cursor,
}

@Override
public Slice<ShortReviewDsl> selectShortReviewsByMemberId(Long memberId, String cursor,
public Slice<ShortReviewDslWithTitle> selectShortReviewsByMemberId(Long memberId, String cursor,
Pageable pageable) {
String property = pageable.getSort().get().toList().get(0).getProperty();
JPAQuery<ShortReviewDsl> shortReviews = query
JPAQuery<ShortReviewDslWithTitle> shortReviews = query
.select(
Projections.constructor(
ShortReviewDsl.class,
ShortReviewDslWithTitle.class,
shortReview.id,
anime.id,
member.memberProfile.name,
member.memberProfile.thumbnail,
anime.title,
anime.thumbnail,
starRating.score,
shortReview.content,
shortReview.hasSpoiler,
Expand All @@ -86,7 +87,6 @@ public Slice<ShortReviewDsl> selectShortReviewsByMemberId(Long memberId, String
)
)
.from(shortReview)
.join(member).on(member.id.eq(shortReview.member.id))
.join(anime).on(anime.id.eq(shortReview.anime.id))
.leftJoin(starRating).on(starRating.anime.id.eq(shortReview.anime.id)
.and(starRating.member.id.eq(shortReview.member.id)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.oduck.api.domain.review.service;

import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDslWithTitle;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.ShortReviewReq;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.Sort;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.SortForProfile;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewCountRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewResWithTitle;
import io.oduck.api.global.common.OrderDirection;
import io.oduck.api.global.common.SliceResponse;

Expand All @@ -16,7 +19,7 @@ public interface ShortReviewService {
SliceResponse<ShortReviewRes> getShortReviews(Long animeId, String cursor, Sort sort, OrderDirection order, int size);
ShortReviewCountRes getShortReviewCountByMemberId(Long memberId);

SliceResponse<ShortReviewRes> getShortReviewsByMemberId(Long memberId, String cursor, Sort sort, OrderDirection order, int size);
SliceResponse<ShortReviewResWithTitle> getShortReviewsByMemberId(Long memberId, String cursor, SortForProfile sort, OrderDirection order, int size);

//애니 리뷰 수정
void update(Long memberId, Long reviewId, ShortReviewReq req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import io.oduck.api.domain.member.entity.Member;
import io.oduck.api.domain.member.repository.MemberRepository;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDsl;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDslWithTitle;
import io.oduck.api.domain.review.dto.ShortReviewReqDto;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.ShortReviewReq;

import io.oduck.api.domain.review.dto.ShortReviewReqDto.SortForProfile;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewCountRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewResWithTitle;
import io.oduck.api.domain.review.entity.ShortReview;
import io.oduck.api.domain.review.repository.ShortReviewRepository;
import io.oduck.api.global.common.OrderDirection;
Expand Down Expand Up @@ -108,18 +111,18 @@ public ShortReviewCountRes getShortReviewCountByMemberId(Long memberId) {
}

@Override
public SliceResponse<ShortReviewRes> getShortReviewsByMemberId(Long memberId, String cursor,
ShortReviewReqDto.Sort sort, OrderDirection order, int size) {
public SliceResponse<ShortReviewResWithTitle> getShortReviewsByMemberId(Long memberId, String cursor,
ShortReviewReqDto.SortForProfile sort, OrderDirection order, int size) {
Sort sortList = Sort.by(
Direction.fromString(order.getOrder()),
sort.getSort()
);

if(sort.equals(ShortReviewReqDto.Sort.LIKE_COUNT) || sort.equals(ShortReviewReqDto.Sort.SCORE)){
if(sort.equals(SortForProfile.TITLE) || sort.equals(SortForProfile.SCORE)){
sortList = sortList.and(Sort.by(Direction.DESC, "createdAt"));
}

Slice<ShortReviewDsl> shortReviews = shortReviewRepository.selectShortReviewsByMemberId(
Slice<ShortReviewDslWithTitle> shortReviews = shortReviewRepository.selectShortReviewsByMemberId(
memberId,
cursor,
applyPageableForNonOffset(
Expand All @@ -128,9 +131,9 @@ public SliceResponse<ShortReviewRes> getShortReviewsByMemberId(Long memberId, St
)
);

List<ShortReviewRes> res = shortReviews.getContent()
List<ShortReviewResWithTitle> res = shortReviews.getContent()
.stream()
.map(ShortReviewRes::of)
.map(ShortReviewResWithTitle::of)
.toList();

return SliceResponse.of(shortReviews, res, sort.getSort());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/oduck/api/global/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new StringToAdminQueryTypeConverter());
registry.addConverter(new StringToStatusConverter());
registry.addConverter(new StringToAdminAnimeSortConverter());
registry.addConverter(new StringToMemerReviewsConverter());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.oduck.api.global.converter;

import io.oduck.api.domain.review.dto.ShortReviewReqDto.SortForProfile;
import org.springframework.core.convert.converter.Converter;

public class StringToMemerReviewsConverter implements Converter<String, SortForProfile> {

@Override
public SortForProfile convert(String sort) {
return SortForProfile.valueOf(sort.toUpperCase());
}
}

0 comments on commit 5ebef65

Please sign in to comment.