Mercurial > gemma
comparison pkg/controllers/importqueue.go @ 1192:3afa71405b87
Added REST endpoint to accept or decline an import.
Use PUT /api/imports/{id:[0-9]+}/accepted to accept an import.
Use PUT /api/imports/{id:[0-9]+}/declined to decline an import.
TODO: Do some db magic to store the decision.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 16 Nov 2018 17:51:44 +0100 |
parents | 3d50f558870c |
children | 58acc343b1b6 |
comparison
equal
deleted
inserted
replaced
1191:b23622905a3f | 1192:3afa71405b87 |
---|---|
287 | 287 |
288 jr = JSONResult{Code: http.StatusNoContent} | 288 jr = JSONResult{Code: http.StatusNoContent} |
289 | 289 |
290 return | 290 return |
291 } | 291 } |
292 | |
293 const ( | |
294 isPendingSQL = ` | |
295 SELECT state = 'pending'::waterway.import_state WHERE id = $1` | |
296 ) | |
297 | |
298 func reviewImport( | |
299 _ interface{}, | |
300 req *http.Request, | |
301 conn *sql.Conn, | |
302 ) (jr JSONResult, err error) { | |
303 | |
304 vars := mux.Vars(req) | |
305 id, _ := strconv.ParseInt(vars["id"], 10, 64) | |
306 state := vars["state"] | |
307 | |
308 ctx := req.Context() | |
309 var tx *sql.Tx | |
310 if tx, err = conn.BeginTx(ctx, nil); err != nil { | |
311 return | |
312 } | |
313 defer tx.Rollback() | |
314 | |
315 var pending bool | |
316 | |
317 err = tx.QueryRowContext(ctx, isPendingSQL, id).Scan(&pending) | |
318 switch { | |
319 case err == sql.ErrNoRows: | |
320 err = JSONError{ | |
321 Code: http.StatusNotFound, | |
322 Message: fmt.Sprintf("Cannot find import #%d.", id), | |
323 } | |
324 return | |
325 case err != nil: | |
326 return | |
327 case !pending: | |
328 err = JSONError{ | |
329 Code: http.StatusBadRequest, | |
330 Message: fmt.Sprintf("Import %d is not pending.", id), | |
331 } | |
332 return | |
333 } | |
334 | |
335 if state == "accepted" { | |
336 // TODO: Call a stored procedure to do the grunt stuff | |
337 // inside the database. | |
338 } else { | |
339 } | |
340 | |
341 if err = tx.Commit(); err != nil { | |
342 return | |
343 } | |
344 return | |
345 } |