Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,11 +1,11 @@
package com.dreamteam.alter.adapter.inbound.general.schedule.controller;

import com.dreamteam.alter.adapter.inbound.common.dto.CommonApiResponse;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleResponseDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.WorkScheduleInquiryRequestDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.WorkspaceScheduleResponseDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.*;
import com.dreamteam.alter.application.aop.AppActionContext;
import com.dreamteam.alter.domain.user.context.AppActor;
import com.dreamteam.alter.domain.workspace.port.inbound.GetMyDailyScheduleUseCase;
import com.dreamteam.alter.domain.workspace.port.inbound.GetMyMonthlyScheduleUseCase;
import com.dreamteam.alter.domain.workspace.port.inbound.GetMyScheduleUseCase;
import com.dreamteam.alter.domain.workspace.port.inbound.GetWorkspaceScheduleUseCase;
import jakarta.annotation.Resource;
Expand All @@ -27,6 +27,12 @@ public class UserScheduleController implements UserScheduleControllerSpec {
@Resource(name = "getMyWorkSchedule")
private final GetMyScheduleUseCase getMySchedule;

@Resource(name = "getMyDailySchedule")
private final GetMyDailyScheduleUseCase getMyDailySchedule;

@Resource(name = "getMyMonthlySchedule")
private final GetMyMonthlyScheduleUseCase getMyMonthlySchedule;

@Resource(name = "getWorkspaceWorkSchedule")
private final GetWorkspaceScheduleUseCase getWorkspaceSchedule;

Expand All @@ -40,6 +46,26 @@ public ResponseEntity<CommonApiResponse<List<MyScheduleResponseDto>>> getMySched
return ResponseEntity.ok(CommonApiResponse.of(getMySchedule.execute(actor, request)));
}

@Override
@GetMapping("/self/monthly")
public ResponseEntity<CommonApiResponse<MyScheduleMonthlyResponseDto>> getMyMonthlySchedule(
MonthlyWorkScheduleInquiryRequestDto request
) {
AppActor actor = AppActionContext.getInstance().getActor();

return ResponseEntity.ok(CommonApiResponse.of(getMyMonthlySchedule.execute(actor, request)));
}

@Override
@GetMapping("/self/daily")
public ResponseEntity<CommonApiResponse<List<MyScheduleResponseDto>>> getMyDailySchedule(
DailyWorkScheduleInquiryRequestDto request
) {
AppActor actor = AppActionContext.getInstance().getActor();

return ResponseEntity.ok(CommonApiResponse.of(getMyDailySchedule.execute(actor, request)));
}

@Override
@GetMapping("/workspaces/{workspaceId}")
public ResponseEntity<CommonApiResponse<List<WorkspaceScheduleResponseDto>>> getWorkspaceSchedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.dreamteam.alter.adapter.inbound.common.dto.CommonApiResponse;
import com.dreamteam.alter.adapter.inbound.common.dto.ErrorResponse;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleResponseDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.WorkScheduleInquiryRequestDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.WorkspaceScheduleResponseDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -29,6 +27,24 @@ ResponseEntity<CommonApiResponse<List<MyScheduleResponseDto>>> getMySchedule(
WorkScheduleInquiryRequestDto request
);

@Operation(summary = "나의 월별 근무 스케쥴 조회", description = "특정 월의 총 근무시간과 스케줄 목록을 조회합니다. year, month 값을 모두 포함해야합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "월별 스케줄 조회 성공")
})
ResponseEntity<CommonApiResponse<MyScheduleMonthlyResponseDto>> getMyMonthlySchedule(
MonthlyWorkScheduleInquiryRequestDto request
);

@Operation(summary = "나의 일별 근무 스케줄 조회", description = "특정 일의 상세 스케줄 목록을 조회합니다. year, month, day 값을 모두 포함해야합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "일별 스케줄 조회 성공")
})
ResponseEntity<CommonApiResponse<List<MyScheduleResponseDto>>> getMyDailySchedule(
DailyWorkScheduleInquiryRequestDto request
);



