Skip to content
Snippets Groups Projects
Commit 978d45c2 authored by Dean's avatar Dean
Browse files

version 1.6.1: fix /users/me to be backwards compatible

parent bed9a54a
No related branches found
Tags v1.6.1
No related merge requests found
......@@ -9,6 +9,23 @@ import (
"github.com/go-chi/render"
)
// meResponse is the response type for /users/me.
type meResponse struct {
Success bool `json:"success"`
StatusCode *int `json:"errorcode"`
User meUser `json:"user"`
}
// meUser is a modified version of db.User for /users/me to maintain
// compatibility with the original version of the route.
type meUser struct {
UserID string `json:"user_id"`
Username string `json:"username"`
Email string `json:"email"`
IsAdmin bool `json:"is_admin"`
IsBlocked bool `json:"is_blocked"`
}
// Me handles /users/me requests.
func Me(w http.ResponseWriter, r *http.Request) {
// Only authorized users can use this route
......@@ -18,7 +35,14 @@ func Me(w http.ResponseWriter, r *http.Request) {
}
// Return response
u := meUser{
UserID: user.ID,
Username: user.Username,
Email: user.Email,
IsAdmin: user.IsAdmin,
IsBlocked: user.IsBlocked,
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
render.JSON(w, r, user)
render.JSON(w, r, meResponse{true, nil, u})
}
......@@ -25,7 +25,7 @@ import (
const (
configLocationUnix = "/etc/whats-this/api/config.toml"
shutdownTimeout = 10 * time.Second
version = "1.6.0"
version = "1.6.1"
)
// printConfiguration iterates through a configuration map[string]interface{}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment