@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/pkg/errors"
16
16
17
+ "gitlab.com/postgres-ai/database-lab/pkg/client/dblabapi/types"
17
18
"gitlab.com/postgres-ai/database-lab/pkg/models"
18
19
)
19
20
@@ -67,27 +68,13 @@ func (c *Client) GetClone(ctx context.Context, cloneID string) (*models.Clone, e
67
68
return & clone , nil
68
69
}
69
70
70
- // CreateRequest represents clone params of a create request.
71
- type CreateRequest struct {
72
- ID string `json:"id"`
73
- Project string `json:"project"`
74
- Protected bool `json:"protected"`
75
- DB * DatabaseRequest `json:"db"`
76
- }
77
-
78
- // DatabaseRequest represents database params of a clone request.
79
- type DatabaseRequest struct {
80
- Username string `json:"username"`
81
- Password string `json:"password"`
82
- }
83
-
84
71
// CreateClone creates a new Database Lab clone.
85
- func (c * Client ) CreateClone (ctx context.Context , cloneRequest CreateRequest ) (* models.Clone , error ) {
72
+ func (c * Client ) CreateClone (ctx context.Context , cloneRequest types. CloneCreateRequest ) (* models.Clone , error ) {
86
73
u := c .URL ("/clone" )
87
74
88
75
body := bytes .NewBuffer (nil )
89
76
if err := json .NewEncoder (body ).Encode (cloneRequest ); err != nil {
90
- return nil , errors .Wrap (err , "failed to encode CreateRequest " )
77
+ return nil , errors .Wrap (err , "failed to encode CloneCreateRequest " )
91
78
}
92
79
93
80
request , err := http .NewRequest (http .MethodPost , u .String (), body )
@@ -161,12 +148,12 @@ func (c *Client) watchCloneStatus(ctx context.Context, cloneID string, initialSt
161
148
}
162
149
163
150
// CreateCloneAsync asynchronously creates a new Database Lab clone.
164
- func (c * Client ) CreateCloneAsync (ctx context.Context , cloneRequest CreateRequest ) (* models.Clone , error ) {
151
+ func (c * Client ) CreateCloneAsync (ctx context.Context , cloneRequest types. CloneCreateRequest ) (* models.Clone , error ) {
165
152
u := c .URL ("/clone" )
166
153
167
154
body := bytes .NewBuffer (nil )
168
155
if err := json .NewEncoder (body ).Encode (cloneRequest ); err != nil {
169
- return nil , errors .Wrap (err , "failed to encode CreateRequest " )
156
+ return nil , errors .Wrap (err , "failed to encode CloneCreateRequest " )
170
157
}
171
158
172
159
request , err := http .NewRequest (http .MethodPost , u .String (), body )
@@ -190,18 +177,13 @@ func (c *Client) CreateCloneAsync(ctx context.Context, cloneRequest CreateReques
190
177
return & clone , nil
191
178
}
192
179
193
- // UpdateRequest represents params of an update request.
194
- type UpdateRequest struct {
195
- Protected bool `json:"protected"`
196
- }
197
-
198
180
// UpdateClone updates an existing Database Lab clone.
199
- func (c * Client ) UpdateClone (ctx context.Context , cloneID string , updateRequest UpdateRequest ) (* models.Clone , error ) {
181
+ func (c * Client ) UpdateClone (ctx context.Context , cloneID string , updateRequest types. CloneUpdateRequest ) (* models.Clone , error ) {
200
182
u := c .URL (fmt .Sprintf ("/clone/%s" , cloneID ))
201
183
202
184
body := bytes .NewBuffer (nil )
203
185
if err := json .NewEncoder (body ).Encode (updateRequest ); err != nil {
204
- return nil , errors .Wrap (err , "failed to encode UpdateRequest " )
186
+ return nil , errors .Wrap (err , "failed to encode CloneUpdateRequest " )
205
187
}
206
188
207
189
request , err := http .NewRequest (http .MethodPatch , u .String (), body )
0 commit comments