@Operation(summary = "업장별 근무 스케줄 조회", description = "year, month 값을 모두 포함해야합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "스케줄 조회 성공"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dreamteam.alter.adapter.inbound.general.schedule.dto;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ParameterObject
@Schema(description = "일별 스케줄 조회 요청")
public class DailyWorkScheduleInquiryRequestDto {

@Parameter(description = "조회할 연도", required = true, example = "2024")
private Integer year;

@Parameter(description = "조회할 월", required = true, example = "5")
private Integer month;

@Parameter(description = "조회할 일", required = true, example = "20")
private Integer day;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.dreamteam.alter.adapter.inbound.general.schedule.dto;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ParameterObject
@Schema(description = "월별 스케줄 조회 요청")
public class MonthlyWorkScheduleInquiryRequestDto {

@Parameter(description = "조회할 연도", required = true, example = "2024")
private Integer year;

@Parameter(description = "조회할 월", required = true, example = "5")
private Integer month;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.dreamteam.alter.adapter.inbound.general.schedule.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
@Schema(description = "내 월별 스케쥴 응답")
public class MyScheduleMonthlyResponseDto {

@Schema(description = "월 총 근무시간", example = "160.5")
private double totalWorkHoursInMonth;

@Schema(description = "월별 스케쥴 목록")
private List<MyScheduleResponseDto> schedules;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public class WorkScheduleInquiryRequestDto {

@Parameter(description = "조회할 월")
private Integer month;

@Parameter(description = "조회할 일 (일별 조회 시 사용)")
private Integer day;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public List<WorkspaceShift> findByUserAndWeeklyRange(User user, LocalDate startD
.fetch();
}

@Override
public List<WorkspaceShift> findByUserAndDate(User user, int year, int month, int day) {
LocalDateTime startOfDay = LocalDateTime.of(year, month, day, 0, 0, 0);
LocalDateTime endOfDay = startOfDay.plusDays(1);
return queryFactory
.selectFrom(workspaceShift)
.where(
workspaceShift.assignedWorkspaceWorker.user.eq(user),
workspaceShift.startDateTime.goe(startOfDay),
workspaceShift.startDateTime.lt(endOfDay)
)
.orderBy(workspaceShift.startDateTime.asc())
.fetch();
}

@Override
public List<WorkspaceShift> findByWorkspaceAndDateRange(Workspace workspace, int year, int month) {
return queryFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.dreamteam.alter.application.workspace.usecase;

import com.dreamteam.alter.adapter.inbound.general.schedule.dto.DailyWorkScheduleInquiryRequestDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleResponseDto;
import com.dreamteam.alter.domain.user.context.AppActor;
import com.dreamteam.alter.domain.workspace.entity.WorkspaceShift;
import com.dreamteam.alter.domain.workspace.port.inbound.GetMyDailyScheduleUseCase;
import com.dreamteam.alter.domain.workspace.port.outbound.WorkspaceShiftQueryRepository;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service("getMyDailySchedule")
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GetMyDailySchedule implements GetMyDailyScheduleUseCase {

private final WorkspaceShiftQueryRepository workspaceShiftQueryRepository;

@Override
public List<MyScheduleResponseDto> execute(AppActor actor, @MonotonicNonNull DailyWorkScheduleInquiryRequestDto request) {

List<WorkspaceShift> dailyShifts = workspaceShiftQueryRepository.findByUserAndDate(
actor.getUser(),
request.getYear(),
request.getMonth(),
request.getDay()
);

return dailyShifts.stream()
.map(MyScheduleResponseDto::of)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.dreamteam.alter.application.workspace.usecase;

import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MonthlyWorkScheduleInquiryRequestDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleMonthlyResponseDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleResponseDto;
import com.dreamteam.alter.domain.user.context.AppActor;
import com.dreamteam.alter.domain.workspace.entity.WorkspaceShift;
import com.dreamteam.alter.domain.workspace.port.inbound.GetMyMonthlyScheduleUseCase;
import com.dreamteam.alter.domain.workspace.port.outbound.WorkspaceShiftQueryRepository;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Duration;
import java.util.List;

@Service("getMyMonthlySchedule")
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GetMyMonthlySchedule implements GetMyMonthlyScheduleUseCase {

private final WorkspaceShiftQueryRepository workspaceShiftQueryRepository;

@Override
public MyScheduleMonthlyResponseDto execute(AppActor actor, @MonotonicNonNull MonthlyWorkScheduleInquiryRequestDto request) {


List<WorkspaceShift> shifts = workspaceShiftQueryRepository.findByUserAndDateRange(
actor.getUser(),
request.getYear(),
request.getMonth()
);

double totalWorkHours = shifts.stream()
.mapToDouble(shift -> {
Duration duration = Duration.between(shift.getStartDateTime(), shift.getEndDateTime());
return duration.toMinutes() / 60.0;
})
.sum();

List<MyScheduleResponseDto> scheduleDtos = shifts.stream()
.map(MyScheduleResponseDto::of)
.toList();
return MyScheduleMonthlyResponseDto.builder()
.totalWorkHoursInMonth(totalWorkHours)
.schedules(scheduleDtos)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dreamteam.alter.domain.workspace.port.inbound;

import com.dreamteam.alter.adapter.inbound.general.schedule.dto.DailyWorkScheduleInquiryRequestDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleResponseDto;
import com.dreamteam.alter.domain.user.context.AppActor;

import java.util.List;

public interface GetMyDailyScheduleUseCase {
List<MyScheduleResponseDto> execute(AppActor actor, DailyWorkScheduleInquiryRequestDto request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.dreamteam.alter.domain.workspace.port.inbound;

import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MonthlyWorkScheduleInquiryRequestDto;
import com.dreamteam.alter.adapter.inbound.general.schedule.dto.MyScheduleMonthlyResponseDto;
import com.dreamteam.alter.domain.user.context.AppActor;

public interface GetMyMonthlyScheduleUseCase {
MyScheduleMonthlyResponseDto execute(AppActor actor, MonthlyWorkScheduleInquiryRequestDto request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public interface WorkspaceShiftQueryRepository {
List<WorkspaceShift> findByUserAndDateRange(User user, int year, int month);
List<WorkspaceShift> findByUserAndWeeklyRange(User user, LocalDate startDate, LocalDate endDate);
List<WorkspaceShift> findByUserAndDate(User user, int year, int month, int day);
List<WorkspaceShift> findByWorkspaceAndDateRange(Workspace workspace, int year, int month);
List<WorkspaceShift> findByManagerAndDateRange(ManagerUser managerUser, Long workspaceId, int year, int month);
Optional<WorkspaceShift> findById(Long id);
Expand Down