all repos — weimar @ cf03eeda27ccb78fc82bbbb91a92e2b30bd2eb18

Unnamed repository; edit this file 'description' to name the repository.

internal/api/users.go (view raw)

 1package api
 2
 3import (
 4	"net/http"
 5	"strconv"
 6)
 7
 8func (a *API) HandleGetMe(w http.ResponseWriter, r *http.Request) {
 9	user := UserFromContext(r.Context())
10	if user == nil {
11		writeError(w, http.StatusUnauthorized, "unauthorized")
12		return
13	}
14
15	avatarURL := ""
16	if user.AvatarPath != nil {
17		avatarURL = "/api/users/" + strconv.FormatInt(user.ID, 10) + "/avatar"
18	}
19
20	writeJSON(w, http.StatusOK, map[string]any{
21		"id":         user.ID,
22		"username":   user.Username,
23		"is_admin":   user.IsAdmin,
24		"avatar_url": avatarURL,
25		"created_at": user.CreatedAt,
26		"updated_at": user.UpdatedAt,
27	})
28}