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 @@ -23,10 +23,11 @@ public class QuestionController {
@GetMapping("/api/sessions/{sessionId}/questions")
public ResponseEntity<ApiResponse<QuestionResDTO.QuestionRoomResponse>> getQuestionRoom(
@PathVariable Long sessionId,
@RequestParam(defaultValue = "0") int understandingIndex
@RequestParam(defaultValue = "0") int understandingIndex,
@AuthenticationPrincipal Long userId
) {
return ResponseUtil.success(QuestionSuccessCode.QUESTION_ROOM_OK,
questionService.getQuestionRoom(sessionId, understandingIndex));
questionService.getQuestionRoom(sessionId, understandingIndex, userId)); // ← userId 추가
}

// 질문 목록 실시간 이벤트 구독
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public record QuestionSummaryResponse(
String imageUrl,
Boolean isResolved,
Boolean isPopular,
Boolean isLiked,
Integer likeCount,
Integer commentCount,
// 댓글이 없으면 빈 배열로 내려가며, 프론트는 빈 배열일 때 미리보기 영역을 숨긴다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public class QuestionService {

// 질문 방 조회
@Transactional(readOnly = true)
public QuestionResDTO.QuestionRoomResponse getQuestionRoom(Long sessionId, int understandingIndex) {
public QuestionResDTO.QuestionRoomResponse getQuestionRoom(Long sessionId, int understandingIndex, Long userId) {
if (understandingIndex < 0) {
throw new IllegalArgumentException("이해도 조회 인덱스는 0 이상이어야 합니다.");
}
StudySession session = findSession(sessionId);
User loginUser = findLoginUser(userId);
return new QuestionResDTO.QuestionRoomResponse(
toSessionResponse(session),
getUnderstandingSlice(session, understandingIndex),
getQuestionGroups(session)
getQuestionGroups(session, loginUser)
);
}

Expand Down Expand Up @@ -464,38 +465,41 @@ private QuestionResDTO.UnderstandingCheckResponse toUnderstandingCheckResponse(U
);
}

private QuestionResDTO.QuestionGroupsResponse getQuestionGroups(StudySession session) {
private QuestionResDTO.QuestionGroupsResponse getQuestionGroups(StudySession session, User loginUser) {
List<Question> questions = questionRepository.findBySessionAndDeletedAtIsNull(session);
QuestionSummaryContext summaryContext = getQuestionSummaryContext(questions);

List<QuestionResDTO.QuestionSummaryResponse> popularQuestions = questions.stream()
.filter(q -> !q.getIsResolved() && q.getLikeCount() >= POPULAR_LIKE_THRESHOLD)
.sorted(Comparator.comparing(Question::getLikeCount, Comparator.reverseOrder())
.thenComparing(Question::getCreatedAt, Comparator.reverseOrder()))
.map(question -> toQuestionSummaryResponse(question, summaryContext)).toList();
.map(q -> toQuestionSummaryResponse(q, summaryContext, loginUser)).toList();

List<QuestionResDTO.QuestionSummaryResponse> unresolvedQuestions = questions.stream()
.filter(q -> !q.getIsResolved() && q.getLikeCount() < POPULAR_LIKE_THRESHOLD)
.sorted(Comparator.comparing(Question::getCreatedAt, Comparator.reverseOrder()))
.map(question -> toQuestionSummaryResponse(question, summaryContext)).toList();
.map(q -> toQuestionSummaryResponse(q, summaryContext, loginUser)).toList();

List<QuestionResDTO.QuestionSummaryResponse> resolvedQuestions = questions.stream()
.filter(Question::getIsResolved)
.sorted(Comparator.comparing(Question::getCreatedAt, Comparator.reverseOrder()))
.map(question -> toQuestionSummaryResponse(question, summaryContext)).toList();
.map(q -> toQuestionSummaryResponse(q, summaryContext, loginUser)).toList();

return new QuestionResDTO.QuestionGroupsResponse(popularQuestions, unresolvedQuestions, resolvedQuestions);
}

private QuestionResDTO.QuestionSummaryResponse toQuestionSummaryResponse(
private QuestionResDTO.QuestionSummaryResponse toQuestionSummaryResponse (
Question question,
QuestionSummaryContext summaryContext
QuestionSummaryContext summaryContext,
User loginUser
) {
Long questionId = question.getId();
boolean isLiked = questionLikeRepository.existsByQuestionAndUser(question, loginUser);
return new QuestionResDTO.QuestionSummaryResponse(
questionId, question.getContent(), question.getImageUrl(),
question.getIsResolved(),
!question.getIsResolved() && question.getLikeCount() >= POPULAR_LIKE_THRESHOLD,
isLiked,
question.getLikeCount(),
summaryContext.commentCounts().getOrDefault(questionId, 0),
// 목록 화면은 최상위 댓글 중 먼저 달린 3개만 미리보기로 보여준다.
Expand Down
Loading