diff pkg/controllers/importqueue.go @ 1392:0e1d89241cda

Imports: An Import (e.g. a sounding result import) can now write a 'summary' of a successful import. This is done if the import switches to to state 'pending'.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 28 Nov 2018 09:52:34 +0100
parents 3ff916e853d4
children 5e1218b5a123
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go	Wed Nov 28 08:11:23 2018 +0100
+++ b/pkg/controllers/importqueue.go	Wed Nov 28 09:52:34 2018 +0100
@@ -15,17 +15,19 @@
 
 import (
 	"database/sql"
+	"encoding/json"
 	"fmt"
 	"log"
 	"net/http"
 	"strconv"
 	"strings"
 
+	"github.com/gorilla/mux"
+	"github.com/jackc/pgx/pgtype"
+
 	"gemma.intevation.de/gemma/pkg/auth"
 	"gemma.intevation.de/gemma/pkg/imports"
 	"gemma.intevation.de/gemma/pkg/models"
-	"github.com/gorilla/mux"
-	"github.com/jackc/pgx/pgtype"
 )
 
 const (
@@ -36,7 +38,8 @@
   enqueued,
   kind,
   username,
-  signer
+  signer,
+  summary
 FROM waterway.imports
 `
 
@@ -166,7 +169,7 @@
 
 	imports := make([]*models.Import, 0, 20)
 
-	var signer sql.NullString
+	var signer, summary sql.NullString
 
 	for rows.Next() {
 		var it models.Import
@@ -177,12 +180,19 @@
 			&it.Kind,
 			&it.User,
 			&signer,
+			&summary,
 		); err != nil {
 			return
 		}
 		if signer.Valid {
 			it.Signer = signer.String
 		}
+		if summary.Valid {
+			if err = json.NewDecoder(
+				strings.NewReader(summary.String)).Decode(&it.Summary); err != nil {
+				return
+			}
+		}
 		imports = append(imports, &it)
 	}