-
Notifications
You must be signed in to change notification settings - Fork 0
workflow 생성 api #211
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
workflow 생성 api #211
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8ed4c3c
feat: WorkflowCreateDto 초안
bwnfo3 98c92ee
feat: Workflow생성 관련 메서드, sql 추가
bwnfo3 6a0ed8d
feat: Workflow생성 임시 post api
bwnfo3 0bded96
feat: WorkflowCreateE2eTest 초안
bwnfo3 0246fe2
Merge branch 'develop' of github.com:Kernel180-BE12/Final-4team-iceba…
bwnfo3 ca37ca7
feat: WorkflowController 워크플로우 생성 api
bwnfo3 44c152b
feat: description @Null 제거
bwnfo3 74a8eb7
feat: 워크플로우 생성시 job,task 생성 메서드 추가
bwnfo3 92c5a32
feat: 워크플로우 생성시 job,task 생성 메서드 추가
bwnfo3 66bb71a
feat: 워크플로우 생성시 job,task 생성 메서드 구현중
bwnfo3 9a9d415
feat: 워크플로우 생성 e2eTest 작성중
bwnfo3 98d6514
Merge branch 'develop' of github.com:Kernel180-BE12/Final-4team-iceba…
bwnfo3 7ad0c5d
chore: spotlessApply
bwnfo3 5f4a940
feat: job,task 생성 없이 워크플로우 생성으로만 수정
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
112 changes: 112 additions & 0 deletions
112
apps/user-service/src/main/java/site/icebang/domain/workflow/dto/WorkflowCreateDto.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,112 @@ | ||
| package site.icebang.domain.workflow.dto; | ||
|
|
||
| import java.math.BigInteger; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import jakarta.validation.constraints.*; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * 워크플로우 생성 요청 DTO | ||
| * | ||
| * <p>프론트엔드에서 워크플로우 생성 시 필요한 모든 정보를 담는 DTO - 기본 정보: 이름, 설명 - 플랫폼 설정: 검색 플랫폼, 포스팅 플랫폼 - 계정 설정: 포스팅 계정 | ||
| * 정보 (JSON 형태로 저장) | ||
| */ | ||
| @Data | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class WorkflowCreateDto { | ||
| @Null private BigInteger id; | ||
|
|
||
| @NotBlank(message = "워크플로우 이름은 필수입니다") | ||
| @Size(max = 100, message = "워크플로우 이름은 100자를 초과할 수 없습니다") | ||
| @Pattern( | ||
| regexp = "^[가-힣a-zA-Z0-9\\s_-]+$", | ||
| message = "워크플로우 이름은 한글, 영문, 숫자, 공백, 언더스코어, 하이픈만 사용 가능합니다") | ||
| private String name; | ||
|
|
||
| @Size(max = 500, message = "설명은 500자를 초과할 수 없습니다") | ||
| private String description; | ||
|
|
||
| @Pattern(regexp = "^(naver|naver_store)?$", message = "검색 플랫폼은 'naver' 또는 'naver_store'만 가능합니다") | ||
| @JsonProperty("search_platform") | ||
| private String searchPlatform; | ||
|
|
||
| @Pattern( | ||
| regexp = "^(naver_blog|tstory_blog|blogger)?$", | ||
| message = "포스팅 플랫폼은 'naver_blog', 'tstory_blog', 'blogger' 중 하나여야 합니다") | ||
| @JsonProperty("posting_platform") | ||
| private String postingPlatform; | ||
|
|
||
| @Size(max = 100, message = "포스팅 계정 ID는 100자를 초과할 수 없습니다") | ||
| @JsonProperty("posting_account_id") | ||
| private String postingAccountId; | ||
|
|
||
| @Size(max = 200, message = "포스팅 계정 비밀번호는 200자를 초과할 수 없습니다") | ||
| @JsonProperty("posting_account_password") | ||
| private String postingAccountPassword; | ||
|
|
||
| @Size(max = 100, message = "블로그 이름은 100자를 초과할 수 없습니다") | ||
| @JsonProperty("blog_name") | ||
| private String blogName; | ||
|
|
||
| @Builder.Default | ||
| @JsonProperty("is_enabled") | ||
| private Boolean isEnabled = true; | ||
|
|
||
| // JSON 변환용 필드 (MyBatis에서 사용) | ||
| private String defaultConfigJson; | ||
|
|
||
| public String genertateDefaultConfigJson() { | ||
| StringBuilder jsonBuilder = new StringBuilder(); | ||
| jsonBuilder.append("{"); | ||
|
|
||
| // 크롤링 플랫폼 설정 (키: "1") | ||
| if (searchPlatform != null && !searchPlatform.isBlank()) { | ||
| jsonBuilder.append("\"1\": {\"tag\": \"").append(searchPlatform).append("\"}"); | ||
| } | ||
|
|
||
| // 포스팅 설정 (키: "8") | ||
| if (hasPostingConfig()) { | ||
| if (jsonBuilder.length() > 1) { | ||
| jsonBuilder.append(", "); | ||
| } | ||
| jsonBuilder | ||
| .append("\"8\": {") | ||
| .append("\"tag\": \"") | ||
| .append(postingPlatform) | ||
| .append("\", ") | ||
| .append("\"blog_id\": \"") | ||
| .append(postingAccountId) | ||
| .append("\", ") | ||
| .append("\"blog_pw\": \"") | ||
| .append(postingAccountPassword) | ||
| .append("\""); | ||
|
|
||
| // tstory_blog인 경우 blog_name 추가 | ||
| if ("tstory_blog".equals(postingPlatform) && blogName != null && !blogName.isBlank()) { | ||
| jsonBuilder.append(", \"blog_name\": \"").append(blogName).append("\""); | ||
| } | ||
|
|
||
| jsonBuilder.append("}"); | ||
| } | ||
|
|
||
| jsonBuilder.append("}"); | ||
| return jsonBuilder.toString(); | ||
| } | ||
|
|
||
| // 포스팅 설정 완성도 체크 (상태 확인 유틸) | ||
| public boolean hasPostingConfig() { | ||
| return postingPlatform != null | ||
| && !postingPlatform.isBlank() | ||
| && postingAccountId != null | ||
| && !postingAccountId.isBlank() | ||
| && postingAccountPassword != null | ||
| && !postingAccountPassword.isBlank(); | ||
| } | ||
| } |
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
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,19 +1,22 @@ | ||
| package site.icebang.domain.workflow.service; | ||
|
|
||
| import java.math.BigInteger; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import site.icebang.common.dto.PageParams; | ||
| import site.icebang.common.dto.PageResult; | ||
| import site.icebang.common.service.PageableService; | ||
| import site.icebang.domain.workflow.dto.ScheduleDto; | ||
| import site.icebang.domain.workflow.dto.WorkflowCardDto; | ||
| import site.icebang.domain.workflow.dto.WorkflowCreateDto; | ||
| import site.icebang.domain.workflow.dto.WorkflowDetailCardDto; | ||
| import site.icebang.domain.workflow.mapper.WorkflowMapper; | ||
|
|
||
|
|
@@ -32,6 +35,7 @@ | |
| * @author [email protected] | ||
| * @since v0.1.0 | ||
| */ | ||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class WorkflowService implements PageableService<WorkflowCardDto> { | ||
|
|
@@ -86,4 +90,72 @@ public WorkflowDetailCardDto getWorkflowDetail(BigInteger workflowId) { | |
|
|
||
| return workflow; | ||
| } | ||
|
|
||
| /** 워크플로우 생성 */ | ||
| @Transactional | ||
| public void createWorkflow(WorkflowCreateDto dto, BigInteger createdBy) { | ||
| // 1. 기본 검증 | ||
| validateBasicInput(dto, createdBy); | ||
|
|
||
| // 2. 비즈니스 검증 | ||
| validateBusinessRules(dto); | ||
|
|
||
| // 3. 중복체크 | ||
| if (workflowMapper.existsByName(dto.getName())) { | ||
| throw new IllegalArgumentException("이미 존재하는 워크플로우 이름입니다 : " + dto.getName()); | ||
| } | ||
|
|
||
|
Comment on lines
+103
to
+107
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.
|
||
| // 4. 워크플로우 생성 | ||
| try { | ||
| // JSON 설정 생성 | ||
| String defaultConfigJson = dto.genertateDefaultConfigJson(); | ||
| dto.setDefaultConfigJson(defaultConfigJson); | ||
|
|
||
| // DB 삽입 파라미터 구성 | ||
| Map<String, Object> params = new HashMap<>(); | ||
| params.put("dto", dto); | ||
| params.put("createdBy", createdBy); | ||
|
|
||
| int result = workflowMapper.insertWorkflow(params); | ||
| if (result != 1) { | ||
| throw new RuntimeException("워크플로우 생성에 실패했습니다"); | ||
| } | ||
|
|
||
| log.info("워크플로우 생성 완료: {} (생성자: {})", dto.getName(), createdBy); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("워크플로우 생성 실패: {}", dto.getName(), e); | ||
| throw new RuntimeException("워크플로우 생성 중 오류가 발생했습니다", e); | ||
| } | ||
| } | ||
|
|
||
| /** 기본 입력값 검증 */ | ||
| private void validateBasicInput(WorkflowCreateDto dto, BigInteger createdBy) { | ||
| if (dto == null) { | ||
| throw new IllegalArgumentException("워크플로우 정보가 필요합니다"); | ||
| } | ||
| if (createdBy == null) { | ||
| throw new IllegalArgumentException("생성자 정보가 필요합니다"); | ||
| } | ||
| } | ||
|
|
||
| /** 비즈니스 규칙 검증 */ | ||
| private void validateBusinessRules(WorkflowCreateDto dto) { | ||
| // 포스팅 플랫폼 선택 시 계정 정보 필수 검증 | ||
| String postingPlatform = dto.getPostingPlatform(); | ||
| if (postingPlatform != null && !postingPlatform.isBlank()) { | ||
| if (dto.getPostingAccountId() == null || dto.getPostingAccountId().isBlank()) { | ||
| throw new IllegalArgumentException("포스팅 플랫폼 선택 시 계정 ID는 필수입니다"); | ||
| } | ||
| if (dto.getPostingAccountPassword() == null || dto.getPostingAccountPassword().isBlank()) { | ||
| throw new IllegalArgumentException("포스팅 플랫폼 선택 시 계정 비밀번호는 필수입니다"); | ||
| } | ||
| // 티스토리 블로그 추가 검증 | ||
| if ("tstory_blog".equals(postingPlatform)) { | ||
| if (dto.getBlogName() == null || dto.getBlogName().isBlank()) { | ||
| throw new IllegalArgumentException("티스토리 블로그 선택 시 블로그 이름은 필수입니다"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+143
to
+160
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. DTO에서 valid를 통해 검증하고 있는데 중복 코드 같아요 |
||
| } | ||
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
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.
컨트롤러에서 AuthCredential을
@Authenticationprincipal어노테이션을 통해 주입 받는 다는 것은 AuthCredential 생성에 실패 (잘못된 인증 정보 or 인증 정보 없는 경우)등을 security 단에서 봐주기 때문에 필요없는 코드입니다.여담으로 인증관련은 Security 관련 exception을 내주시면 됩니다. IlligalArugmentException은 잘못된 값이 메서드에 전달되었을 때 발생하는 이슈 입니다.