Refactor user struct and user info handling for improved readability

This commit is contained in:
Leon Bösche
2026-01-24 02:30:34 +01:00
parent c7e740e732
commit c3e3356574
2 changed files with 12 additions and 12 deletions

View File

@@ -63,12 +63,12 @@ func (sa StringArray) Value() (driver.Value, error) {
}
type User struct {
ID uuid.UUID `json:"id"`
Email string `json:"email"`
Username string `json:"username"`
DisplayName string `json:"displayName"`
PasswordHash *string `json:"-"`
CreatedAt time.Time `json:"createdAt"`
ID uuid.UUID `json:"id"`
Email string `json:"email"`
Username string `json:"username"`
DisplayName string `json:"displayName"`
PasswordHash *string `json:"-"`
CreatedAt time.Time `json:"createdAt"`
LastLoginAt *time.Time `json:"lastLoginAt"`
}

View File

@@ -922,15 +922,15 @@ func listMembersHandler(w http.ResponseWriter, r *http.Request, db *database.DB)
Role: m.Membership.Role,
CreatedAt: m.Membership.CreatedAt,
User: userInfo{
ID: m.User.ID.String(),
Username: m.User.Username,
ID: m.User.ID.String(),
Username: m.User.Username,
DisplayName: func() *string {
if m.User.DisplayName == "" {
return nil
}
return &m.User.DisplayName
}(),
Email: m.User.Email,
Email: m.User.Email,
},
})
}
@@ -1194,15 +1194,15 @@ func listJoinRequestsHandler(w http.ResponseWriter, r *http.Request, db *databas
RequestedAt: req.JoinRequest.RequestedAt,
Status: req.JoinRequest.Status,
User: userInfo{
ID: req.User.ID.String(),
Username: req.User.Username,
ID: req.User.ID.String(),
Username: req.User.Username,
DisplayName: func() *string {
if req.User.DisplayName == "" {
return nil
}
return &req.User.DisplayName
}(),
Email: req.User.Email,
Email: req.User.Email,
},
})
}