Skip to content

Commit

Permalink
[FEAT] 특정 챌린지 참가자의 독서 캘린더 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
EunbeenDev committed Mar 7, 2025
1 parent 4cb12ee commit 750ca13
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.nookbook.domain.challenge.dto.response.ChallengeInvitationRes;
import com.nookbook.domain.challenge.dto.response.ChallengeListRes;
import com.nookbook.domain.challenge.dto.response.ParticipantListRes;
import com.nookbook.domain.user_book.application.UserBookService;
import com.nookbook.domain.user_book.dto.response.DailyUserBookCalendarRes;
import com.nookbook.global.config.security.token.CurrentUser;
import com.nookbook.global.config.security.token.UserPrincipal;
import com.nookbook.global.payload.ErrorResponse;
Expand All @@ -30,6 +32,7 @@
public class ChallengeController {

private final ChallengeService challengeService;
private final UserBookService userBookService;

// 새 챌린지 생성 API
@Operation(summary = "새 챌린지 생성 API", description = "새 챌린지를 생성하는 API입니다.")
Expand Down Expand Up @@ -234,4 +237,21 @@ public ResponseEntity<?> leaveChallenge(
}


// 챌린지 참가자의 독서 기록 정보 조회 API
// 날짜 형식: 2021-11-01 또는 2021-11
@Operation(summary = "챌린지 참가자의 날짜별 독서 기록 조회", description = "챌린지 참가자의 날짜별 독서 기록을 조회합니다.")
@GetMapping("{participantId}/calendar/{date}")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "독서 캘린더 조회 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = DailyUserBookCalendarRes.class)) } ),
@ApiResponse(responseCode = "400", description = "독서 캘린더 조회 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
} )
public ResponseEntity<?> getUserBookCalendar(
@Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "참가자 ID를 입력해주세요.", required = true) @PathVariable Long participantId,
@Parameter(description = "조회할 날짜를 입력해주세요.", example = "2021-11-01", required = true) @PathVariable String date
) {
return userBookService.getUserBookCalendar(userPrincipal, participantId, date);
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nookbook.domain.user_book.application;

import com.nookbook.domain.challenge.application.ParticipantService;
import com.nookbook.domain.challenge.domain.Participant;
import com.nookbook.domain.timer.application.TimerService;
import com.nookbook.domain.timer.domain.Timer;
import com.nookbook.domain.user.application.UserService;
Expand Down Expand Up @@ -38,7 +40,9 @@ public class UserBookService {
private final TimerService timerService;

private final UserRepository userRepository;
private final ParticipantService participantService;

// 사용자의 독서 기록(캘린더) 조회
public ResponseEntity<?> getUserBookCalendar(UserPrincipal userPrincipal, String date) {
User user = validateUser(userPrincipal);
// 날짜 형식 판단 메소드
Expand All @@ -47,6 +51,19 @@ public ResponseEntity<?> getUserBookCalendar(UserPrincipal userPrincipal, String

}

// 특정 챌린지 참가자의 독서 기록(캘린더) 조회
public ResponseEntity<?> getUserBookCalendar(UserPrincipal userPrincipal,Long participantId, String date) {
validateUser(userPrincipal);
Participant participant = participantService.getParticipant(participantId);
User participantUser = participant.getUser();
// 날짜 형식 판단 메소드
// YYYY-MM-DD 형식 / YYYY-MM 형식
return distinctDateFormat(participantUser, date);

}



private ResponseEntity<?> distinctDateFormat(User user, String date) {
if (isValidDateFormat(date, "yyyy-MM")) {
log.info("YYYY-MM 형식");
Expand Down Expand Up @@ -103,7 +120,6 @@ private DailyUserBookCalendarRes getUserBookInfoByDate(User user, String date) {
.bookList(getBookListByDate(user, date))
.build();


}

private String sumTotalReadTime(List<Timer> timerList) {
Expand Down

0 comments on commit 750ca13

Please sign in to comment.