Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: 친구 복약 일정 조회 API #85

Merged
merged 1 commit into from
Feb 11, 2024
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 @@ -33,6 +33,7 @@ public enum SuccessCode {
UNCHECK_PILL_SCHEDULE_SUCCESS(HttpStatus.OK, "복용 체크 취소에 성공했습니다."),
GET_MONTH_SCHEDULE_SUCCESS(HttpStatus.OK, "월 스케줄 조회에 성공했습니다"),
GET_DATE_SCHEDULE_SUCCESS(HttpStatus.OK, "일 스케줄 조회에 성공했습니다."),
GET_FRIEND_MONTH_SCHEDULE_SUCCESS(HttpStatus.OK, "친구 월 스케줄 조회에 성공했습니다."),

// friend
ADD_FRIEND_SUCCESS(HttpStatus.OK, "공유 요청에 성공했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.sobok.SobokSobok.auth.infrastructure.UserRepository;
import io.sobok.SobokSobok.exception.ErrorCode;
import io.sobok.SobokSobok.exception.model.ForbiddenException;
import io.sobok.SobokSobok.friend.infrastructure.FriendQueryRepository;
import io.sobok.SobokSobok.pill.domain.Pill;
import io.sobok.SobokSobok.pill.domain.PillSchedule;
import io.sobok.SobokSobok.pill.infrastructure.PillRepository;
Expand All @@ -28,6 +29,7 @@ public class PillScheduleService {
private final PillRepository pillRepository;
private final PillScheduleRepository pillScheduleRepository;
private final PillScheduleQueryRepository pillScheduleQueryRepository;
private final FriendQueryRepository friendQueryRepository;

@Transactional
public List<MonthScheduleResponse> getMonthSchedule(Long userId, LocalDate date) {
Expand All @@ -46,6 +48,21 @@ public List<DateScheduleResponse> getDateSchedule(Long userId, LocalDate date) {
return pillScheduleQueryRepository.getDateSchedule(userId, date);
}

@Transactional
public List<MonthScheduleResponse> getFriendMonthSchedule(Long userId, Long friendId, LocalDate date) {
UserServiceUtil.existsUserById(userRepository, userId);
UserServiceUtil.existsUserById(userRepository, friendId);

if (!friendQueryRepository.isAlreadyFriend(userId, friendId)) {
throw new ForbiddenException(ErrorCode.NOT_FRIEND);
}

LocalDate startDateOfMonth = DateUtil.getStartDateOfMonth(date);
LocalDate endDateOfMonth = DateUtil.getEndDateOfMonth(date);

return pillScheduleQueryRepository.getMonthSchedule(friendId, startDateOfMonth, endDateOfMonth);
}

@Transactional
public CheckPillScheduleResponse changePillScheduleCheck(Long userId, Long scheduleId, Boolean isCheck) {
UserServiceUtil.existsUserById(userRepository, userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public List<MonthScheduleResponse> getMonthSchedule(Long userId, LocalDate start
.leftJoin(pill).on(pill.id.eq(pillSchedule.pillId))
.where(
pill.userId.eq(userId),
pill.isStop.eq(false),
pillSchedule.scheduleDate.goe(startDate),
pillSchedule.scheduleDate.loe(endDate)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ public ResponseEntity<ApiResponse<List<DateScheduleResponse>>> getDateSchedule(
));
}

@GetMapping("/{memberId}/calendar")
@Operation(
summary = "친구 복약 일정 조회 API 메서드",
description = "path variable -> 친구의 userId, query string -> date (조회할 달의 아무 날짜)"
)
public ResponseEntity<ApiResponse<List<MonthScheduleResponse>>> getFriendMonthSchedule(
@AuthenticationPrincipal User user,
@PathVariable Long memberId,
@RequestParam LocalDate date
) {
return ResponseEntity
.status(HttpStatus.OK)
.body(ApiResponse.success(
SuccessCode.GET_FRIEND_MONTH_SCHEDULE_SUCCESS,
pillScheduleService.getFriendMonthSchedule(user.getId(), memberId, date)
));
}

@PutMapping("/check/{scheduleId}")
@Operation(
summary = "복용 체크 완료 API 메서드",
Expand Down
Loading