summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--handlers/admin.go11
-rw-r--r--types/types.go6
2 files changed, 9 insertions, 8 deletions
diff --git a/handlers/admin.go b/handlers/admin.go
index 5614e0e..2c86b7d 100644
--- a/handlers/admin.go
+++ b/handlers/admin.go
@@ -44,12 +44,7 @@ func AdminPageHandler(w http.ResponseWriter, r *http.Request) {
}
}
-// EnrichedUser is a wrapper for User with additional computed fields.
-// Note: We use pointers to the original User to avoid copying large structs.
-type EnrichedUser struct {
- *types.User
- TimeSinceLogin string `json:"time_since_login"`
-}
+
// GetUsersHandler returns a list of all users with enriched information.
// It uses a worker pool to calculate extra information for each user in parallel.
@@ -62,7 +57,7 @@ func GetUsersHandler(w http.ResponseWriter, r *http.Request) {
return
}
- enrichedUsers := make([]EnrichedUser, len(users))
+ enrichedUsers := make([]types.EnrichedUser, len(users))
var wg sync.WaitGroup
for i, user := range users {
@@ -81,7 +76,7 @@ func GetUsersHandler(w http.ResponseWriter, r *http.Request) {
timeSinceLogin = fmt.Sprintf("%.0fm ago", time.Since(userCopy.LastLoginAt.Time).Minutes())
}
- enrichedUsers[index] = EnrichedUser{
+ enrichedUsers[index] = types.EnrichedUser{
User: &userCopy,
TimeSinceLogin: timeSinceLogin,
}
diff --git a/types/types.go b/types/types.go
index 79059d4..44cb60a 100644
--- a/types/types.go
+++ b/types/types.go
@@ -97,3 +97,9 @@ type WorkerPool struct {
Wg sync.WaitGroup
Active int64
}
+
+// EnrichedUser is a wrapper for User with additional computed fields for admin views.
+type EnrichedUser struct {
+ *User
+ TimeSinceLogin string `json:"time_since_login"`
+} \ No newline at end of file