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 @@ -3,10 +3,94 @@
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import site.icebang.domain.schedule.model.Schedule;

/**
* Schedule 데이터베이스 접근을 위한 MyBatis Mapper 인터페이스
*
* <p>워크플로우의 스케줄 정보를 관리하며, 한 워크플로우에 여러 스케줄을 등록할 수 있지만 같은 크론식의 중복 등록은 방지합니다.
*
* @author [email protected]
* @since v0.1.0
*/
@Mapper
public interface ScheduleMapper {

/**
* 활성화된 모든 스케줄 조회
*
* @return 활성 상태인 스케줄 목록
*/
List<Schedule> findAllActive();

/**
* 새로운 스케줄 등록
*
* @param schedule 등록할 스케줄 정보
* @return 영향받은 행 수 (1: 성공, 0: 실패)
*/
int insertSchedule(Schedule schedule);

/**
* 특정 워크플로우의 모든 활성 스케줄 조회
*
* @param workflowId 조회할 워크플로우 ID
* @return 해당 워크플로우의 활성 스케줄 목록
*/
List<Schedule> findAllByWorkflowId(@Param("workflowId") Long workflowId);

/**
* 특정 워크플로우에서 특정 크론식이 이미 존재하는지 확인
*
* @param workflowId 워크플로우 ID
* @param cronExpression 확인할 크론 표현식
* @return 중복 여부 (true: 이미 존재함, false: 존재하지 않음)
*/
boolean existsByWorkflowIdAndCronExpression(
@Param("workflowId") Long workflowId, @Param("cronExpression") String cronExpression);

/**
* 특정 워크플로우의 특정 크론식을 가진 스케줄 조회
*
* @param workflowId 워크플로우 ID
* @param cronExpression 크론 표현식
* @return 해당하는 스케줄 (없으면 null)
*/
Schedule findByWorkflowIdAndCronExpression(
@Param("workflowId") Long workflowId, @Param("cronExpression") String cronExpression);

/**
* 스케줄 활성화 상태 변경
*
* @param id 스케줄 ID
* @param isActive 활성화 여부
* @return 영향받은 행 수
*/
int updateActiveStatus(@Param("id") Long id, @Param("isActive") boolean isActive);

/**
* 스케줄 정보 수정 (크론식, 설명 등)
*
* @param schedule 수정할 스케줄 정보
* @return 영향받은 행 수
*/
int updateSchedule(Schedule schedule);

/**
* 스케줄 삭제 (soft delete)
*
* @param id 삭제할 스케줄 ID
* @return 영향받은 행 수
*/
int deleteSchedule(@Param("id") Long id);

/**
* 워크플로우의 모든 스케줄 비활성화
*
* @param workflowId 워크플로우 ID
* @return 영향받은 행 수
*/
int deactivateAllByWorkflowId(@Param("workflowId") Long workflowId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package site.icebang.domain.workflow.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import site.icebang.domain.schedule.model.Schedule;

/**
* 스케줄 생성 요청 DTO
*
* <p>워크플로우 생성 시 함께 등록할 스케줄 정보를 담습니다.
*
* <p>역할: - API 요청 시 클라이언트로부터 스케줄 정보 수신 - 입력값 검증 (형식, 길이 등) - Schedule(Model)로 변환되어 DB 저장
*
* <p>기존 ScheduleDto(응답용)와 통일성을 위해 camelCase 사용
*
* @author [email protected]
* @since v0.1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ScheduleCreateDto {
/**
* 크론 표현식 (필수)
*
* <p>Quartz 크론 표현식 형식을 따릅니다.
*
* <ul>
* <li>초 분 시 일 월 요일 (년도)
* <li>예시: "0 9 * * *" (매일 9시 0분 0초)
* <li>예시: "0 0 14 * * MON-FRI" (평일 오후 2시)
* </ul>
*
* <p>정밀한 유효성 검증은 서비스 레이어에서 Quartz CronExpression으로 수행됩니다.
*/
@NotBlank(message = "크론 표현식은 필수입니다")
@Size(max = 50, message = "크론 표현식은 50자를 초과할 수 없습니다")
private String cronExpression;

/**
* 사용자 친화적 스케줄 설명
*
* <p>UI에 표시될 스케줄 설명입니다. 자동으로 생성됩니다.
*
* <ul>
* <li>예시: "매일 오전 9시"
* <li>예시: "평일 오후 2시"
* <li>예시: "매주 금요일 6시"
* </ul>
*/
@Size(max = 20, message = "스케줄 설명은 자동으로 생성됩니다")
private String scheduleText;

/**
* 스케줄 활성화 여부 (기본값: true)
*
* <p>false일 경우 DB에는 저장되지만 Quartz에 등록되지 않습니다.
*/
@Builder.Default private Boolean isActive = true;

/**
* 스케줄 실행 시 추가 파라미터 (선택, JSON 형식)
*
* <p>워크플로우 실행 시 전달할 추가 파라미터를 JSON 문자열로 저장합니다.
*
* <pre>{@code
* // 예시:
* {
* "retryCount": 3,
* "timeout": 300,
* "notifyOnFailure": true
* }
* }</pre>
*/
private String parameters;

/**
* Schedule(Model) 엔티티로 변환
*
* <p>DTO의 정보를 DB 저장용 엔티티로 변환하며, 서비스 레이어에서 주입되는 workflowId와 userId를 함께 설정합니다.
*
* @param workflowId 연결할 워크플로우 ID
* @param userId 생성자 ID
* @return DB 저장 가능한 Schedule 엔티티
*/
public Schedule toEntity(Long workflowId, Long userId) {
return Schedule.builder()
.workflowId(workflowId)
.cronExpression(this.cronExpression)
.scheduleText(this.scheduleText)
.isActive(this.isActive != null ? this.isActive : true)
Comment on lines +92 to +97
Copy link
Collaborator

@can019 can019 Sep 27, 2025

Choose a reason for hiding this comment

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

정적 팩토리 메서드로 변경해주시면 좋을 것 같습니다.

  1. 객체 책임 명확화
  2. DTO의 역할
  • DTO 내부 상태를 변경하는 작업이 아니기 때문에 인스턴스 메서드가 아닌 클래스 레벨로 두는 것이 좋을 것 같습니다.
public static Schedule toEntity(ScheduleRequestDto dto, Long workflowId, Long userId) {
        return Schedule.builder()
            .workflowId(workflowId)
            // 인스턴스가 아닌 정적 메서드의 인수로 받은 dto를 사용
            .cronExpression(dto.cronExpression) 
            .scheduleText(dto.scheduleText)
            .isActive(dto.isActive != null ? dto.isActive : true)
            .parameters(dto.parameters)
            .createdBy(userId)
            .updatedBy(userId)
            .build();
    }

.parameters(this.parameters)
.createdBy(userId)
.updatedBy(userId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package site.icebang.domain.workflow.dto;

import java.math.BigInteger;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -14,7 +16,10 @@
* 워크플로우 생성 요청 DTO
*
* <p>프론트엔드에서 워크플로우 생성 시 필요한 모든 정보를 담는 DTO - 기본 정보: 이름, 설명 - 플랫폼 설정: 검색 플랫폼, 포스팅 플랫폼 - 계정 설정: 포스팅 계정
* 정보 (JSON 형태로 저장)
* 정보 (JSON 형태로 저장) - 스케줄 설정: 선택적으로 여러 스케줄 등록 가능
*
* @author [email protected]
* @since v0.1.0
*/
@Data
@Builder
Expand Down Expand Up @@ -59,6 +64,18 @@ public class WorkflowCreateDto {
@JsonProperty("is_enabled")
private Boolean isEnabled = true;

/**
* 워크플로우에 등록할 스케줄 목록 (선택사항)
*
* <p>사용 시나리오:
*
* <ul>
* <li>null 또는 빈 리스트: 스케줄 없이 워크플로우만 생성
* <li>1개 이상: 해당 스케줄들을 함께 등록 (트랜잭션 보장)
* </ul>
*/
@Valid private List<@Valid ScheduleCreateDto> schedules;

// JSON 변환용 필드 (MyBatis에서 사용)
private String defaultConfigJson;

Expand Down Expand Up @@ -109,4 +126,13 @@ public boolean hasPostingConfig() {
&& postingAccountPassword != null
&& !postingAccountPassword.isBlank();
}

/**
* 스케줄 설정이 있는지 확인
*
* @return 스케줄이 1개 이상 있으면 true
*/
public boolean hasSchedules() {
return schedules != null && !schedules.isEmpty();
Copy link
Collaborator

Choose a reason for hiding this comment

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

여담으로 이런 방법도 있긴 합니다.

import org.springframework.util.CollectionUtils;
 public boolean hasSchedules() {
  return !CollectionUtils.isEmpty(schedules);
}

}
}
Loading
Loading