Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
1025:a55f20dc8d8d | 1026:3de54d7b7d30 |
---|---|
33 FROM waterway.imports | 33 FROM waterway.imports |
34 ORDER BY id` | 34 ORDER BY id` |
35 | 35 |
36 selectImportPagedSQL = selectImportsUnpagedSQL + ` | 36 selectImportPagedSQL = selectImportsUnpagedSQL + ` |
37 LIMIT $1 OFFSET $2` | 37 LIMIT $1 OFFSET $2` |
38 | |
39 selectImportLogsSQL = ` | |
40 SELECT | |
41 time, | |
42 kind::varchar, | |
43 msg | |
44 FROM waterway.import_logs | |
45 WHERE import_id = $1 | |
46 ORDER BY time` | |
38 ) | 47 ) |
39 | 48 |
40 func listImports( | 49 func listImports( |
41 _ interface{}, | 50 _ interface{}, |
42 req *http.Request, | 51 req *http.Request, |
88 Imports []*models.Import `json:"imports"` | 97 Imports []*models.Import `json:"imports"` |
89 }{ | 98 }{ |
90 Imports: imports, | 99 Imports: imports, |
91 }, | 100 }, |
92 } | 101 } |
93 | |
94 return | 102 return |
95 } | 103 } |
104 | |
105 func importLogs( | |
106 _ interface{}, | |
107 req *http.Request, | |
108 conn *sql.Conn, | |
109 ) (jr JSONResult, err error) { | |
110 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) | |
111 | |
112 var rows *sql.Rows | |
113 | |
114 rows, err = conn.QueryContext(req.Context(), selectImportLogsSQL, id) | |
115 if err != nil { | |
116 return | |
117 } | |
118 defer rows.Close() | |
119 | |
120 entries := make([]*models.ImportLogEntry, 0, 10) | |
121 | |
122 for rows.Next() { | |
123 var entry models.ImportLogEntry | |
124 if err = rows.Scan(&entry.Time, &entry.Kind, &entry.Message); err != nil { | |
125 return | |
126 } | |
127 entries = append(entries, &entry) | |
128 } | |
129 | |
130 if err = rows.Err(); err != nil { | |
131 return | |
132 } | |
133 | |
134 jr = JSONResult{ | |
135 Result: struct { | |
136 Entries []*models.ImportLogEntry `json:"entries"` | |
137 }{ | |
138 Entries: entries, | |
139 }, | |
140 } | |
141 return | |
142 } |