diff --git a/internal/admin/users.go b/internal/admin/users.go index 3988bd9..40ae211 100644 --- a/internal/admin/users.go +++ b/internal/admin/users.go @@ -13,20 +13,6 @@ import ( "github.com/google/uuid" ) -func NewUserDTO(row *repository.User) types.UserDTO { - return types.UserDTO{ - ID: row.ID, - Email: row.Email, - FullName: row.FullName, - IsAdmin: row.IsAdmin, - CreatedAt: row.CreatedAt, - UpdatedAt: row.UpdatedAt, - LastLogin: row.LastLogin, - PhoneNumber: row.PhoneNumber, - ProfilePicture: row.ProfilePicture, - } -} - func (h *AdminHandler) GetUsers(w http.ResponseWriter, r *http.Request) { userId, ok := util.GetRequestUserId(r.Context()) if !ok { @@ -55,7 +41,7 @@ func (h *AdminHandler) GetUsers(w http.ResponseWriter, r *http.Request) { var items []types.UserDTO for _, user := range users { - items = append(items, NewUserDTO(&user)) + items = append(items, types.NewUserDTO(&user)) } encoder := json.NewEncoder(w) @@ -88,7 +74,7 @@ func (h *AdminHandler) GetUser(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - if err := encoder.Encode(NewUserDTO(&user)); err != nil { + if err := encoder.Encode(types.NewUserDTO(&user)); err != nil { web.Error(w, "failed to encode user dto", http.StatusInternalServerError) } } diff --git a/internal/auth/routes.go b/internal/auth/routes.go index a809f3b..8fc4ad7 100644 --- a/internal/auth/routes.go +++ b/internal/auth/routes.go @@ -162,17 +162,7 @@ func (h *AuthHandler) getProfile(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - if err := json.NewEncoder(w).Encode(types.UserDTO{ - ID: user.ID, - FullName: user.FullName, - Email: user.Email, - PhoneNumber: user.PhoneNumber, - IsAdmin: user.IsAdmin, - LastLogin: user.LastLogin, - ProfilePicture: user.ProfilePicture, - UpdatedAt: user.UpdatedAt, - CreatedAt: user.CreatedAt, - }); err != nil { + if err := json.NewEncoder(w).Encode(types.NewUserDTO(&user)); err != nil { web.Error(w, "failed to encode user profile", http.StatusInternalServerError) } } diff --git a/internal/types/user.go b/internal/types/user.go index e6a8806..e83d0c3 100644 --- a/internal/types/user.go +++ b/internal/types/user.go @@ -3,6 +3,7 @@ package types import ( "time" + "gitea.local/admin/hspguard/internal/repository" "github.com/google/uuid" ) @@ -16,4 +17,24 @@ type UserDTO struct { LastLogin *time.Time `json:"last_login"` PhoneNumber *string `json:"phone_number"` ProfilePicture *string `json:"profile_picture"` + EmailVerified bool `json:"email_verified"` + AvatarVerified bool `json:"avatar_verified"` + Verified bool `json:"verified"` +} + +func NewUserDTO(row *repository.User) UserDTO { + return UserDTO{ + ID: row.ID, + Email: row.Email, + FullName: row.FullName, + IsAdmin: row.IsAdmin, + CreatedAt: row.CreatedAt, + UpdatedAt: row.UpdatedAt, + LastLogin: row.LastLogin, + PhoneNumber: row.PhoneNumber, + ProfilePicture: row.ProfilePicture, + EmailVerified: row.EmailVerified, + AvatarVerified: row.AvatarVerified, + Verified: row.Verified, + } }