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 @@ -233,4 +233,28 @@ public ResponseEntity<ApiResponse<DebateResponseDto.DebatePageResponse>> getUser
DebateResponseDto.DebatePageResponse result = debateService.getDebatesByMemberAndMoviePopularity(memberId, tmdbId, page, size);
return ApiResponse.success(SuccessStatus.SEND_DEBATE_LIST_SUCCESS, result);
}

@Operation(summary = "사용자의 토론 반응 상태 조회", description = "현재 사용자가 특정 토론에 대한 좋아요/싫어요 상태를 조회합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "반응 상태 조회 성공")
})
@GetMapping("/{debateId}/user-reaction")
public ResponseEntity<ApiResponse<DebateResponseDto.UserReaction>> getUserDebateReaction(
@Parameter(description = "토론 ID", example = "1")
@PathVariable Long debateId,
@AuthenticationPrincipal SecurityMember securityMember) {

// 비로그인 사용자의 경우
if (securityMember == null) {
DebateResponseDto.UserReaction result = DebateResponseDto.UserReaction.builder()
.isLiked(false)
.isHated(false)
.build();
return ApiResponse.success(SuccessStatus.GET_USER_REACTION_SUCCESS, result);
}

Long currentUserId = securityMember.getId();
DebateResponseDto.UserReaction result = debateService.getUserReaction(debateId, currentUserId);
return ApiResponse.success(SuccessStatus.GET_USER_REACTION_SUCCESS, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,17 @@ public static class DebateMovieInfo {
@Schema(description = "영화 평점")
private Double rating;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "사용자의 토론 반응 상태")
public static class UserReaction {
@Schema(description = "현재 사용자가 좋아요를 눌렀는지", example = "true")
private Boolean isLiked;

@Schema(description = "현재 사용자가 싫어요를 눌렀는지", example = "false")
private Boolean isHated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ ORDER BY CAST(d.created_at AS DATE)
""", nativeQuery = true)
List<Object[]> countNewDebatesByDate(@Param("startDate") LocalDate startDate,
@Param("endDate") LocalDate endDate);

boolean existsByIdAndIsDeletedFalse(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Slf4j
Expand Down Expand Up @@ -337,5 +339,34 @@ public DebateResponseDto.DebatePageResponse getDebatesByNicknamePopularity(Strin
return DebateResponseDto.DebatePageResponse.from(detailPage);
}

// 사용자의 토론 반응 상태 조회
public DebateResponseDto.UserReaction getUserReaction(Long debateId, Long userId) {
// 토론 존재 여부 확인
if (!debateRepository.existsByIdAndIsDeletedFalse(debateId)) {
throw new NotFoundException(ErrorStatus.DEBATE_NOT_FOUND.getMessage());
}

Boolean isLiked = false;
Boolean isHated = false;

// 사용자의 반응 조회
Optional<DebateLikeHate> userReaction = debateLikeHateRepository
.findByDebateIdAndMemberId(debateId, userId);

if (userReaction.isPresent()) {
DebateLikeHate likeHate = userReaction.get();
if (likeHate.getType() == LikeHateType.LIKE) {
isLiked = true;
} else if (likeHate.getType() == LikeHateType.HATE) {
isHated = true;
}
}

return DebateResponseDto.UserReaction.builder()
.isLiked(isLiked)
.isHated(isHated)
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public enum SuccessStatus {
REPORT_CREATE_SUCCESS(HttpStatus.OK,"신고 등록 성공"),
REPORT_DELETE_SUCCESS(HttpStatus.OK,"신고 삭제 성공"),
SEND_TODAY_MOVIE_SUCCESS(HttpStatus.OK, "오늘의 TOP10 영화 조회 성공"),
GET_USER_REACTION_SUCCESS(HttpStatus.OK, "사용자 반응 상태 조회에 성공했습니다."),

WITHDRAW_SUCCESS(HttpStatus.OK, "회원 탈퇴 성공");
private final HttpStatus httpStatus;
Expand Down