66import com .flowci .flow .business .FetchTemplateContent ;
77import com .flowci .flow .model .CreateFlowParam ;
88import com .flowci .flow .model .Flow ;
9+ import com .flowci .flow .model .FlowUser ;
910import com .flowci .flow .model .FlowYaml ;
1011import com .flowci .flow .repo .FlowRepo ;
12+ import com .flowci .flow .repo .FlowUserRepo ;
1113import com .flowci .flow .repo .FlowYamlRepo ;
1214import lombok .AllArgsConstructor ;
1315import lombok .extern .slf4j .Slf4j ;
@@ -23,6 +25,8 @@ public class CreateFlowImpl implements CreateFlow {
2325
2426 private final FlowYamlRepo flowYamlRepo ;
2527
28+ private final FlowUserRepo flowUserRepo ;
29+
2630 private final FetchTemplateContent fetchTemplateContent ;
2731
2832 private final RequestContextHolder requestContextHolder ;
@@ -32,6 +36,7 @@ public class CreateFlowImpl implements CreateFlow {
3236 public Flow invoke (CreateFlowParam param ) {
3337 var flow = flowRepo .save (toObject (param ));
3438 flowYamlRepo .save (toObject (flow , param ));
39+ flowUserRepo .save (toObject (flow ));
3540 log .info ("Created flow: {} by user {}" , flow .getName (), flow .getCreatedBy ());
3641 return flow ;
3742 }
@@ -41,19 +46,16 @@ private Flow toObject(CreateFlowParam param) {
4146 flow .setName (param .name ());
4247 flow .setType (Flow .Type .FLOW );
4348 flow .setVariables (Variables .EMPTY );
44- flow .setCreatedBy (requestContextHolder .getUser ());
45- flow .setUpdatedBy (requestContextHolder .getUser ());
46-
47- if (param .rootId () != null ) {
48- flow .setParentId (param .rootId ());
49- }
50-
49+ flow .setParentId (param .rootId () == null ? Flow .ROOT_ID : param .rootId ());
50+ flow .setCreatedBy (requestContextHolder .getUserId ());
51+ flow .setUpdatedBy (requestContextHolder .getUserId ());
5152 return flow ;
5253 }
5354
5455 private FlowYaml toObject (Flow flow , CreateFlowParam param ) {
5556 var flowYaml = new FlowYaml ();
5657 flowYaml .setId (flow .getId ());
58+ flowYaml .setYaml ("" );
5759 flowYaml .setCreatedBy (flow .getCreatedBy ());
5860 flowYaml .setUpdatedBy (flow .getUpdatedBy ());
5961
@@ -63,4 +65,13 @@ private FlowYaml toObject(Flow flow, CreateFlowParam param) {
6365
6466 return flowYaml ;
6567 }
68+
69+ private FlowUser toObject (Flow flow ) {
70+ var fu = new FlowUser ();
71+ fu .setFlowId (flow .getId ());
72+ fu .setUserId (flow .getCreatedBy ());
73+ fu .setCreatedBy (flow .getCreatedBy ());
74+ fu .setUpdatedBy (flow .getUpdatedBy ());
75+ return fu ;
76+ }
6677}
0 commit comments