Skip to content

Commit dc37e28

Browse files
authored
Merge pull request #84 from dnd-side-project/feat/#83
feat: 유저의 구독 사실 확인 api 추가 유저가 구독했을시 true 아닐경우 false 반환
2 parents d793881 + 6112283 commit dc37e28

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/main/java/com/moyeoit/domain/club/controller/ClubController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ public ApiResponse<?> getUserSubscribe(
7171
@PageableDefault(size = 12, direction = Sort.Direction.DESC) Pageable pageable) {
7272
return ApiResponse.success("유저의 동아리 구독 목록을 확인하였습니다.", clubService.subClubList(user.getId(), pageable));
7373
}
74+
75+
@GetMapping("/user-subscribe/check")
76+
public ApiResponse<?> checkUserSubscription(
77+
@Parameter(hidden = true) @CurrentUser AccessUser user,
78+
@RequestParam Long clubId) {
79+
boolean subscribed = clubService.findOutClubSub(clubId, user.getId());
80+
return ApiResponse.success("유저의 동아리 구독 사실을 확인하였습니다.",Map.of("subscribed",subscribed));
81+
}
7482
}

src/main/java/com/moyeoit/domain/club/repository/ClubSubscribeRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ public interface ClubSubscribeRepository extends JpaRepository<ClubSubscribe, Lo
1515

1616
@Query("SELECT count(cs) FROM ClubSubscribe cs WHERE cs.user.id = :userId")
1717
Long countByUserId(@Param("userId") Long userId);
18+
19+
boolean existsByClubAndUser(Club club, AppUser user);
1820
}

src/main/java/com/moyeoit/domain/club/service/ClubService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,11 @@ public boolean subscribeClub(Long clubId,Long userId){
100100
public Page<ClubListResponse> subClubList(Long userId,Pageable pageable){
101101
return clubRepository.findSubscribedClubs(userId,pageable).map(ClubListResponse::from);
102102
}
103+
104+
@Transactional(readOnly = true)
105+
public boolean findOutClubSub(Long clubId,Long userId){
106+
Club club = clubRepository.findById(clubId).orElseThrow(()->new AppException(ClubErrorCode.NOT_FOUND));
107+
AppUser user = userRepository.findById(userId).orElseThrow(()->new AppException(UserErrorCode.NOT_FOUND));
108+
return clubSubscribeRepository.existsByClubAndUser(club,user);
109+
}
103110
}

0 commit comments

Comments
 (0)