Skip to content
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 @@ -10,7 +10,7 @@
import java.util.UUID;

@ToString
@Getter
@Data
@NoArgsConstructor // 기본 생성자 추가
@AllArgsConstructor // 모든 필드를 포함하는 생성자 추가
public class ScheduleDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -21,4 +20,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
// socialType과 socialId으로 user 찾는 메소드
// 추가정보 입력받을때 사용
Optional<User> findBySocialTypeAndSocialId(SocialType socialType, String socialId);

@Query("SELECT u.spareTime FROM User u WHERE u.id = :id")
Integer findSpareTimeById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import devkor.ontime_back.response.ErrorCode;
import devkor.ontime_back.response.GeneralException;
import jakarta.persistence.EntityNotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
Expand All @@ -18,6 +17,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -50,6 +50,8 @@ private Schedule getScheduleWithAuthorization(UUID scheduleId, Long userId) {

// 특정 기간의 약속 조회
public List<ScheduleDto> showSchedulesByPeriod(Long userId, LocalDateTime startDate, LocalDateTime endDate) {
Integer userSpareTime = userRepository.findSpareTimeById(userId);

List<Schedule> periodScheduleList;
if (startDate == null && endDate != null) { // StartDate가 null인 경우, EndDate 이전의 일정 모두 반환
periodScheduleList = scheduleRepository.findAllByUserIdAndScheduleTimeBefore(userId, endDate);
Expand All @@ -63,7 +65,12 @@ public List<ScheduleDto> showSchedulesByPeriod(Long userId, LocalDateTime startD
}

return periodScheduleList.stream()
.map(this::mapToDto)
.map(schedule -> {
ScheduleDto scheduleDto = mapToDto(schedule);
// schedule의 spareTime이 null이면 userSpareTime을 사용
scheduleDto.setScheduleSpareTime(Optional.ofNullable(schedule.getScheduleSpareTime()).orElse(userSpareTime));
Copy link
Contributor

@jjjh02 jjjh02 Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entity에서는 @Setter 사용을 지양하는 쪽으로 코드 리팩토링을 진행했었는데 여기서는 DTO라 Entity와는 달리 단순히 데이터를 전달하는 역할이라 @Setter를 사용하신게 맞을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 DTO이고, DTO 내부에 따로 비즈니스 메서드가 있는것도 아니여서 Setter 사용에 무리가 없을 것 같습니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵넵! 확인했습니다

return scheduleDto;
})
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -201,7 +208,7 @@ private ScheduleDto mapToDto(Schedule schedule) {
schedule.getScheduleName(),
schedule.getMoveTime(),
schedule.getScheduleTime(),
schedule.getScheduleSpareTime(),
(schedule.getScheduleSpareTime() == null) ? schedule.getUser().getSpareTime() : schedule.getScheduleSpareTime(),
schedule.getScheduleNote(),
schedule.getLatenessTime()
);
Expand Down