Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*;

import java.time.LocalDateTime;

import org.ezcode.codetest.application.usermanagement.user.dto.response.SimpleUserInfoResponse;
import org.ezcode.codetest.domain.community.dto.DiscussionQueryResult;
import org.ezcode.codetest.domain.community.model.entity.Discussion;
import org.ezcode.codetest.domain.community.model.enums.VoteType;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "DiscussionResponse", description = "Discussion 조회 응답 DTO")
@Schema(name = "DiscussionResponse", description = "Discussion 응답 DTO, 목록 조회 시에만 추천 수, 비추천 수 등의 데이터가 포함됨")
public record DiscussionResponse(

@Schema(description = "Discussion 고유 ID", example = "123", requiredMode = REQUIRED)
Long discussionId,

Expand All @@ -18,20 +23,51 @@ public record DiscussionResponse(
@Schema(description = "관련 문제 ID", example = "45", requiredMode = REQUIRED)
Long problemId,

@Schema(description = "사용 언어명", example = "Java 17", requiredMode = REQUIRED)
String languages,

@Schema(description = "토론 내용", example = "이 문제는 이렇게 풀 수 있습니다...", requiredMode = REQUIRED)
String content
String content,

@Schema(description = "생성 일시", example = "2025-06-25T14:30:00", requiredMode = REQUIRED)
LocalDateTime createdAt,

@Schema(description = "총 추천 수 (upvote)", example = "10")
Long upvoteCount,

@Schema(description = "총 비추천 수 (downvote)", example = "2")
Long downvoteCount,

@Schema(description = "총 댓글 수", example = "5")
Long replyCount,

@Schema(description = "현재 사용자의 추천 상태 (UP, DOWN, NONE)", example = "UP")
VoteType voteStatus

) {

public static DiscussionResponse fromEntity(Discussion discussion) {
return new DiscussionResponse(
discussion.getId(),
SimpleUserInfoResponse.fromEntity(discussion.getUser()),
discussion.getProblem().getId(), // 문제 id가 굳이 필요한가?
discussion.getLanguage().getName(), // TODO: 가공해줘야 할듯?
discussion.getContent()
discussion.getProblem().getId(),
discussion.getContent(),
discussion.getCreatedAt(),
null,
null,
null,
null
);
}

public static DiscussionResponse from(DiscussionQueryResult result) {
return new DiscussionResponse(
result.getDiscussionId(),
result.getUserInfo(),
result.getProblemId(),
result.getContent(),
result.getCreatedAt(),
result.getUpvoteCount(),
result.getDownvoteCount(),
result.getReplyCount(),
result.getVoteStatus()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*;

import java.time.LocalDateTime;

import org.ezcode.codetest.application.usermanagement.user.dto.response.SimpleUserInfoResponse;
import org.ezcode.codetest.domain.community.dto.ReplyQueryResult;
import org.ezcode.codetest.domain.community.model.entity.Reply;
import org.ezcode.codetest.domain.community.model.enums.VoteType;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "ReplyResponse", description = "Reply 조회 응답 DTO")
public record ReplyResponse(

@Schema(description = "Reply 고유 ID", example = "456", requiredMode = REQUIRED)
Long replyId,

@Schema(description = "부모 Reply ID (없으면 null)", example = "123", nullable = true, requiredMode = NOT_REQUIRED)
Long parentId,
Long parentReplyId,

@Schema(description = "소속 Discussion ID", example = "123", requiredMode = REQUIRED)
Long discussionId,
Expand All @@ -22,19 +27,58 @@ public record ReplyResponse(
SimpleUserInfoResponse userInfo,

@Schema(description = "댓글 내용", example = "동의합니다!", requiredMode = REQUIRED)
String content
String content,

@Schema(description = "생성 일시", example = "2025-06-25T14:30:00", requiredMode = REQUIRED)
LocalDateTime createdAt,

@Schema(description = "총 추천 수 (upvote)", example = "10")
Long upvoteCount,

@Schema(description = "총 비추천 수 (downvote)", example = "2")
Long downvoteCount,

@Schema(description = "총 댓글 수", example = "5")
Long childReplyCount,

@Schema(description = "현재 사용자의 추천 상태 (UP, DOWN, NONE)", example = "UP")
VoteType voteStatus

) {

public static ReplyResponse fromEntity(Reply reply) {

Long parentId = (reply.getParent() != null)
? reply.getParent().getId()
: null;

return new ReplyResponse(
reply.getId(),
parentId,
reply.getDiscussion().getId(),
SimpleUserInfoResponse.fromEntity(reply.getUser()),
reply.getContent()
reply.getContent(),
reply.getCreatedAt(),
null,
null,
null,
null
);
}

public static ReplyResponse from(ReplyQueryResult result) {

return new ReplyResponse(
result.getReplyId(),
result.getParentReplyId(),
result.getDiscussionId(),
result.getUserInfo(),
result.getContent(),
result.getCreatedAt(),
result.getUpvoteCount(),
result.getDownvoteCount(),
result.getChildReplyCount(),
result.getVoteStatus()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*;

import org.ezcode.codetest.domain.community.model.VoteResult;
import org.ezcode.codetest.domain.community.dto.VoteResult;
import org.ezcode.codetest.domain.community.model.enums.VoteType;

import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ezcode.codetest.application.community.service;

import org.ezcode.codetest.application.community.dto.response.VoteResponse;
import org.ezcode.codetest.domain.community.model.VoteResult;
import org.ezcode.codetest.domain.community.dto.VoteResult;
import org.ezcode.codetest.domain.community.model.entity.BaseVote;
import org.ezcode.codetest.domain.community.model.enums.VoteType;
import org.ezcode.codetest.domain.community.service.BaseVoteDomainService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.ezcode.codetest.application.community.dto.request.DiscussionCreateRequest;
import org.ezcode.codetest.application.community.dto.request.DiscussionModifyRequest;
import org.ezcode.codetest.application.community.dto.response.DiscussionResponse;
import org.ezcode.codetest.domain.community.dto.DiscussionQueryResult;
import org.ezcode.codetest.domain.community.model.entity.Discussion;
import org.ezcode.codetest.domain.community.service.DiscussionDomainService;
import org.ezcode.codetest.domain.language.model.entity.Language;
Expand Down Expand Up @@ -40,10 +41,11 @@ public DiscussionResponse createDiscussion(Long problemId, DiscussionCreateReque
}

@Transactional(readOnly = true)
public Page<DiscussionResponse> getDiscussions(Long problemId, Pageable pageable) {
public Page<DiscussionResponse> getDiscussions(Long problemId, String sortBy, Long userId, Pageable pageable) {

Page<Discussion> discussionResponsePage = discussionDomainService.getAllDiscussionsByProblemId(problemId, pageable);
return discussionResponsePage.map(DiscussionResponse::fromEntity);
Page<DiscussionQueryResult> result =
discussionDomainService.getAllDiscussionsByProblemId(problemId, sortBy, userId, pageable);
return result.map(DiscussionResponse::from);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.ezcode.codetest.application.community.dto.response.ReplyResponse;
import org.ezcode.codetest.application.notification.event.NotificationCreateEvent;
import org.ezcode.codetest.application.notification.port.NotificationEventService;
import org.ezcode.codetest.domain.community.dto.ReplyQueryResult;
import org.ezcode.codetest.domain.community.model.entity.Discussion;
import org.ezcode.codetest.domain.community.model.entity.Reply;
import org.ezcode.codetest.domain.community.service.DiscussionDomainService;
Expand Down Expand Up @@ -58,28 +59,30 @@ public ReplyResponse createReply(
}

@Transactional(readOnly = true)
public Page<ReplyResponse> getReplies(Long problemId, Long discussionId, Pageable pageable) {
public Page<ReplyResponse> getReplies(Long problemId, Long discussionId, Long currentUserId, Pageable pageable) {

Discussion discussion = discussionDomainService.getDiscussionForProblem(discussionId, problemId);

Page<Reply> replies = replyDomainService.getRepliesByDiscussionId(discussion, pageable);
Page<ReplyQueryResult> replies = replyDomainService.getRepliesByDiscussionId(discussion, currentUserId, pageable);

return replies.map(ReplyResponse::fromEntity);
return replies.map(ReplyResponse::from);
}

@Transactional(readOnly = true)
public Page<ReplyResponse> getChildReplies(
Long problemId,
Long discussionId,
Long parentReplyId,
Long currentUserId,
Pageable pageable
) {

Discussion discussion = discussionDomainService.getDiscussionForProblem(discussionId, problemId);

Page<Reply> replies = replyDomainService.getRepliesByParentReplyId(parentReplyId, discussion, pageable);
Page<ReplyQueryResult> childReplies =
replyDomainService.getRepliesByParentReplyId(parentReplyId, discussion, currentUserId, pageable);

return replies.map(ReplyResponse::fromEntity);
return childReplies.map(ReplyResponse::from);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.ezcode.codetest.domain.community.dto;

import java.time.LocalDateTime;

import org.ezcode.codetest.application.usermanagement.user.dto.response.SimpleUserInfoResponse;
import org.ezcode.codetest.domain.community.model.enums.VoteType;

import com.querydsl.core.annotations.QueryProjection;

import lombok.Getter;

@Getter
public class DiscussionQueryResult {

private final Long discussionId;

private final SimpleUserInfoResponse userInfo;

private final Long problemId;

private final String content;

private final LocalDateTime createdAt;

private final Long upvoteCount;

private final Long downvoteCount;

private final Long replyCount;

private final VoteType voteStatus;

@QueryProjection
public DiscussionQueryResult(
Long discussionId,
SimpleUserInfoResponse userInfo,
Long problemId,
String content,
LocalDateTime createdAt,
Long upvoteCount,
Long downvoteCount,
Long replyCount,
VoteType voteType
) {

this.discussionId = discussionId;
this.userInfo = userInfo;
this.problemId = problemId;
this.content = content;
this.createdAt = createdAt;
this.upvoteCount = upvoteCount;
this.downvoteCount = downvoteCount;
this.replyCount = replyCount;

if (voteType == null) {
this.voteStatus = VoteType.NONE;
} else if (voteType == VoteType.UP) {
this.voteStatus = VoteType.UP;
} else {
this.voteStatus = VoteType.DOWN;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.ezcode.codetest.domain.community.dto;

import java.time.LocalDateTime;

import org.ezcode.codetest.application.usermanagement.user.dto.response.SimpleUserInfoResponse;
import org.ezcode.codetest.domain.community.model.enums.VoteType;

import com.querydsl.core.annotations.QueryProjection;

import lombok.Getter;

@Getter
public class ReplyQueryResult {

private final Long replyId;

private final SimpleUserInfoResponse userInfo;

private final Long parentReplyId;

private final Long discussionId;

private final String content;

private final LocalDateTime createdAt;

private final Long upvoteCount;

private final Long downvoteCount;

private final Long childReplyCount;

private final VoteType voteStatus;

@QueryProjection
public ReplyQueryResult(
Long replyId,
SimpleUserInfoResponse userInfo,
Long parentReplyId,
Long discussionId,
String content,
LocalDateTime createdAt,
Long upvoteCount,
Long downvoteCount,
Long childReplyCount,
VoteType voteType
) {

this.replyId = replyId;
this.userInfo = userInfo;
this.parentReplyId = parentReplyId;
this.discussionId = discussionId;
this.content = content;
this.createdAt = createdAt;
this.upvoteCount = upvoteCount;
this.downvoteCount = downvoteCount;
this.childReplyCount = childReplyCount;

if (voteType == null) {
this.voteStatus = VoteType.NONE;
} else if (voteType == VoteType.UP) {
this.voteStatus = VoteType.UP;
} else {
this.voteStatus = VoteType.DOWN;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ezcode.codetest.domain.community.model;
package org.ezcode.codetest.domain.community.dto;

import org.ezcode.codetest.domain.community.model.enums.VoteType;

Expand Down
Loading