Skip to content

Commit

Permalink
Merge pull request #179 from SMU-SATTO/feature/#21
Browse files Browse the repository at this point in the history
✨ [FEATURE] 이벤트 참여 조회 Dto 속성 추가
  • Loading branch information
chamm99 authored Aug 28, 2024
2 parents 1ef01b2 + 81835ee commit b696d7e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public BaseResponse<List<ContestResponseDto>> getContestParticipants(
@AuthenticationPrincipal Users user,
@PathVariable(name = "category") String category
) {
return BaseResponse.onSuccess(eventService.getContestParticipants(category));
return BaseResponse.onSuccess(eventService.getContestParticipants(user, category));
}

@Operation(method = "POST", summary = "이벤트 좋아요 누르기", description = "좋아요 상태면 좋아요 취소, 좋아요 상태가 아니면 좋아요 부여")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
public record ContestResponseDto(
Long contestId,
String name,
String studentId,
String photo,
Long likeCount,
Long dislikeCount,
boolean isLiked,
boolean isDisliked,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ContestDislikeRepository extends JpaRepository<ContestDislike,
Optional<ContestDislike> findByUserAndContest(Users user, Contest contest);

Long countByContest(Contest photoContest);

boolean existsByUserAndContest(Users user, Contest contest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ContestLikeRepository extends JpaRepository<ContestLike, Long>
Optional<ContestLike> findByUserAndContest(Users user, Contest contest);

Long countByContest(Contest photoContest);

boolean existsByUserAndContest(Users user, Contest contest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface EventService {
List<EventCategoryResponseDto> getEventCategoryInfoList();

// Event API 하나로 통합
List<ContestResponseDto> getContestParticipants(String category);
List<ContestResponseDto> getContestParticipants(Users user, String category);

String likeContest(Long contestId, Users user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,23 @@ public List<EventCategoryResponseDto> getEventCategoryInfoList() {

// Event API 하나로 통합
@Override
public List<ContestResponseDto> getContestParticipants(String category) {
public List<ContestResponseDto> getContestParticipants(Users user, String category) {
List<Contest> contestList = contestRepository.findAllByCategory(category);
List<ContestResponseDto> contestResponseDtoList = new ArrayList<>();
for (Contest contest : contestList) {
Long likeCount = contestLikeRepository.countByContest(contest);
Long dislikeCount = contestDislikeRepository.countByContest(contest);
boolean isLiked = contestLikeRepository.existsByUserAndContest(user, contest);
boolean isDisliked = contestDislikeRepository.existsByUserAndContest(user, contest);
String name = contest.getUser().getName();
contestResponseDtoList.add(ContestResponseDto.builder()
.contestId(contest.getContestId())
.name(name)
.studentId(contest.getUser().getStudentId())
.likeCount(likeCount)
.dislikeCount(dislikeCount)
.isLiked(isLiked)
.isDisliked(isDisliked)
.photo(contest.getImg())
.createdAt(contest.getCreatedAt())
.updatedAt(contest.getUpdatedAt())
Expand Down

0 comments on commit b696d7e

Please sign in to comment.