diff pkg/controllers/importqueue.go @ 1468:5e1218b5a123 bulkreview

proof of concept
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 29 Nov 2018 12:09:01 +0100
parents 0e1d89241cda
children 286a3306f6bf
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go	Thu Nov 29 09:59:10 2018 +0100
+++ b/pkg/controllers/importqueue.go	Thu Nov 29 12:09:01 2018 +0100
@@ -66,6 +66,15 @@
 DELETE FROM waterway.imports WHERE id = $1`
 )
 
+type Review struct {
+	ID    int64  `json:"id"`
+	State string `json:"state"`
+}
+
+func (r Review) String() string {
+	return fmt.Sprintf("%d %s", r.ID, r.State)
+}
+
 func toTextArray(txt string, allowed []string) *pgtype.TextArray {
 	parts := strings.Split(txt, ",")
 	var accepted []string
@@ -334,6 +343,20 @@
 INSERT INTO waterway.import_logs (import_id, msg) VALUES ($1, $2)`
 )
 
+func reviewImports(
+	_ interface{},
+	req *http.Request,
+	conn *sql.Conn,
+) (jr JSONResult, err error) {
+	decoder := json.NewDecoder(req.Body)
+	var reviews []Review
+	decoder.Decode(&reviews)
+	for _, review := range reviews {
+		updateImport(req, conn, review.ID, review.State)
+	}
+	return
+}
+
 func reviewImport(
 	_ interface{},
 	req *http.Request,
@@ -343,7 +366,15 @@
 	vars := mux.Vars(req)
 	id, _ := strconv.ParseInt(vars["id"], 10, 64)
 	state := vars["state"]
+	return updateImport(req, conn, id, state)
+}
 
+func updateImport(
+	req *http.Request,
+	conn *sql.Conn,
+	id int64,
+	state string,
+) (jr JSONResult, err error) {
 	ctx := req.Context()
 	var tx *sql.Tx
 	if tx, err = conn.BeginTx(ctx, nil); err != nil {