Properly set Avatar value to null
This commit is contained in:
parent
6fbde6389d
commit
0a7a2512d4
3 changed files with 31 additions and 31 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
type userResponse struct {
|
||||
Avatar string `json:"avatar"`
|
||||
Avatar *string `json:"avatar"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Initials string `json:"initials"`
|
||||
IsActive bool `json:"is_active"`
|
||||
|
|
@ -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"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue