Mercurial > gemma
comparison pkg/controllers/routes.go @ 2058:09f9ae3d0526 unify_imports
Imports: Handle manual imports with a single route using the shortnames of the imports to distiquish between them.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 28 Jan 2019 20:35:14 +0100 |
parents | d29ac997eb34 |
children | e6dccc7a3ea1 |
comparison
equal
deleted
inserted
replaced
2057:84d88fbd6007 | 2058:09f9ae3d0526 |
---|---|
16 | 16 |
17 import ( | 17 import ( |
18 "encoding/json" | 18 "encoding/json" |
19 "net/http" | 19 "net/http" |
20 "net/http/httputil" | 20 "net/http/httputil" |
21 "strings" | |
21 | 22 |
22 "github.com/gorilla/mux" | 23 "github.com/gorilla/mux" |
23 | 24 |
24 "gemma.intevation.de/gemma/pkg/auth" | 25 "gemma.intevation.de/gemma/pkg/auth" |
25 "gemma.intevation.de/gemma/pkg/imports" | 26 "gemma.intevation.de/gemma/pkg/imports" |
42 api.Handle("/users", any(&JSONHandler{ | 43 api.Handle("/users", any(&JSONHandler{ |
43 Handle: listUsers, | 44 Handle: listUsers, |
44 })).Methods(http.MethodGet) | 45 })).Methods(http.MethodGet) |
45 | 46 |
46 api.Handle("/users", sysAdmin(&JSONHandler{ | 47 api.Handle("/users", sysAdmin(&JSONHandler{ |
47 Input: func() interface{} { return new(models.User) }, | 48 Input: func(*http.Request) interface{} { return new(models.User) }, |
48 Handle: createUser, | 49 Handle: createUser, |
49 })).Methods(http.MethodPost) | 50 })).Methods(http.MethodPost) |
50 | 51 |
51 api.Handle("/users/{user}", any(&JSONHandler{ | 52 api.Handle("/users/{user}", any(&JSONHandler{ |
52 Handle: listUser, | 53 Handle: listUser, |
53 })).Methods(http.MethodGet) | 54 })).Methods(http.MethodGet) |
54 | 55 |
55 api.Handle("/users/{user}", any(&JSONHandler{ | 56 api.Handle("/users/{user}", any(&JSONHandler{ |
56 Input: func() interface{} { return new(models.User) }, | 57 Input: func(*http.Request) interface{} { return new(models.User) }, |
57 Handle: updateUser, | 58 Handle: updateUser, |
58 })).Methods(http.MethodPut) | 59 })).Methods(http.MethodPut) |
59 | 60 |
60 api.Handle("/users/{user}", sysAdmin(&JSONHandler{ | 61 api.Handle("/users/{user}", sysAdmin(&JSONHandler{ |
61 Handle: deleteUser, | 62 Handle: deleteUser, |
76 api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{ | 77 api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{ |
77 Handle: getFeatureStyle, | 78 Handle: getFeatureStyle, |
78 })).Methods(http.MethodGet) | 79 })).Methods(http.MethodGet) |
79 | 80 |
80 api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{ | 81 api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{ |
81 Input: func() interface{} { return new(models.Colour) }, | 82 Input: func(*http.Request) interface{} { return new(models.Colour) }, |
82 Handle: setFeatureStyle, | 83 Handle: setFeatureStyle, |
83 })).Methods(http.MethodPut) | 84 })).Methods(http.MethodPut) |
84 | 85 |
85 // Password resets. | 86 // Password resets. |
86 api.Handle("/users/passwordreset", &JSONHandler{ | 87 api.Handle("/users/passwordreset", &JSONHandler{ |
87 Input: func() interface{} { return new(models.PWResetUser) }, | 88 Input: func(*http.Request) interface{} { return new(models.PWResetUser) }, |
88 Handle: passwordResetRequest, | 89 Handle: passwordResetRequest, |
89 NoConn: true, | 90 NoConn: true, |
90 }).Methods(http.MethodPost) | 91 }).Methods(http.MethodPost) |
91 | 92 |
92 api.Handle("/users/passwordreset/{hash}", &JSONHandler{ | 93 api.Handle("/users/passwordreset/{hash}", &JSONHandler{ |
146 Handle: listBottlenecks, | 147 Handle: listBottlenecks, |
147 })).Methods(http.MethodGet) | 148 })).Methods(http.MethodGet) |
148 | 149 |
149 // Cross sections | 150 // Cross sections |
150 api.Handle("/cross", any(&JSONHandler{ | 151 api.Handle("/cross", any(&JSONHandler{ |
151 Input: func() interface{} { return new(models.CrossSectionInput) }, | 152 Input: func(*http.Request) interface{} { return new(models.CrossSectionInput) }, |
152 Handle: crossSection, | 153 Handle: crossSection, |
153 })).Methods(http.MethodPost) | 154 })).Methods(http.MethodPost) |
154 | 155 |
155 // Feature search | 156 // Feature search |
156 api.Handle("/search", any(&JSONHandler{ | 157 api.Handle("/search", any(&JSONHandler{ |
157 Input: func() interface{} { return new(models.SearchRequest) }, | 158 Input: func(*http.Request) interface{} { return new(models.SearchRequest) }, |
158 Handle: searchFeature, | 159 Handle: searchFeature, |
159 })).Methods(http.MethodPost) | 160 })).Methods(http.MethodPost) |
160 | 161 |
161 // Geo styling | 162 // Geo styling |
162 api.Handle("/geo/style/{feature}", | 163 api.Handle("/geo/style/{feature}", |
163 sysAdmin(http.HandlerFunc(uploadStyle))).Methods(http.MethodPost) | 164 sysAdmin(http.HandlerFunc(uploadStyle))).Methods(http.MethodPost) |
164 | 165 |
165 // Imports | 166 // Imports |
166 api.Handle("/imports/soundingresult-upload/{token}", | 167 api.Handle("/imports/sr-upload/{token}", |
167 waterwayAdmin(http.HandlerFunc(deleteSoundingUpload))).Methods(http.MethodDelete) | 168 waterwayAdmin(http.HandlerFunc(deleteSoundingUpload))).Methods(http.MethodDelete) |
168 | 169 |
169 api.Handle("/imports/soundingresult-upload", waterwayAdmin(&JSONHandler{ | 170 api.Handle("/imports/sr-upload", waterwayAdmin(&JSONHandler{ |
170 Handle: uploadSoundingResult, | 171 Handle: uploadSoundingResult, |
171 })).Methods(http.MethodPost) | 172 })).Methods(http.MethodPost) |
172 | 173 |
173 api.Handle("/imports/soundingresult", waterwayAdmin( | 174 api.Handle("/imports/sr", waterwayAdmin( |
174 http.HandlerFunc(importSoundingResult))).Methods(http.MethodPost) | 175 http.HandlerFunc(importSoundingResult))).Methods(http.MethodPost) |
175 | 176 |
176 api.Handle("/imports/approvedgm", waterwayAdmin( | 177 api.Handle("/imports/agm", waterwayAdmin( |
177 http.HandlerFunc(importApprovedGaugeMeasurements))).Methods(http.MethodPost) | 178 http.HandlerFunc(importApprovedGaugeMeasurements))).Methods(http.MethodPost) |
178 | 179 |
179 api.Handle("/imports/bottleneck", waterwayAdmin(&JSONHandler{ | 180 api.Handle("/imports/{kind:st}", sysAdmin(&JSONHandler{ |
180 Input: imports.MustImportModel(imports.BNJobKind), | 181 Input: importModel, |
181 Handle: manualImport(imports.BNJobKind), | 182 Handle: manualImport, |
182 NoConn: true, | 183 NoConn: true, |
183 })).Methods(http.MethodPost) | 184 })).Methods(http.MethodPost) |
184 | 185 |
185 api.Handle("/imports/gaugemeasurement", waterwayAdmin(&JSONHandler{ | 186 kinds := strings.Join([]string{ |
186 Input: imports.MustImportModel(imports.GMJobKind), | 187 "bn", "gm", "fa", "wx", "wa", |
187 Handle: manualImport(imports.GMJobKind), | 188 "wg", "dmv", "fd", "dm", |
188 NoConn: true, | 189 }, "|") |
189 })).Methods(http.MethodPost) | 190 |
190 | 191 api.Handle("/imports/{kind:"+kinds+"}", waterwayAdmin(&JSONHandler{ |
191 api.Handle("/imports/fairwayavailability", waterwayAdmin(&JSONHandler{ | 192 Input: importModel, |
192 Input: imports.MustImportModel(imports.FAJobKind), | 193 Handle: manualImport, |
193 Handle: manualImport(imports.FAJobKind), | |
194 NoConn: true, | |
195 })).Methods(http.MethodPost) | |
196 | |
197 api.Handle("/imports/waterwayaxis", waterwayAdmin(&JSONHandler{ | |
198 Input: imports.MustImportModel(imports.WXJobKind), | |
199 Handle: manualImport(imports.WXJobKind), | |
200 NoConn: true, | |
201 })).Methods(http.MethodPost) | |
202 | |
203 api.Handle("/imports/waterwayarea", waterwayAdmin(&JSONHandler{ | |
204 Input: imports.MustImportModel(imports.WAJobKind), | |
205 Handle: manualImport(imports.WAJobKind), | |
206 NoConn: true, | |
207 })).Methods(http.MethodPost) | |
208 | |
209 api.Handle("/imports/waterwaygauge", waterwayAdmin(&JSONHandler{ | |
210 Input: imports.MustImportModel(imports.WGJobKind), | |
211 Handle: manualImport(imports.WGJobKind), | |
212 NoConn: true, | |
213 })).Methods(http.MethodPost) | |
214 | |
215 api.Handle("/imports/distancemarksvirtual", waterwayAdmin(&JSONHandler{ | |
216 Input: imports.MustImportModel(imports.DMVJobKind), | |
217 Handle: manualImport(imports.DMVJobKind), | |
218 NoConn: true, | |
219 })).Methods(http.MethodPost) | |
220 | |
221 api.Handle("/imports/fairwaydimension", waterwayAdmin(&JSONHandler{ | |
222 Input: imports.MustImportModel(imports.FDJobKind), | |
223 Handle: manualImport(imports.FDJobKind), | |
224 NoConn: true, | |
225 })).Methods(http.MethodPost) | |
226 | |
227 api.Handle("/imports/distancemarks", waterwayAdmin(&JSONHandler{ | |
228 Input: imports.MustImportModel(imports.DMAJobKind), | |
229 Handle: manualImport(imports.DMAJobKind), | |
230 NoConn: true, | |
231 })).Methods(http.MethodPost) | |
232 | |
233 api.Handle("/imports/stretch", sysAdmin(&JSONHandler{ | |
234 Input: imports.MustImportModel(imports.STJobKind), | |
235 Handle: manualImport(imports.STJobKind), | |
236 NoConn: true, | 194 NoConn: true, |
237 })).Methods(http.MethodPost) | 195 })).Methods(http.MethodPost) |
238 | 196 |
239 // Import scheduler configuration | 197 // Import scheduler configuration |
240 api.Handle("/imports/config/{id:[0-9]+}/run", | 198 api.Handle("/imports/config/{id:[0-9]+}/run", |
242 Handle: runImportConfig, | 200 Handle: runImportConfig, |
243 })).Methods(http.MethodGet) | 201 })).Methods(http.MethodGet) |
244 | 202 |
245 api.Handle("/imports/config/{id:[0-9]+}", | 203 api.Handle("/imports/config/{id:[0-9]+}", |
246 waterwayAdmin(&JSONHandler{ | 204 waterwayAdmin(&JSONHandler{ |
247 Input: func() interface{} { return &json.RawMessage{} }, | 205 Input: func(*http.Request) interface{} { return &json.RawMessage{} }, |
248 Handle: modifyImportConfig, | 206 Handle: modifyImportConfig, |
249 })).Methods(http.MethodPatch) | 207 })).Methods(http.MethodPatch) |
250 | 208 |
251 api.Handle("/imports/config/{id:[0-9]+}", | 209 api.Handle("/imports/config/{id:[0-9]+}", |
252 waterwayAdmin(&JSONHandler{ | 210 waterwayAdmin(&JSONHandler{ |
258 Handle: infoImportConfig, | 216 Handle: infoImportConfig, |
259 })).Methods(http.MethodGet) | 217 })).Methods(http.MethodGet) |
260 | 218 |
261 api.Handle("/imports/config", | 219 api.Handle("/imports/config", |
262 waterwayAdmin(&JSONHandler{ | 220 waterwayAdmin(&JSONHandler{ |
263 Input: func() interface{} { return new(imports.ImportConfigIn) }, | 221 Input: func(*http.Request) interface{} { return new(imports.ImportConfigIn) }, |
264 Handle: addImportConfig, | 222 Handle: addImportConfig, |
265 })).Methods(http.MethodPost) | 223 })).Methods(http.MethodPost) |
266 | 224 |
267 api.Handle("/imports/config", | 225 api.Handle("/imports/config", |
268 waterwayAdmin(&JSONHandler{ | 226 waterwayAdmin(&JSONHandler{ |
280 api.Handle("/imports/{id:[0-9]+}", waterwayAdmin(&JSONHandler{ | 238 api.Handle("/imports/{id:[0-9]+}", waterwayAdmin(&JSONHandler{ |
281 Handle: importLogs, | 239 Handle: importLogs, |
282 })).Methods(http.MethodGet) | 240 })).Methods(http.MethodGet) |
283 | 241 |
284 api.Handle("/imports", waterwayAdmin(&JSONHandler{ | 242 api.Handle("/imports", waterwayAdmin(&JSONHandler{ |
285 Input: func() interface{} { return &[]models.Review{} }, | 243 Input: func(*http.Request) interface{} { return &[]models.Review{} }, |
286 Handle: reviewImports, | 244 Handle: reviewImports, |
287 })).Methods(http.MethodPatch) | 245 })).Methods(http.MethodPatch) |
288 | 246 |
289 api.Handle("/imports/{id:[0-9]+}", waterwayAdmin(&JSONHandler{ | 247 api.Handle("/imports/{id:[0-9]+}", waterwayAdmin(&JSONHandler{ |
290 Handle: deleteImport, | 248 Handle: deleteImport, |