Mercurial > gemma
annotate controllers/user.go @ 311:74559e12a59f
sql.Result.RowsAffected is a driver specific feature. Check
for it after handling errors.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 01 Aug 2018 17:29:52 +0200 |
parents | 750a9c9cd965 |
children | adceb47920fb |
rev | line source |
---|---|
226
63dd5216eee4
Refactored gemma server to be more REST-like.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
218
diff
changeset
|
1 package controllers |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 "database/sql" |
254
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
5 "fmt" |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 "net/http" |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
241
3b688fe04c39
No omitempty if JSON serialising PostgreSQL errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
240
diff
changeset
|
8 "github.com/gorilla/mux" |
3b688fe04c39
No omitempty if JSON serialising PostgreSQL errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
240
diff
changeset
|
9 |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
10 "gemma.intevation.de/gemma/auth" |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 ) |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 const ( |
216
494a257e7715
Called schema prefixed sys_admin.create_user instead of create_user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
206
diff
changeset
|
14 createUserSQL = `SELECT sys_admin.create_user($1, $2, $3, $4, NULL, $5)` |
494a257e7715
Called schema prefixed sys_admin.create_user instead of create_user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
206
diff
changeset
|
15 createUserExtentSQL = `SELECT sys_admin.create_user($1, $2, $3, $4, |
188
ee3093966a6d
ST_SetSRID should be not need as the map extent column does not have any SRID code.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
187
diff
changeset
|
16 ST_MakeBox2D(ST_Point($5, $6), ST_Point($7, $8)), $9)` |
235
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
17 |
307
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
18 updateUserSQL = `UPDATE users.list_users |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
19 SET (rolname, username, pw, country, map_extent, email_address) |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
20 = ($2, $3, $4, $5, NULL, $6) |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
21 WHERE username = $1` |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
22 updateUserExtentSQL = `UPDATE users.list_users |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
23 SET (rolname, username, pw, country, map_extent, email_address) |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
24 = ($2, $3, $4, $5, ST_MakeBox2D(ST_Point($6, $7), ST_Point($8, $9)), $10) |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
25 WHERE username = $1` |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
26 |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
27 deleteUserSQL = `SELECT sys_admin.delete_user($1)` |
250
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
28 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
29 listUsersSQL = `SELECT |
253
322c3d0e05ef
The column in sys_admin.list_users is called rolname not rolename.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
250
diff
changeset
|
30 rolname, |
250
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
31 username, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
32 country, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
33 email_address, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
34 ST_XMin(map_extent), ST_YMin(map_extent), |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
35 ST_XMax(map_extent), ST_YMax(map_extent) |
279
d89a19c297e0
list_users is now in users schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
261
diff
changeset
|
36 FROM users.list_users` |
254
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
37 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
38 listUserSQL = `SELECT |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
39 rolname, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
40 country, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
41 email_address, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
42 ST_XMin(map_extent), ST_YMin(map_extent), |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
43 ST_XMax(map_extent), ST_YMax(map_extent) |
279
d89a19c297e0
list_users is now in users schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
261
diff
changeset
|
44 FROM users.list_users |
254
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
45 WHERE username = $1` |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 ) |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
48 func deleteUser( |
288
4befc5868ea6
Mark input in user controllers as unused if they don't need a JSON input.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
287
diff
changeset
|
49 _ interface{}, req *http.Request, |
257
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
50 db *sql.DB, |
240
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
51 ) (jr JSONResult, err error) { |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
52 |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
53 user := mux.Vars(req)["user"] |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
54 if user == "" { |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
55 err = JSONError{http.StatusBadRequest, "error: user empty"} |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
56 return |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
57 } |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
58 |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
59 session, _ := auth.GetSession(req) |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
60 if session.User == user { |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
61 err = JSONError{http.StatusBadRequest, "error: cannot delete yourself"} |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
62 return |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
63 } |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
64 |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
65 if _, err = db.Exec(deleteUserSQL, user); err != nil { |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
66 return |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
67 } |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
68 |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
69 // Running in a go routine should not be necessary. |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
70 go func() { auth.ConnPool.Logout(user) }() |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
71 |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
72 jr = JSONResult{Code: http.StatusNoContent} |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
73 return |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
74 } |
9012e4045da4
Implemented /user delete controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
237
diff
changeset
|
75 |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
76 func updateUser( |
257
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
77 input interface{}, req *http.Request, |
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
78 db *sql.DB, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
79 ) (jr JSONResult, err error) { |
235
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
80 |
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
81 user := mux.Vars(req)["user"] |
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
82 if user == "" { |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
83 err = JSONError{http.StatusBadRequest, "error: user empty"} |
235
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
84 return |
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
85 } |
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
86 |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
87 newUser := input.(*User) |
307
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
88 var res sql.Result |
235
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
89 |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
90 if newUser.Extent == nil { |
307
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
91 res, err = db.Exec( |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
92 updateUserSQL, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
93 user, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
94 newUser.Role, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
95 newUser.User, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
96 newUser.Password, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
97 newUser.Country, |
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
98 newUser.Email, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
99 ) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
100 } else { |
307
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
101 res, err = db.Exec( |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
102 updateUserExtentSQL, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
103 user, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
104 newUser.Role, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
105 newUser.User, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
106 newUser.Password, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
107 newUser.Country, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
108 newUser.Extent.X1, newUser.Extent.Y1, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
109 newUser.Extent.X2, newUser.Extent.Y2, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
110 newUser.Email, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
111 ) |
235
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
112 } |
7d1f0ffdfa41
Implemented /users update controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
226
diff
changeset
|
113 |
311
74559e12a59f
sql.Result.RowsAffected is a driver specific feature. Check
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
114 if err != nil { |
74559e12a59f
sql.Result.RowsAffected is a driver specific feature. Check
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
115 return |
74559e12a59f
sql.Result.RowsAffected is a driver specific feature. Check
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
116 } |
74559e12a59f
sql.Result.RowsAffected is a driver specific feature. Check
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
117 |
74559e12a59f
sql.Result.RowsAffected is a driver specific feature. Check
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
307
diff
changeset
|
118 if n, err2 := res.RowsAffected(); err2 == nil && n == 0 { |
307
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
119 err = JSONError{ |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
120 Code: http.StatusNotFound, |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
121 Message: fmt.Sprintf("Cannot find user %s.", user), |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
122 } |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
123 return |
750a9c9cd965
Use SQL UPDATE to update users
Tom Gottfried <tom@intevation.de>
parents:
288
diff
changeset
|
124 } |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
261
ab9859981ee3
If a user got renamed kick her/him from the connection pool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
126 if user != newUser.User { |
ab9859981ee3
If a user got renamed kick her/him from the connection pool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
127 // Running in a go routine should not be necessary. |
ab9859981ee3
If a user got renamed kick her/him from the connection pool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
128 go func() { auth.ConnPool.Logout(user) }() |
ab9859981ee3
If a user got renamed kick her/him from the connection pool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
129 } |
ab9859981ee3
If a user got renamed kick her/him from the connection pool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
257
diff
changeset
|
130 |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
131 jr = JSONResult{ |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
132 Code: http.StatusCreated, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
133 Result: struct { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
134 Result string `json:"result"` |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
135 }{ |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
136 Result: "success", |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
137 }, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
138 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
139 return |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
140 } |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
141 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
142 func createUser( |
257
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
143 input interface{}, req *http.Request, |
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
144 db *sql.DB, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
145 ) (jr JSONResult, err error) { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
146 |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
147 user := input.(*User) |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
149 if user.Extent == nil { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
150 _, err = db.Exec( |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
151 createUserSQL, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
152 user.Role, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
153 user.User, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
154 user.Password, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
155 user.Country, |
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
156 user.Email, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
157 ) |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
158 } else { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
159 _, err = db.Exec( |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
160 createUserExtentSQL, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
161 user.Role, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
162 user.User, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
163 user.Password, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
164 user.Country, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
165 user.Extent.X1, user.Extent.Y1, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
166 user.Extent.X2, user.Extent.Y2, |
243
d39f897fae16
Made models for email, user and country driver.Valuer to get rid of some conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
241
diff
changeset
|
167 user.Email, |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
168 ) |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
187
51addc0533fe
More complete show case for creating users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
171 if err != nil { |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
172 return |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
175 jr = JSONResult{ |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
176 Code: http.StatusCreated, |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
177 Result: struct { |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
178 Result string `json:"result"` |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
179 }{ |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
180 Result: "success", |
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
181 }, |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 } |
237
3771788d3dae
Reduce boilerplate code when writing JSON parsing/generating endpoints.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
235
diff
changeset
|
183 return |
186
fe3a88f00b0a
Experimental user creation support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 } |
250
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
185 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
186 func listUsers( |
288
4befc5868ea6
Mark input in user controllers as unused if they don't need a JSON input.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
287
diff
changeset
|
187 _ interface{}, req *http.Request, |
257
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
188 db *sql.DB, |
250
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
189 ) (jr JSONResult, err error) { |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
190 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
191 var rows *sql.Rows |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
192 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
193 rows, err = db.Query(listUsersSQL) |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
194 if err != nil { |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
195 return |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
196 } |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
197 defer rows.Close() |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
198 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
199 var users []*User |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
200 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
201 for rows.Next() { |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
202 user := &User{Extent: &BoundingBox{}} |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
203 if err = rows.Scan( |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
204 &user.Role, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
205 &user.User, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
206 &user.Country, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
207 &user.Email, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
208 &user.Extent.X1, &user.Extent.Y1, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
209 &user.Extent.X2, &user.Extent.Y2, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
210 ); err != nil { |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
211 return |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
212 } |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
213 users = append(users, user) |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
214 } |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
215 |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
216 jr = JSONResult{ |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
217 Result: struct { |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
218 Users []*User `json:"users"` |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
219 }{ |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
220 Users: users, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
221 }, |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
222 } |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
223 return |
deabc2712634
Implemented /users GET as list of users.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
243
diff
changeset
|
224 } |
254
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
225 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
226 func listUser( |
288
4befc5868ea6
Mark input in user controllers as unused if they don't need a JSON input.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
287
diff
changeset
|
227 _ interface{}, req *http.Request, |
257
dfc2b035e055
Slimming down the signature of the JSONHandler type to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
254
diff
changeset
|
228 db *sql.DB, |
254
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
229 ) (jr JSONResult, err error) { |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
230 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
231 user := mux.Vars(req)["user"] |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
232 if user == "" { |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
233 err = JSONError{http.StatusBadRequest, "error: user empty"} |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
234 return |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
235 } |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
236 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
237 result := &User{ |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
238 User: user, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
239 Extent: &BoundingBox{}, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
240 } |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
241 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
242 err = db.QueryRow(listUserSQL, user).Scan( |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
243 &result.Role, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
244 &result.Country, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
245 &result.Email, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
246 &result.Extent.X1, &result.Extent.Y1, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
247 &result.Extent.X2, &result.Extent.Y2, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
248 ) |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
249 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
250 switch { |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
251 case err == sql.ErrNoRows: |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
252 err = JSONError{ |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
253 Code: http.StatusNotFound, |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
254 Message: fmt.Sprintf("Cannot find user %s.", user), |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
255 } |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
256 return |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
257 case err != nil: |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
258 return |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
259 } |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
260 |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
261 jr.Result = result |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
262 return |
de6fdb316b8f
Implemented /users/{user} GET a listing of given user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
253
diff
changeset
|
263 } |