Mercurial > gemma
changeset 1031:c0f5dedf5753
Check first if we have a import before generating log import entries list.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 24 Oct 2018 15:32:38 +0200 |
parents | bf10a7f990cc |
children | 4c0c4dd393de |
files | pkg/controllers/importqueue.go |
diffstat | 1 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go Wed Oct 24 15:09:06 2018 +0200 +++ b/pkg/controllers/importqueue.go Wed Oct 24 15:32:38 2018 +0200 @@ -15,6 +15,7 @@ import ( "database/sql" + "fmt" "net/http" "strconv" @@ -36,6 +37,9 @@ selectImportPagedSQL = selectImportsUnpagedSQL + ` LIMIT $1 OFFSET $2` + selectHasImportSQL = ` +SELECT true FROM Waterway.imports WHERE id = $1` + selectImportLogsSQL = ` SELECT time, @@ -107,11 +111,28 @@ req *http.Request, conn *sql.Conn, ) (jr JSONResult, err error) { + + ctx := req.Context() + id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) - var rows *sql.Rows + // Check if he have such a import job first. + var dummy bool + err = conn.QueryRowContext(ctx, selectHasImportSQL, id).Scan(&dummy) + switch { + case err == sql.ErrNoRows: + err = JSONError{ + Code: http.StatusNotFound, + Message: fmt.Sprintf("Cannot find import #%d.", id), + } + return + case err != nil: + return + } - rows, err = conn.QueryContext(req.Context(), selectImportLogsSQL, id) + // We have it -> generate log entries. + var rows *sql.Rows + rows, err = conn.QueryContext(ctx, selectImportLogsSQL, id) if err != nil { return }