Skip to content

Commit 2787e41

Browse files
authored
Merge pull request #243 from MoneyMakersClub/develop
[DEPLOY] 최근 생성된, 모집 중인 클럽 보기 API 배포
2 parents e593226 + 836a4ad commit 2787e41

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

bookduck/src/main/java/com/mmc/bookduck/domain/club/controller/ClubController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public ResponseEntity<Long> createClub(@Valid @RequestBody ClubCreateRequestDto
4040
.body(clubId); // body에 clubId 리턴
4141
}
4242

43+
@Operation(summary = "최근 모집 중인 클럽 보기", description = "최근 생성된, 모집 중인 클럽을 표시합니다.")
44+
@GetMapping("/new")
45+
public ResponseEntity<ClubSearchListResponseDto> findRecentActiveClubs(Pageable pageable) {
46+
return ResponseEntity.ok(clubService.findRecentActiveClubs(pageable));
47+
}
48+
4349
@Operation(summary = "클럽 검색", description = "클럽명, 책 제목, 저자명으로 클럽을 검색합니다. 정렬 기준: 정확도순 > 가입인원순 > 최근생성순 > 곧종료순")
4450
@GetMapping("/search")
4551
public ResponseEntity<ClubSearchListResponseDto> searchClubs(

bookduck/src/main/java/com/mmc/bookduck/domain/club/dto/response/ClubSearchListResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@Builder
99
@Schema(description = "클럽 검색 목록 응답 DTO")
1010
public record ClubSearchListResponseDto(
11-
@Schema(description = "검색된 클럽 목록") PaginatedResponseDto<ClubSearchResponseDto> clubs
11+
@Schema(description = "클럽 목록") PaginatedResponseDto<ClubSearchResponseDto> clubs
1212
) {
1313
public static ClubSearchListResponseDto from(Page<ClubSearchResponseDto> clubPage) {
1414
return ClubSearchListResponseDto.builder()

bookduck/src/main/java/com/mmc/bookduck/domain/club/dto/response/ClubSearchResponseDto.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
import com.mmc.bookduck.domain.book.entity.BookInfo;
44
import com.mmc.bookduck.domain.club.dto.common.ClubBookInfoDto;
55
import com.mmc.bookduck.domain.club.entity.Club;
6-
import com.mmc.bookduck.domain.club.entity.ClubMember;
76
import com.mmc.bookduck.domain.club.entity.ClubStatus;
87
import io.swagger.v3.oas.annotations.media.Schema;
98
import lombok.Builder;
109

11-
import java.awt.print.Book;
1210
import java.time.LocalDate;
13-
import java.time.LocalDateTime;
14-
import java.util.List;
1511

1612
@Builder
1713
@Schema(description = "클럽 검색 응답 DTO")

bookduck/src/main/java/com/mmc/bookduck/domain/club/dto/response/ClubUpdateResponseDto.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import lombok.Builder;
77

88
import java.time.LocalDate;
9-
import java.time.LocalDateTime;
109

1110
@Builder
1211
@Schema(description = "클럽 정보 수정 응답 DTO")

bookduck/src/main/java/com/mmc/bookduck/domain/club/repository/ClubRepository.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Page<Club> searchClubs(@Param("keyword") String keyword,
3535
Pageable pageable);
3636

3737
@Query("SELECT c FROM Club c WHERE c.clubStatus = :status AND c.activeEndAt < :now")
38-
List<Club> findByStatusAndActiveEndAtBefore(@Param("status") ClubStatus status,
39-
@Param("now") LocalDateTime now);
38+
List<Club> findByClubStatusAndActiveEndAtBefore(@Param("status") ClubStatus status,
39+
@Param("now") LocalDateTime now);
40+
41+
Page<Club> findByClubStatusOrderByCreatedTimeDesc(ClubStatus status, Pageable pageable);
4042
}

bookduck/src/main/java/com/mmc/bookduck/domain/club/service/ClubService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,17 @@ public LocalDateTime getLastReadAt(ClubMember clubMember) {
354354
.map(ClubMemberReadStatus::getLastReadAt)
355355
.orElse(LocalDateTime.MIN);
356356
}
357+
358+
@Transactional(readOnly = true)
359+
public ClubSearchListResponseDto findRecentActiveClubs(Pageable pageable) {
360+
Page<Club> clubPage = clubRepository.findByClubStatusOrderByCreatedTimeDesc(ClubStatus.ACTIVE, pageable);
361+
362+
Page<ClubSearchResponseDto> dtoPage = clubPage.map(club -> {
363+
BookInfo bookInfo = club.getBookInfo();
364+
int memberCount = Math.toIntExact(clubMemberService.countByClub(club)); // 현재 가입 인원 수
365+
return ClubSearchResponseDto.from(club, bookInfo, memberCount);
366+
});
367+
368+
return ClubSearchListResponseDto.from(dtoPage);
369+
}
357370
}

bookduck/src/main/java/com/mmc/bookduck/global/schedule/ClubStatusScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ClubStatusScheduler {
2424
@Transactional
2525
public void updateExpiredClubs() {
2626
try {
27-
List<Club> expiredClubs = clubRepository.findByStatusAndActiveEndAtBefore(
27+
List<Club> expiredClubs = clubRepository.findByClubStatusAndActiveEndAtBefore(
2828
ClubStatus.ACTIVE, LocalDateTime.now());
2929
if (expiredClubs.isEmpty()) {
3030
log.info("종료된 클럽 없음.");

0 commit comments

Comments
 (0)