(c *gin.Context)
| 192 | } |
| 193 | |
| 194 | func updateUserProfile(c *gin.Context) { |
| 195 | response := gin.H{"code": http.StatusOK} |
| 196 | defer c.JSON(http.StatusOK, response) |
| 197 | var user User |
| 198 | if err := c.BindJSON(&user); err != nil { |
| 199 | response["code"] = http.StatusBadRequest |
| 200 | log.Println(err) |
| 201 | return |
| 202 | } |
| 203 | if user.ID == 0 { |
| 204 | response["code"] = http.StatusBadRequest |
| 205 | return |
| 206 | } |
| 207 | currUser := mydb.getUserProfile(c.GetString("username")) |
| 208 | if user.ID != currUser.ID { |
| 209 | if !currUser.isAdmin() { |
| 210 | response["code"] = http.StatusForbidden |
| 211 | return |
| 212 | } |
| 213 | } |
| 214 | user.Password = currUser.Password |
| 215 | if err := mydb.updateUserProfile(&user); err != nil { |
| 216 | response["code"] = http.StatusInternalServerError |
| 217 | return |
| 218 | } |
| 219 | response["user"] = mydb.getUserProfile(user.Username) |
| 220 | } |
| 221 | |
| 222 | func changeUserRole(c *gin.Context) { |
| 223 | response := gin.H{"code": http.StatusOK} |
nothing calls this directly
no test coverage detected