33import com .flowci .common .exception .DuplicateException ;
44import com .flowci .common .exception .ExceptionUtils ;
55import com .flowci .common .validator .ValidId ;
6- import com .flowci .flow .business .CreateFlow ;
7- import com .flowci .flow .business .FetchFlow ;
8- import com .flowci .flow .business .FetchTemplates ;
9- import com .flowci .flow .business .ListFlows ;
6+ import com .flowci .flow .business .*;
107import com .flowci .flow .model .CreateFlowParam ;
118import com .flowci .flow .model .Flow ;
129import com .flowci .flow .model .YamlTemplate ;
10+ import io .swagger .v3 .oas .annotations .Operation ;
11+ import io .swagger .v3 .oas .annotations .Parameter ;
12+ import io .swagger .v3 .oas .annotations .media .Content ;
13+ import io .swagger .v3 .oas .annotations .media .ExampleObject ;
14+ import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
1315import io .swagger .v3 .oas .annotations .tags .Tag ;
1416import jakarta .validation .Valid ;
1517import jakarta .validation .constraints .Min ;
1618import lombok .AllArgsConstructor ;
1719import lombok .extern .slf4j .Slf4j ;
1820import org .springframework .data .domain .PageRequest ;
21+ import org .springframework .http .MediaType ;
1922import org .springframework .web .bind .annotation .*;
2023
2124import java .util .List ;
3033public class FlowController {
3134
3235 private final FetchTemplates fetchTemplates ;
33-
3436 private final CreateFlow createFlow ;
35-
3637 private final ListFlows listFlows ;
37-
3838 private final FetchFlow fetchFlow ;
39+ private final FetchFlowYamlContent fetchFlowYamlContent ;
40+ private final UpdateFlowYamlContent updateFlowYamlContent ;
3941
4042 @ GetMapping ("/{id}" )
4143 public Flow getFlow (@ PathVariable ("id" ) @ Valid @ ValidId String id ) {
@@ -44,24 +46,19 @@ public Flow getFlow(@PathVariable("id") @Valid @ValidId String id) {
4446
4547 @ GetMapping
4648 public List <Flow > getFlows (@ RequestParam (required = false , name = "parentId" , defaultValue = "10000" )
47- @ Valid
48- @ ValidId String parentId ,
49+ @ Valid @ ValidId
50+ String parentId ,
4951
5052 @ RequestParam (required = false , name = "page" , defaultValue = "0" )
51- @ Valid
52- @ Min ( 0 ) Integer page ,
53+ @ Valid @ Min ( 0 )
54+ Integer page ,
5355
5456 @ RequestParam (required = false , name = "size" , defaultValue = "20" )
55- @ Valid
56- @ Min ( 20 ) Integer size ) {
57+ @ Valid @ Min ( 20 )
58+ Integer size ) {
5759 return listFlows .invoke (parseLong (parentId ), PageRequest .of (page , size ));
5860 }
5961
60- @ GetMapping ("/templates" )
61- public List <YamlTemplate > getTemplates () {
62- return fetchTemplates .invoke ();
63- }
64-
6562 @ PostMapping
6663 public Flow createFlow (@ RequestBody @ Valid CreateFlowParam param ) {
6764 try {
@@ -73,4 +70,45 @@ public Flow createFlow(@RequestBody @Valid CreateFlowParam param) {
7370 );
7471 }
7572 }
73+
74+ @ GetMapping ("/templates" )
75+ public List <YamlTemplate > getTemplates () {
76+ return fetchTemplates .invoke ();
77+ }
78+
79+ @ Operation (
80+ description = "fetch flow yaml return base64 encoded yaml content" ,
81+ parameters = @ Parameter (name = "id" , description = "flow id" ),
82+ responses = @ ApiResponse (
83+ description = "base64 encoded yaml" ,
84+ content = @ Content (
85+ examples = @ ExampleObject (value = "c3RlcHM6CiAgLSBuYW1lOiBzdGVwXzE" +
86+ "KICAgIGNvbW1hbmRzOgogICAgICAtIG5hbWU6IHByaW50CiAgICAgICAgYmFz" +
87+ "aDogfAogICAgICAgICAgZWNobyAic3RlcCAxIG9uIGJhc2gi" )
88+ )
89+ )
90+ )
91+ @ GetMapping (value = "/{id}/yaml" , produces = MediaType .TEXT_PLAIN_VALUE )
92+ public String getYaml (@ PathVariable ("id" ) @ Valid @ ValidId String id ) {
93+ return fetchFlowYamlContent .invoke (parseLong (id ));
94+ }
95+
96+ @ Operation (
97+ description = "update yaml by flow id" ,
98+ parameters = @ Parameter (name = "id" , description = "flow id" ),
99+ requestBody = @ io .swagger .v3 .oas .annotations .parameters .RequestBody (
100+ description = "base64 encoded yaml" ,
101+ required = true ,
102+ content = @ Content (
103+ examples = @ ExampleObject (value = "c3RlcHM6CiAgLSBuYW1lOiBzdGVwXzE" +
104+ "KICAgIGNvbW1hbmRzOgogICAgICAtIG5hbWU6IHByaW50CiAgICAgICAgYmFz" +
105+ "aDogfAogICAgICAgICAgZWNobyAic3RlcCAxIG9uIGJhc2gi" )
106+ )
107+ )
108+ )
109+ @ PostMapping (value = "/{id}/yaml" , consumes = MediaType .TEXT_PLAIN_VALUE )
110+ public void updateYaml (@ PathVariable ("id" ) @ Valid @ ValidId String id ,
111+ @ RequestBody String b64Yaml ) {
112+ updateFlowYamlContent .invoke (parseLong (id ), b64Yaml );
113+ }
76114}
0 commit comments