Mercurial > gemma
changeset 2627:3a242e6aa56d
Import log: Add filter for log entries with warnings only: GET /api/imports?warnings=true
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 13 Mar 2019 16:26:51 +0100 |
parents | 9dbaf69c7a66 |
children | 53807c3a2de7 |
files | pkg/controllers/importqueue.go schema/gemma.sql |
diffstat | 2 files changed, 30 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go Wed Mar 13 16:18:39 2019 +0100 +++ b/pkg/controllers/importqueue.go Wed Mar 13 16:26:51 2019 +0100 @@ -31,9 +31,16 @@ ) const ( + warningSQLPrefix = ` +` selectImportsSQL = ` +WITH warned AS ( + SELECT distinct(import_id) AS id + FROM import.import_logs + WHERE kind = 'warn'::log_type +) SELECT - id, + imports.id AS id, state::varchar, enqueued, kind, @@ -41,12 +48,16 @@ signer, summary, EXISTS ( - SELECT true FROM import.import_logs - WHERE kind = 'warn'::log_type AND - import_id = import.imports.id + SELECT true FROM warned + WHERE warned.id = imports.id ) AS has_warnings +` + withoutWarningsSQL = ` FROM import.imports ` + withWarningsSQL = ` +FROM import.imports JOIN warned ON imports.id = warned.id +` selectHasImportSQL = ` SELECT true FROM import.imports WHERE id = $1` @@ -133,6 +144,13 @@ args = append(args, v) } + var warnings bool + + switch warn := strings.ToLower(req.FormValue("warnings")); warn { + case "1", "t", "true": + warnings = true + } + if st := req.FormValue("states"); st != "" { states = toTextArray(st, imports.ImportStateNames) } @@ -146,6 +164,12 @@ } stmt.WriteString(selectImportsSQL) + if warnings { + stmt.WriteString(withWarningsSQL) + } else { + stmt.WriteString(withoutWarningsSQL) + } + if states != nil || kinds != nil || ids != nil { stmt.WriteString(" WHERE ") }