05165c6587
- Deleted the company_id field from CreateUserForm, User entity, and related API documentation in Swagger and YAML files to streamline user creation process. - Updated the CreateUser service method to reflect the removal of company_id, ensuring consistency across the user management functionality.
76 lines
2.5 KiB
Go
76 lines
2.5 KiB
Go
package user
|
|
|
|
import (
|
|
"tm/pkg/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// UserRole represents user roles in the system
|
|
type UserRole string
|
|
|
|
const (
|
|
UserRoleAdmin UserRole = "admin"
|
|
UserRoleManager UserRole = "manager"
|
|
UserRoleOperator UserRole = "operator"
|
|
UserRoleViewer UserRole = "viewer"
|
|
)
|
|
|
|
// UserStatus represents user account status
|
|
type UserStatus string
|
|
|
|
const (
|
|
UserStatusActive UserStatus = "active"
|
|
UserStatusInactive UserStatus = "inactive"
|
|
UserStatusSuspended UserStatus = "suspended"
|
|
)
|
|
|
|
// User represents a system user (admin/manager/operator)
|
|
type User struct {
|
|
mongo.Model `bson:",inline"`
|
|
FullName string `bson:"full_name" json:"full_name"`
|
|
Username string `bson:"username" json:"username"`
|
|
Email string `bson:"email" json:"email"`
|
|
Password string `bson:"password" json:"-"` // Never serialize password
|
|
Role UserRole `bson:"role" json:"role"`
|
|
Status UserStatus `bson:"status" json:"status"`
|
|
Department *string `bson:"department,omitempty" json:"department,omitempty"`
|
|
Position *string `bson:"position,omitempty" json:"position,omitempty"`
|
|
Phone *string `bson:"phone,omitempty" json:"phone,omitempty"`
|
|
ProfileImage *string `bson:"profile_image,omitempty" json:"profile_image,omitempty"`
|
|
IsVerified bool `bson:"is_verified" json:"is_verified"`
|
|
LastLoginAt *int64 `bson:"last_login_at,omitempty" json:"last_login_at,omitempty"` // Unix timestamp
|
|
CreatedBy *string `bson:"created_by,omitempty" json:"created_by,omitempty"`
|
|
UpdatedBy *string `bson:"updated_by,omitempty" json:"updated_by,omitempty"`
|
|
}
|
|
|
|
// SetID sets the user ID (implements IDSetter interface)
|
|
func (u *User) SetID(id string) {
|
|
u.ID, _ = primitive.ObjectIDFromHex(id)
|
|
}
|
|
|
|
// GetID returns the user ID (implements IDGetter interface)
|
|
func (u *User) GetID() string {
|
|
return u.ID.Hex()
|
|
}
|
|
|
|
// SetCreatedAt sets the created timestamp (implements Timestampable interface)
|
|
func (u *User) SetCreatedAt(timestamp int64) {
|
|
u.CreatedAt = timestamp
|
|
}
|
|
|
|
// SetUpdatedAt sets the updated timestamp (implements Timestampable interface)
|
|
func (u *User) SetUpdatedAt(timestamp int64) {
|
|
u.UpdatedAt = timestamp
|
|
}
|
|
|
|
// GetCreatedAt returns the created timestamp (implements Timestampable interface)
|
|
func (u *User) GetCreatedAt() int64 {
|
|
return u.CreatedAt
|
|
}
|
|
|
|
// GetUpdatedAt returns the updated timestamp (implements Timestampable interface)
|
|
func (u *User) GetUpdatedAt() int64 {
|
|
return u.UpdatedAt
|
|
}
|