From 0a7a2512d4eea48672a447ebd719b5f069acfdfd Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 1 Apr 2026 20:35:00 +0000 Subject: [PATCH] Properly set Avatar value to null --- api/routes.go | 3 ++- platform/user.go | 29 +++++++++++++++-------------- resource/user.go | 30 ++++++++++++++---------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/api/routes.go b/api/routes.go index c6cd7e18..366e58ea 100644 --- a/api/routes.go +++ b/api/routes.go @@ -8,6 +8,7 @@ import ( ) func AddRoutes(r *mux.Router) { + router := resource.NewRouter(r) //r.Use(render.SetContentType(render.ContentTypeJSON)) // Unauthenticated endpoints r.HandleFunc("/signin", handlerJSONPost(postSignin)) @@ -50,7 +51,7 @@ func AddRoutes(r *mux.Router) { r.Handle("/upload/{id}/commit", authenticatedHandlerJSONPost(upload.Commit)).Methods("POST") r.Handle("/upload/{id}/discard", authenticatedHandlerJSONPost(upload.Discard)).Methods("POST") - user := resource.User(r) + user := resource.User(router) r.Handle("/user/self", authenticatedHandlerJSON(user.SelfGet)).Methods("GET") r.Handle("/user/suggestion", authenticatedHandlerJSON(user.SuggestionGet)).Methods("GET") r.Handle("/user", authenticatedHandlerJSONSlice(user.List)).Methods("GET") diff --git a/platform/user.go b/platform/user.go index 7ca09a02..ec7bd798 100644 --- a/platform/user.go +++ b/platform/user.go @@ -25,19 +25,19 @@ type NoUserError struct{} func (e NoUserError) Error() string { return "That user does not exist" } type User struct { - Active bool `json:"active"` - Avatar string `json:"avatar"` - DisplayName string `json:"display_name"` - ID int `json:"id"` - Initials string `json:"initials"` - Notifications []Notification `json:"notifications"` - NotificationCounts UserNotificationCounts `json:"notification_counts"` - Organization Organization `json:"organization"` - PasswordHash string `json:"-"` - PasswordHashType string `json:"-"` - Role string `json:"role"` - Tags []string `json:"tags"` - Username string `json:"username"` + Active bool + Avatar *uuid.UUID + DisplayName string + ID int + Initials string + Notifications []Notification + NotificationCounts UserNotificationCounts + Organization Organization + PasswordHash string + PasswordHashType string + Role string + Tags []string + Username string model *models.User } @@ -53,9 +53,10 @@ func (u User) HasRoot() bool { return u.model.Role == enums.UserroleRoot } func newUser(ctx context.Context, org Organization, user *models.User) User { + avatar := user.Avatar.Ptr() u := User{ Active: true, - Avatar: user.Avatar.GetOr(uuid.UUID{}).String(), + Avatar: avatar, DisplayName: user.DisplayName, ID: int(user.ID), Initials: extractInitials(user.DisplayName), diff --git a/resource/user.go b/resource/user.go index 40881d21..21c6bd56 100644 --- a/resource/user.go +++ b/resource/user.go @@ -15,10 +15,10 @@ import ( ) type userResponse struct { - Avatar string `json:"avatar"` - DisplayName string `json:"display_name"` - Initials string `json:"initials"` - IsActive bool `json:"is_active"` + Avatar *string `json:"avatar"` + DisplayName string `json:"display_name"` + Initials string `json:"initials"` + IsActive bool `json:"is_active"` //Notifications []Notification `json:"notifications"` //NotificationCounts UserNotificationCounts `json:"notification_counts"` //Organization Organization `json:"organization"` @@ -30,7 +30,7 @@ type userResponse struct { Username string `json:"username"` } -func User(r *mux.Router) *userR { +func User(r *router) *userR { return &userR{ router: r, } @@ -39,30 +39,28 @@ func (res *userR) response(u *platform.User) (*userResponse, error) { if u == nil { return nil, fmt.Errorf("nil user") } - log.Info().Int("id", u.ID).Msg("making response from user") - i := strconv.FormatInt(int64(u.ID), 10) - handler := res.router.Get("user.ByIDGet") - if handler == nil { - return nil, fmt.Errorf("nil handler") - } - uri, err := handler.URL("id", i) + avatar, err := res.router.UUIDToURI("avatar.ByUUIDGet", u.Avatar) if err != nil { - return nil, fmt.Errorf("build uri: %w", err) + return nil, fmt.Errorf("id to uri: %w", err) + } + uri, err := res.router.IDToURI("user.ByIDGet", u.ID) + if err != nil { + return nil, fmt.Errorf("id to uri: %w", err) } return &userResponse{ - Avatar: u.Avatar, + Avatar: avatar, DisplayName: u.DisplayName, Initials: u.Initials, IsActive: u.Active, Role: u.Role, Tags: u.Tags, - URI: uri.String(), + URI: uri, Username: u.Username, }, nil } type userR struct { - router *mux.Router + router *router } type responseListUser struct { Users []*platform.User `json:"users"`