Mercurial > gemma
comparison pkg/controllers/importconfig.go @ 4242:1458c9b0fdaa json-handler-middleware
Made the sql.Conn in function accessible via the context of the request.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 22 Aug 2019 10:18:13 +0200 |
parents | 8af156928a2d |
children | d776110b4db0 |
comparison
equal
deleted
inserted
replaced
4240:a4f76e170290 | 4242:1458c9b0fdaa |
---|---|
29 ) | 29 ) |
30 | 30 |
31 func runImportConfig( | 31 func runImportConfig( |
32 _ interface{}, | 32 _ interface{}, |
33 req *http.Request, | 33 req *http.Request, |
34 conn *sql.Conn, | |
35 ) (jr JSONResult, err error) { | 34 ) (jr JSONResult, err error) { |
36 | 35 |
37 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) | 36 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
38 | 37 |
39 ctx := req.Context() | 38 ctx := req.Context() |
40 | 39 |
41 var jobID int64 | 40 var jobID int64 |
42 if jobID, err = imports.RunConfiguredImportContext(ctx, conn, id); err != nil { | 41 if jobID, err = imports.RunConfiguredImportContext(ctx, JSONConn(req), id); err != nil { |
43 return | 42 return |
44 } | 43 } |
45 | 44 |
46 var result = struct { | 45 var result = struct { |
47 ID int64 `json:"id"` | 46 ID int64 `json:"id"` |
57 } | 56 } |
58 | 57 |
59 func modifyImportConfig( | 58 func modifyImportConfig( |
60 input interface{}, | 59 input interface{}, |
61 req *http.Request, | 60 req *http.Request, |
62 conn *sql.Conn, | |
63 ) (jr JSONResult, err error) { | 61 ) (jr JSONResult, err error) { |
64 | 62 |
65 ctx := req.Context() | 63 ctx := req.Context() |
66 | 64 |
67 raw := input.(*json.RawMessage) | 65 raw := input.(*json.RawMessage) |
68 | 66 |
69 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) | 67 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
68 | |
69 conn := JSONConn(req) | |
70 | 70 |
71 var pc *imports.PersistentConfig | 71 var pc *imports.PersistentConfig |
72 pc, err = imports.LoadPersistentConfigContext(ctx, conn, id) | 72 pc, err = imports.LoadPersistentConfigContext(ctx, conn, id) |
73 switch { | 73 switch { |
74 case err == sql.ErrNoRows: | 74 case err == sql.ErrNoRows: |
150 } | 150 } |
151 | 151 |
152 func infoImportConfig( | 152 func infoImportConfig( |
153 _ interface{}, | 153 _ interface{}, |
154 req *http.Request, | 154 req *http.Request, |
155 conn *sql.Conn, | |
156 ) (jr JSONResult, err error) { | 155 ) (jr JSONResult, err error) { |
157 | 156 |
158 ctx := req.Context() | 157 ctx := req.Context() |
159 | 158 |
160 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) | 159 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
161 | 160 |
162 var cfg *imports.PersistentConfig | 161 var cfg *imports.PersistentConfig |
163 | 162 |
164 cfg, err = imports.LoadPersistentConfigContext(ctx, conn, id) | 163 cfg, err = imports.LoadPersistentConfigContext(ctx, JSONConn(req), id) |
165 switch { | 164 switch { |
166 case err != nil: | 165 case err != nil: |
167 return | 166 return |
168 case cfg == nil: | 167 case cfg == nil: |
169 err = JSONError{ | 168 err = JSONError{ |
209 } | 208 } |
210 | 209 |
211 func deleteImportConfig( | 210 func deleteImportConfig( |
212 _ interface{}, | 211 _ interface{}, |
213 req *http.Request, | 212 req *http.Request, |
214 conn *sql.Conn, | |
215 ) (jr JSONResult, err error) { | 213 ) (jr JSONResult, err error) { |
216 | 214 |
217 ctx := req.Context() | 215 ctx := req.Context() |
218 | 216 |
219 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) | 217 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
220 | 218 |
221 var tx *sql.Tx | 219 var tx *sql.Tx |
222 if tx, err = conn.BeginTx(ctx, nil); err != nil { | 220 if tx, err = JSONConn(req).BeginTx(ctx, nil); err != nil { |
223 return | 221 return |
224 } | 222 } |
225 defer tx.Rollback() | 223 defer tx.Rollback() |
226 | 224 |
227 err = imports.DeletePersistentConfigurationContext( | 225 err = imports.DeletePersistentConfigurationContext( |
260 } | 258 } |
261 | 259 |
262 func addImportConfig( | 260 func addImportConfig( |
263 input interface{}, | 261 input interface{}, |
264 req *http.Request, | 262 req *http.Request, |
265 conn *sql.Conn, | |
266 ) (jr JSONResult, err error) { | 263 ) (jr JSONResult, err error) { |
267 | 264 |
268 cfg := input.(*imports.ImportConfigIn) | 265 cfg := input.(*imports.ImportConfigIn) |
269 | 266 |
270 kind := imports.JobKind(cfg.Kind) | 267 kind := imports.JobKind(cfg.Kind) |
292 pc.Attributes.Marshal(config) | 289 pc.Attributes.Marshal(config) |
293 | 290 |
294 ctx := req.Context() | 291 ctx := req.Context() |
295 | 292 |
296 var tx *sql.Tx | 293 var tx *sql.Tx |
297 if tx, err = conn.BeginTx(ctx, nil); err != nil { | 294 if tx, err = JSONConn(req).BeginTx(ctx, nil); err != nil { |
298 return | 295 return |
299 } | 296 } |
300 defer tx.Rollback() | 297 defer tx.Rollback() |
301 | 298 |
302 var id int64 | 299 var id int64 |
330 } | 327 } |
331 | 328 |
332 func listImportConfigs( | 329 func listImportConfigs( |
333 _ interface{}, | 330 _ interface{}, |
334 req *http.Request, | 331 req *http.Request, |
335 conn *sql.Conn, | |
336 ) (jr JSONResult, err error) { | 332 ) (jr JSONResult, err error) { |
337 | 333 |
338 ctx := req.Context() | 334 ctx := req.Context() |
339 configs := []*imports.ImportConfigOut{} | 335 configs := []*imports.ImportConfigOut{} |
340 | 336 |
341 if err = imports.ListAllPersistentConfigurationsContext( | 337 if err = imports.ListAllPersistentConfigurationsContext( |
342 ctx, conn, | 338 ctx, JSONConn(req), |
343 func(config *imports.ImportConfigOut) error { | 339 func(config *imports.ImportConfigOut) error { |
344 configs = append(configs, config) | 340 configs = append(configs, config) |
345 return nil | 341 return nil |
346 }, | 342 }, |
347 ); err != nil { | 343 ); err != nil { |