Skip to content

Commit

Permalink
fix : Repository 병합 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
1000kkannoo committed Jan 15, 2024
1 parent 083e1af commit 897b663
Show file tree
Hide file tree
Showing 25 changed files with 433 additions and 165 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ bootJar {
from("${generateSwaggerUISample.outputDir}") {
into 'static/docs'
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/dnd/project/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class BaseEntity {
private LocalDateTime createdDate;

@PrePersist
public void onPrePersist(){
public void onPrePersist() {
this.createdDate = LocalDateTime.now(ZoneId.of("Asia/Seoul"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@Repository
public interface BookmarkRepository extends JpaRepository<Bookmark, Long>, BookmarkCustomRepository {
Optional<Bookmark> findByLectureAndUser(Lecture lecture, Users user);

void deleteByLectureAndUser(Lecture lecture, Users users);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import dnd.project.domain.lecture.entity.Lecture;
import dnd.project.domain.lecture.response.LectureListReadResponse;
import dnd.project.domain.lecture.response.LectureReviewListReadResponse;
import dnd.project.domain.lecture.response.LectureScopeListReadResponse;
import dnd.project.domain.review.entity.Review;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
Expand Down Expand Up @@ -51,6 +53,44 @@ public Map<Long, Long> findBookmarkCount(List<Long> ids) {
.transform(GroupBy.groupBy(lecture.id).as(bookmark.id.count()));
}

public Map<Long, Double> findReviewAverageScore(List<Long> ids) {
return queryFactory
.from(lecture)
.leftJoin(review).on(lecture.id.eq(review.lecture.id))
.where(lecture.id.in(ids))
.groupBy(lecture.id)
.transform(GroupBy.groupBy(lecture.id).as(review.score.avg()));
}

public List<Review> findAllReviewsByIds(List<Long> ids) {
return queryFactory
.select(review)
.from(review)
.where(review.lecture.id.in(ids))
.fetch();
}

public List<LectureListReadResponse.LectureInfo.ReviewInfo> findAllReviewsById(Long id) {

return queryFactory.select(
Projections.constructor(LectureListReadResponse.LectureInfo.ReviewInfo.class,
review.id,
selectUser("nickName"),
review.tags,
review.content,
review.createdDate,
review.score,
likeReview.id.count()))
.from(review)
.leftJoin(review.user, users)
.leftJoin(likeReview).on(review.id.eq(likeReview.review.id))
.where(review.lecture.id.eq(id))
.groupBy(review.id)
.orderBy(review.id.desc())
.limit(10)
.fetch();
}

public Page<Lecture> findAll(String mainCategory,
String subCategory,
String searchKeyword,
Expand Down Expand Up @@ -198,6 +238,7 @@ public List<String> findAllReviewTagsById(Long id) {
.fetch();
}


public Page<LectureReviewListReadResponse.ReviewInfo> findAllReviewsById(Long id,
String searchKeyword,
Integer page,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dnd.project.domain.lecture.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import dnd.project.domain.lecture.entity.Lecture;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

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

@Getter
Expand All @@ -30,8 +33,16 @@ public static class LectureInfo {
private final String imageUrl;
private final Long reviewCount;
private final Long bookmarkCount;
private final Double averageScore;
private final List<TagGroup> tagGroups;
private final List<ReviewInfo> reviews; // 최근 10개 리뷰

public static LectureInfo of(Lecture lecture, Long reviewCount, Long bookmarkCount) {
public static LectureInfo of(Lecture lecture,
Long reviewCount,
Long bookmarkCount,
Double averageScore,
List<TagGroup> tagGroups,
List<ReviewInfo> reviews) {
return new LectureInfo(lecture.getId(),
lecture.getTitle(),
lecture.getSource(),
Expand All @@ -42,7 +53,34 @@ public static LectureInfo of(Lecture lecture, Long reviewCount, Long bookmarkCou
lecture.getSubCategory(),
lecture.getImageUrl(),
reviewCount,
bookmarkCount);
bookmarkCount,
averageScore,
tagGroups,
reviews);
}

@Getter
public static class ReviewInfo {
private final Long id;
private final String nickname;
private final List<String> tags = new ArrayList<>();
private final String content;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
private final LocalDateTime createdDate;
private final Double score;
private final Long likeCount;

public ReviewInfo(Long id, String nickname, String tags, String content, LocalDateTime createdDate, Double score, Long likeCount) {
this.id = id;
this.nickname = nickname;
for (String tag : tags.split(",")) {
this.tags.add(tag.trim());
}
this.content = content;
this.createdDate = createdDate;
this.score = score;
this.likeCount = likeCount;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,4 @@ public static LectureReadResponse of(Lecture lecture,
averageScore,
tagGroups);
}

@Getter
@RequiredArgsConstructor
public static class TagGroup {
private final String name;
private final List<Tag> tags;

@Getter
@RequiredArgsConstructor
public static class Tag {
private final String name;
private final Integer count;
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/dnd/project/domain/lecture/response/TagGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dnd.project.domain.lecture.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;

@Getter
@RequiredArgsConstructor
public class TagGroup {
private final String name;
private final List<Tag> tags;

@Getter
@RequiredArgsConstructor
public static class Tag {
private final String name;
private final Integer count;
}
}
Loading

0 comments on commit 897b663

Please sign in to comment.