🚀 요구 사항

/**
 * 서비스 클래스: DashboardService
 * 사용자의 대시보드 정보를 생성하는 서비스로, 일정(Schedules)과 할 일(Todos) 정보를 조회하고 가공합니다.
 */
public class DashboardService {
    // 의존성 주입: UserService, SchedulesService, TodosService
    // 각각 사용자 정보, 일정 정보, 할 일 정보를 처리하는 서비스 클래스들
    private final UserService userService;
    private final SchedulesService schedulesService;
    private final TodosService todosService;

    /**
     * 사용자의 대시보드 정보를 조회합니다.
     * @param searchRequestDto 검색 요청 데이터 (조회할 연도와 월 정보 포함)
     * @return DashBoardDto 대시보드 정보를 담은 객체
     */
    public DashBoardDto getDashBoardInfo(SearchRequestDto searchRequestDto) {
        // 현재 로그인한 사용자의 ID를 조회합니다.
        Long userId = userService.getUserId();

        // SearchRequestDto에서 전달된 targetDate를 기반으로 YearMonth 객체 생성
        // YearMonth는 특정 연도와 월을 표현하기 위한 클래스입니다.
        YearMonth yearMonth = YearMonth.of(
            searchRequestDto.getTargetDate().getYear(),
            searchRequestDto.getTargetDate().getMonth()
        );

        // 대시보드 정보 객체 초기화
        DashBoardDto dashBoardDto = new DashBoardDto();

        // 해당 월에 해당하는 일정 정보를 조회하여 대시보드에 설정
        dashBoardDto.setSchedulesDtoList(searchScheduleList(yearMonth));

        // 해당 월에 해당하는 할 일 정보를 조회하여 대시보드에 설정
        dashBoardDto.setTodayList(searchTodosList(yearMonth));

        // 완성된 대시보드 정보를 반환
        return dashBoardDto;
    }

    /**
     * 일정 정보를 조회합니다.
     * @param yearMonth 조회할 연도와 월을 표현하는 YearMonth 객체
     * @return List<SchedulesModel> 일정 정보를 담은 모델 리스트
     */
    private List<SchedulesModel> searchScheduleList(YearMonth yearMonth) {
        // 일정 검색 조건을 설정
        SearchSchedulesDto searchSchedulesDto = new SearchSchedulesDto();

        // 검색 시작일: 해당 월의 첫째 날
        searchSchedulesDto.setStartDate(yearMonth.atDay(1));

        // 검색 종료일: 해당 월의 마지막 날
        searchSchedulesDto.setEndDate(yearMonth.atEndOfMonth());

        // SchedulesService를 호출하여 조건에 맞는 일정 리스트를 조회
        List<SchedulesEntity> schedulesEntityList = schedulesService.getDetailScheduleList(searchSchedulesDto);

        // 조회된 엔티티 리스트를 모델 리스트로 변환하여 반환
        // SchedulesModel의 생성자를 사용하여 각 엔티티를 모델 객체로 변환
        return schedulesEntityList.stream().map(SchedulesModel::new).toList();
    }

    /**
     * 할 일 정보를 조회합니다.
     * @param yearMonth 조회할 연도와 월을 표현하는 YearMonth 객체
     * @return List<TodosModel> 할 일 정보를 담은 모델 리스트
     */
    private List<TodosModel> searchTodosList(YearMonth yearMonth) {
        // 할 일 검색 조건을 설정
        TodosDtoSearchDto todosDtoSearchDto = new TodosDtoSearchDto();

        // 검색 시작일: 해당 월의 첫째 날
        todosDtoSearchDto.setStartDate(yearMonth.atDay(1));

        // 검색 종료일: 해당 월의 마지막 날
        todosDtoSearchDto.setDueDate(yearMonth.atEndOfMonth());

        // TodosService를 호출하여 조건에 맞는 할 일 리스트를 조회
        List<TodosEntity> todosEntityList = todosService.getDetailTodosList(todosDtoSearchDto)
            .stream() // 스트림 생성
            // 상태가 PENDING(대기 중) 또는 IN_PROGRESS(진행 중)인 항목만 필터링
            .filter(item -> item.getStatus().equals(TodoStatus.PENDING.code()) ||
                            item.getStatus().equals(TodoStatus.IN_PROGRESS.code()))
            .toList(); // 필터링 결과를 리스트로 변환

        // 조회된 엔티티 리스트를 모델 리스트로 변환하여 반환
        // TodosModel의 생성자를 사용하여 각 엔티티를 모델 객체로 변환
        return todosEntityList.stream().map(TodosModel::new).toList();
    }
}


주요 개념 설명

  1. YearMonth:
  2. stream():
  3. 의존성 주입:
  4. DTO와 Entity 변환:

이 코드의 흐름

  1. 사용자 ID 조회: 로그인된 사용자의 ID를 가져옵니다.
  2. 대시보드 정보 생성:
  3. 데이터 변환:
  4. 대시보드 DTO 구성: 모든 데이터를 DashBoardDto에 담아 반환합니다.

목적