Mercurial > gemma
diff pkg/controllers/importqueue.go @ 1026:3de54d7b7d30
Added endpoint to show the detail logs of an import.
Path /api/import/[0-9]+
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 24 Oct 2018 13:35:15 +0200 |
parents | 337a7f4c8a16 |
children | c0f5dedf5753 |
line wrap: on
line diff
--- a/pkg/controllers/importqueue.go Wed Oct 24 13:09:54 2018 +0200 +++ b/pkg/controllers/importqueue.go Wed Oct 24 13:35:15 2018 +0200 @@ -35,6 +35,15 @@ selectImportPagedSQL = selectImportsUnpagedSQL + ` LIMIT $1 OFFSET $2` + + selectImportLogsSQL = ` +SELECT + time, + kind::varchar, + msg +FROM waterway.import_logs +WHERE import_id = $1 +ORDER BY time` ) func listImports( @@ -90,6 +99,44 @@ Imports: imports, }, } - return } + +func importLogs( + _ interface{}, + req *http.Request, + conn *sql.Conn, +) (jr JSONResult, err error) { + id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) + + var rows *sql.Rows + + rows, err = conn.QueryContext(req.Context(), selectImportLogsSQL, id) + if err != nil { + return + } + defer rows.Close() + + entries := make([]*models.ImportLogEntry, 0, 10) + + for rows.Next() { + var entry models.ImportLogEntry + if err = rows.Scan(&entry.Time, &entry.Kind, &entry.Message); err != nil { + return + } + entries = append(entries, &entry) + } + + if err = rows.Err(); err != nil { + return + } + + jr = JSONResult{ + Result: struct { + Entries []*models.ImportLogEntry `json:"entries"` + }{ + Entries: entries, + }, + } + return +}