-
Notifications
You must be signed in to change notification settings - Fork 0
Schedule 생성 api #216
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
Merged
Merged
Schedule 생성 api #216
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6296dcf
feat: ScheduleCreateDto
bwnfo3 821a478
feat: ScheduleMapper 스케줄 생성 관련 메서드 추가
bwnfo3 9523385
feat: WorkflowCreateDto에 스케줄 관련 추가
bwnfo3 72c9a10
feat: CreateWorkflow메서드에 스케줄 등록 추가
bwnfo3 c7fc11c
feat: WorkflowCreateFlowE2eTest에 스케줄 등록 관련 테스트 코드 추가
bwnfo3 140698f
chore: spotlessApply
bwnfo3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
103 changes: 103 additions & 0 deletions
103
apps/user-service/src/main/java/site/icebang/domain/workflow/dto/ScheduleCreateDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| .parameters(this.parameters) | ||
| .createdBy(userId) | ||
| .updatedBy(userId) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
@@ -14,7 +16,10 @@ | |
| * 워크플로우 생성 요청 DTO | ||
| * | ||
| * <p>프론트엔드에서 워크플로우 생성 시 필요한 모든 정보를 담는 DTO - 기본 정보: 이름, 설명 - 플랫폼 설정: 검색 플랫폼, 포스팅 플랫폼 - 계정 설정: 포스팅 계정 | ||
| * 정보 (JSON 형태로 저장) | ||
| * 정보 (JSON 형태로 저장) - 스케줄 설정: 선택적으로 여러 스케줄 등록 가능 | ||
| * | ||
| * @author [email protected] | ||
| * @since v0.1.0 | ||
| */ | ||
| @Data | ||
| @Builder | ||
|
|
@@ -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; | ||
|
|
||
|
|
@@ -109,4 +126,13 @@ public boolean hasPostingConfig() { | |
| && postingAccountPassword != null | ||
| && !postingAccountPassword.isBlank(); | ||
| } | ||
|
|
||
| /** | ||
| * 스케줄 설정이 있는지 확인 | ||
| * | ||
| * @return 스케줄이 1개 이상 있으면 true | ||
| */ | ||
| public boolean hasSchedules() { | ||
| return schedules != null && !schedules.isEmpty(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여담으로 이런 방법도 있긴 합니다. import org.springframework.util.CollectionUtils;
public boolean hasSchedules() {
return !CollectionUtils.isEmpty(schedules);
} |
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정적 팩토리 메서드로 변경해주시면 좋을 것 같습니다.