Files
tm_back/internal/user/entity.go
T
n.nakhostin dfcdef60d6 Add Device Token Support for Customer and User Entities
- Introduced a new DeviceToken field in both Customer and User entities to store device tokens for authentication and notifications.
- Updated LoginForm structures for both Customer and User to include an optional DeviceToken field, allowing clients to send device tokens during login.
- Enhanced the Login methods in the customer and user services to append the device token to the respective entities if it does not already exist, improving user session management and notification capabilities.
- Ensured proper validation and structured responses for the new DeviceToken field in the forms, maintaining compliance with best practices for API design.
2025-09-20 10:11:36 +03:30

75 lines
2.0 KiB
Go

package user
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
)
// 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"`
Username string `bson:"username"`
Email string `bson:"email"`
Password string `bson:"password" json:"-"`
Role UserRole `bson:"role"`
Status UserStatus `bson:"status"`
Department *string `bson:"department"`
Position *string `bson:"position"`
Phone *string `bson:"phone"`
ProfileImage *string `bson:"profile_image"`
DeviceToken []string `bson:"device_token"`
IsVerified bool `bson:"is_verified"`
LastLoginAt *int64 `bson:"last_login_at"`
}
// SetID sets the user ID (implements IDSetter interface)
func (u *User) SetID(id string) {
u.ID, _ = bson.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 Timestamp interface)
func (u *User) SetCreatedAt(timestamp int64) {
u.CreatedAt = timestamp
}
// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
func (u *User) SetUpdatedAt(timestamp int64) {
u.UpdatedAt = timestamp
}
// GetCreatedAt returns the created timestamp (implements Timestamp interface)
func (u *User) GetCreatedAt() int64 {
return u.CreatedAt
}
// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
func (u *User) GetUpdatedAt() int64 {
return u.UpdatedAt
}