diff options
| author | haturatu <taro@eyes4you.org> | 2025-10-13 06:17:21 +0900 |
|---|---|---|
| committer | haturatu <taro@eyes4you.org> | 2025-10-13 06:17:21 +0900 |
| commit | a4a5b418e367c3172439c080490cd5b3dfb526c1 (patch) | |
| tree | bd14ea5ed4d1e6c46856127eb50c10586010e5f6 | |
| parent | bf63281f289d09367aca24088760c9b0a0b9da3d (diff) | |
ref(types): move EnrichedUser
| -rw-r--r-- | handlers/admin.go | 11 | ||||
| -rw-r--r-- | types/types.go | 6 |
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 |
