changeset 1534:165f31b71042

Bottleneck import: Added /api/imports/bottleneck POST endpoint.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 07 Dec 2018 14:54:39 +0100
parents 8fc1a2298acb
children b4b3dfd24739
files pkg/controllers/bnimports.go pkg/controllers/routes.go pkg/models/bn.go
diffstat 3 files changed, 90 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/controllers/bnimports.go	Fri Dec 07 14:54:39 2018 +0100
@@ -0,0 +1,66 @@
+// This is Free Software under GNU Affero General Public License v >= 3.0
+// without warranty, see README.md and license for details.
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// License-Filename: LICENSES/AGPL-3.0.txt
+//
+// Copyright (C) 2018 by via donau
+//   – Österreichische Wasserstraßen-Gesellschaft mbH
+// Software engineering by Intevation GmbH
+//
+// Author(s):
+//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+package controllers
+
+import (
+	"database/sql"
+	"log"
+	"net/http"
+
+	"gemma.intevation.de/gemma/pkg/auth"
+	"gemma.intevation.de/gemma/pkg/common"
+	"gemma.intevation.de/gemma/pkg/imports"
+	"gemma.intevation.de/gemma/pkg/models"
+)
+
+func importBottleneck(
+	input interface{},
+	req *http.Request,
+	conn *sql.Conn,
+) (jr JSONResult, err error) {
+
+	bi := input.(*models.BottleneckImport)
+
+	bn := &imports.Bottleneck{
+		URL:      bi.URL,
+		Insecure: bi.Insecure,
+	}
+
+	var serialized string
+	serialized, err = common.ToJSONString(bn)
+	if err != nil {
+		return
+	}
+
+	session, _ := auth.GetSession(req)
+
+	jobID, err := imports.AddJob(imports.BNJobKind, session.User, serialized)
+	if err != nil {
+		return
+	}
+
+	log.Printf("info: added import #%d to queue\n", jobID)
+
+	result := struct {
+		ID int64 `json:"id"`
+	}{
+		ID: jobID,
+	}
+
+	jr = JSONResult{
+		Code:   http.StatusCreated,
+		Result: &result,
+	}
+	return
+}
--- a/pkg/controllers/routes.go	Fri Dec 07 14:36:06 2018 +0100
+++ b/pkg/controllers/routes.go	Fri Dec 07 14:54:39 2018 +0100
@@ -170,6 +170,11 @@
 	api.Handle("/imports/soundingresult", waterwayAdmin(
 		http.HandlerFunc(importSoundingResult))).Methods(http.MethodPost)
 
+	api.Handle("/imports/bottleneck", waterwayAdmin(&JSONHandler{
+		Input:  func() interface{} { return new(models.BottleneckImport) },
+		Handle: importBottleneck,
+	})).Methods(http.MethodPost)
+
 	// Import queue
 	lsImports := waterwayAdmin(&JSONHandler{
 		Handle: listImports,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/models/bn.go	Fri Dec 07 14:54:39 2018 +0100
@@ -0,0 +1,19 @@
+// This is Free Software under GNU Affero General Public License v >= 3.0
+// without warranty, see README.md and license for details.
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// License-Filename: LICENSES/AGPL-3.0.txt
+//
+// Copyright (C) 2018 by via donau
+//   – Österreichische Wasserstraßen-Gesellschaft mbH
+// Software engineering by Intevation GmbH
+//
+// Author(s):
+//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+package models
+
+type BottleneckImport struct {
+	URL      string `json:"url"`
+	Insecure bool   `json:"insecure"`
+}