@@ -19,11 +19,15 @@ package openapi
19
19
20
20
import (
21
21
"fmt"
22
+ "net/http"
22
23
23
24
"github.com/acmestack/envcd/internal/core/plugin"
25
+ "github.com/acmestack/envcd/internal/core/storage/dao"
24
26
"github.com/acmestack/envcd/internal/pkg/context"
27
+ "github.com/acmestack/envcd/internal/pkg/entity"
25
28
"github.com/acmestack/envcd/pkg/entity/data"
26
29
"github.com/acmestack/godkits/gox/errorsx"
30
+ "github.com/acmestack/godkits/gox/stringsx"
27
31
"github.com/gin-gonic/gin"
28
32
)
29
33
@@ -37,7 +41,7 @@ func (openapi *Openapi) getApp(ctx *gin.Context) {
37
41
}
38
42
}
39
43
40
- func (openapi * Openapi ) createApp (ctx * gin.Context ) {
44
+ func (openapi * Openapi ) putApp (ctx * gin.Context ) {
41
45
c := & context.Context {Action : func () (* data.EnvcdResult , error ) {
42
46
fmt .Println ("hello world" )
43
47
// create App
@@ -63,18 +67,30 @@ func (openapi *Openapi) DeleteApp(ctx *gin.Context) {
63
67
}
64
68
}
65
69
66
- func (openapi * Openapi ) getConfig (ctx * gin.Context ) {
67
- c := & context.Context {Action : func () (* data.EnvcdResult , error ) {
68
- fmt .Println ("hello world" )
69
- openapi .exchange .Put ("key" , "value" )
70
- return nil , errorsx .Err ("test error" )
71
- }}
72
- if ret , err := plugin .NewChain (openapi .executors ).Execute (c ); err != nil {
70
+ func (openapi * Openapi ) getDict (ctx * gin.Context ) {
71
+ c , _ := buildContext (ctx )
72
+ c .Action = func () (* data.EnvcdResult , error ) {
73
+ // get user id from gin context
74
+ userId := stringsx .ToInt (ctx .Param ("userId" ))
75
+ appId := stringsx .ToInt (ctx .Param ("appId" ))
76
+ configId := stringsx .ToInt (ctx .Param ("configId" ))
77
+ dict := entity.Dictionary {Id : configId , UserId : userId , ApplicationId : appId }
78
+ dictionary , err := dao .New (openapi .storage ).SelectDictionary (dict )
79
+ if err != nil {
80
+ return data .Failure (err .Error ()), err
81
+ }
82
+ return data .Success (dictionary ), nil
83
+ }
84
+ ret , err := plugin .NewChain (openapi .executors ).Execute (c )
85
+ if err != nil {
86
+ // FIXME log.error("ret = %v, error = %v", ret, err)
73
87
fmt .Printf ("ret = %v, error = %v" , ret , err )
88
+ ctx .JSON (http .StatusBadRequest , ret .Data )
74
89
}
90
+ ctx .JSON (http .StatusOK , ret .Data )
75
91
}
76
92
77
- func (openapi * Openapi ) createConfig (ctx * gin.Context ) {
93
+ func (openapi * Openapi ) putDict (ctx * gin.Context ) {
78
94
c := & context.Context {Action : func () (* data.EnvcdResult , error ) {
79
95
fmt .Println ("hello world" )
80
96
// create config
@@ -88,7 +104,7 @@ func (openapi *Openapi) createConfig(ctx *gin.Context) {
88
104
}
89
105
}
90
106
91
- func (openapi * Openapi ) deleteConfig (ctx * gin.Context ) {
107
+ func (openapi * Openapi ) deleteDict (ctx * gin.Context ) {
92
108
c := & context.Context {Action : func () (* data.EnvcdResult , error ) {
93
109
fmt .Println ("hello world" )
94
110
// delete config
0 commit comments