changeset 1582:dc727824183a

Started with REST API for scheduler.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 13 Dec 2018 18:08:17 +0100
parents 8e8523282853
children caedd9b176f2
files pkg/controllers/routes.go pkg/controllers/scheduler.go pkg/models/importconfig.go pkg/models/scheduler.go
diffstat 4 files changed, 97 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/routes.go	Thu Dec 13 17:34:12 2018 +0100
+++ b/pkg/controllers/routes.go	Thu Dec 13 18:08:17 2018 +0100
@@ -202,6 +202,12 @@
 			Handle: reviewImport,
 		})).Methods(http.MethodPut)
 
+	// Import scheduler configuration
+	api.Handle("/imports/scheduler}",
+		waterwayAdmin(&JSONHandler{
+			Handle: listScheduler,
+		})).Methods(http.MethodGet)
+
 	// Token handling: Login/Logout.
 	api.HandleFunc("/login", login).
 		Methods(http.MethodPost)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/controllers/scheduler.go	Thu Dec 13 18:08:17 2018 +0100
@@ -0,0 +1,28 @@
+// 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"
+	"net/http"
+)
+
+func listScheduler(
+	_ interface{},
+	req *http.Request,
+	conn *sql.Conn,
+) (jr JSONResult, err error) {
+	// TODO: Implement me!
+	return
+}
--- a/pkg/models/importconfig.go	Thu Dec 13 17:34:12 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-package models
-
-import (
-	"encoding/json"
-	"fmt"
-
-	"github.com/robfig/cron"
-
-	"gemma.intevation.de/gemma/pkg/scheduler"
-)
-
-// 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>
-
-type (
-	CronSpec   string
-	ImportKind string
-
-	ImportConfig struct {
-		Kind ImportKind `json:"kind"`
-		Cron CronSpec   `json:"cron"`
-		URL  *string    `json:"url"`
-	}
-)
-
-func (ik *ImportKind) UnmarshalJSON(data []byte) error {
-	var s string
-	if err := json.Unmarshal(data, &s); err != nil {
-		return err
-	}
-
-	if !scheduler.HasAction(s) {
-		return fmt.Errorf("Unknown kind '%s'", s)
-	}
-
-	*ik = ImportKind(s)
-
-	return nil
-}
-
-func (cs *CronSpec) UnmarshalJSON(data []byte) error {
-	var spec string
-	if err := json.Unmarshal(data, &spec); err != nil {
-		return err
-	}
-	if _, err := cron.Parse(spec); err != nil {
-		return err
-	}
-	*cs = CronSpec(spec)
-	return nil
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/models/scheduler.go	Thu Dec 13 18:08:17 2018 +0100
@@ -0,0 +1,63 @@
+// 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
+
+import (
+	"encoding/json"
+	"fmt"
+
+	"github.com/robfig/cron"
+
+	"gemma.intevation.de/gemma/pkg/scheduler"
+)
+
+type (
+	CronSpec   string
+	ImportKind string
+
+	ImportConfig struct {
+		Kind       ImportKind `json:"kind"`
+		Cron       CronSpec   `json:"cron"`
+		SendEMail  bool       `json:"send-email"`
+		AutoAccept bool       `json:"auto-accept"`
+		URL        *string    `json:"url"`
+	}
+)
+
+func (ik *ImportKind) UnmarshalJSON(data []byte) error {
+	var s string
+	if err := json.Unmarshal(data, &s); err != nil {
+		return err
+	}
+
+	if !scheduler.HasAction(s) {
+		return fmt.Errorf("Unknown kind '%s'", s)
+	}
+
+	*ik = ImportKind(s)
+
+	return nil
+}
+
+func (cs *CronSpec) UnmarshalJSON(data []byte) error {
+	var spec string
+	if err := json.Unmarshal(data, &spec); err != nil {
+		return err
+	}
+	if _, err := cron.Parse(spec); err != nil {
+		return err
+	}
+	*cs = CronSpec(spec)
+	return nil
+}