Skip to content

Commit

Permalink
Merge pull request #103 from tukcomCD2024/test#59/set-backend-test
Browse files Browse the repository at this point in the history
  • Loading branch information
ggamD00 authored Jun 14, 2024
2 parents edd1d1b + bc6716f commit b86cbaa
Show file tree
Hide file tree
Showing 35 changed files with 721 additions and 295 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
package com.example.memetory.domain.comment.dto;

import java.time.LocalDateTime;

import com.example.memetory.domain.comment.entity.Comment;
import com.example.memetory.domain.member.dto.response.MemberResponse;
import com.querydsl.core.annotations.QueryProjection;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
@Schema(description = "댓글 정보")
public class CommentInfo {

@Schema(description = "댓글 아이디")
private Long commentId;

@Schema(description = "댓글 쓴 멤버 아이디")
private Long memberId;

@Schema(description = "댓글 쓴 멤버 이름")
private String memberName;

@Schema(description = "댓글 내용")
private String content;

@Schema(description = "댓글 생성 시각")
private LocalDateTime createdAt;

@Builder
public CommentInfo(Long commentId, Long memberId, String memberName, String content, LocalDateTime createdAt) {
this.commentId = commentId;
this.memberId = memberId;
this.memberName = memberName;
this.content = content;
this.createdAt = createdAt;
}

public static CommentInfo of(Comment comment) {
return CommentInfo.builder()
.commentId(comment.getId())
.memberId(comment.getMember().getId())
.memberName(comment.getMember().getName())
.content(comment.getContent())
.createdAt(comment.getCreatedAt())
.build();
}
@Schema(description = "댓글 아이디")
private Long commentId;

@Schema(description = "댓글 쓴 멤버 정보")
private MemberResponse member;

@Schema(description = "댓글 내용")
private String content;

@Schema(description = "댓글 생성 시각")
private LocalDateTime createdAt;

@QueryProjection
@Builder
public CommentInfo(Long commentId, MemberResponse member, String content, LocalDateTime createdAt) {
this.commentId = commentId;
this.member = member;
this.content = content;
this.createdAt = createdAt;
}

public static CommentInfo of(Comment comment) {
return CommentInfo.builder()
.commentId(comment.getId())
.member(MemberResponse.of(comment.getMember()))
.content(comment.getContent())
.createdAt(comment.getCreatedAt())
.build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.memetory.domain.comment.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

import org.springframework.data.domain.Slice;

@Getter
@NoArgsConstructor
@Schema(description = "댓글 리스트")
public class CommentInfoSlice {
@Schema(description = "현재 페이지")
private int currentPage;
@Schema(description = "다음 페이지 여부")
private boolean hasNext;

private List<CommentInfo> commentInfoList;

@Builder
public CommentInfoSlice(int currentPage, boolean hasNext, List<CommentInfo> commentInfoList) {
this.currentPage = currentPage;
this.hasNext = hasNext;
this.commentInfoList = commentInfoList;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.memetory.domain.comment.dto.request;

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

@NoArgsConstructor
@Builder
@AllArgsConstructor
@Getter
public class CommentRequest {
private String content;
private Long memesId;
private String email;

public void setMemesIdAndEmail(Long memesId, String email) {
this.memesId = memesId;
this.email = email;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.memetory.domain.comment.repository;

import static com.example.memetory.domain.comment.entity.QComment.*;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.example.memetory.domain.comment.dto.QCommentInfo;
import com.example.memetory.domain.member.dto.response.QMemberResponse;

@Component
public class CommentQDtoFactory {

@Bean
public QCommentInfo qCommentInfo() {
return new QCommentInfo(comment.id,
new QMemberResponse(comment.member.id, comment.member.nickname, comment.member.imageUrl, comment.member.createdAt),
comment.content, comment.createdAt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.memetory.domain.comment.repository;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;

import com.example.memetory.domain.comment.dto.CommentInfo;

public interface CommentQueryRepository {
Slice<CommentInfo> findCommentsSliceByMemesId(Long memesId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.memetory.domain.comment.repository;

import static com.example.memetory.domain.comment.entity.QComment.*;
import static com.example.memetory.domain.member.entity.QMember.*;
import static com.example.memetory.domain.memes.entity.QMemes.*;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.stereotype.Repository;

import com.example.memetory.domain.comment.dto.CommentInfo;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class CommentQueryRepositoryImpl implements CommentQueryRepository {
private final JPAQueryFactory jpaQueryFactory;
private final CommentQDtoFactory commentQDtoFactory;

@Override
public Slice<CommentInfo> findCommentsSliceByMemesId(Long memesId, Pageable pageable) {
int pageSize = pageable.getPageSize();
List<CommentInfo> memesList = jpaQueryFactory.select(commentQDtoFactory.qCommentInfo())
.from(comment)
.where(comment.memes.id.eq(memesId))
.join(comment.member, member)
.join(comment.memes, memes)
.offset(pageable.getOffset())
.limit(pageSize + 1)
.fetch();

boolean hasNext = false;
if (memesList.size() > pageSize) {
memesList.remove(pageSize);
hasNext = true;
}

return new SliceImpl<>(memesList, pageable, hasNext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.example.memetory.domain.comment.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CommentRepository extends JpaRepository<Comment, Long> {
public interface CommentRepository extends JpaRepository<Comment, Long>, CommentQueryRepository {
}
Loading

0 comments on commit b86cbaa

Please sign in to comment.