user

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package user provides user domain models and management.

Index

Constants

View Source
const (
	RoleAdmin    = "Admin"
	RoleAgent    = "Agent"
	RoleCustomer = "Customer"
	RoleGuest    = "Guest"
)

User roles.

View Source
const (
	ActionCreate = "create"
	ActionRead   = "read"
	ActionUpdate = "update"
	ActionDelete = "delete"
	ActionList   = "list"
	ActionManage = "manage"
)

Permission actions.

View Source
const (
	ResourceTicket       = "ticket"
	ResourceUser         = "user"
	ResourceQueue        = "queue"
	ResourceReport       = "report"
	ResourceSystem       = "system"
	ResourceOrganization = "organization"
)

Permission resources.

Variables

This section is empty.

Functions

func RegisterUserServiceServer

func RegisterUserServiceServer(s interface{}, srv UserServiceServer)

RegisterUserServiceServer registers the service with gRPC server.

Types

type AuthenticateUserRequest

type AuthenticateUserRequest struct {
	Email     string `json:"email"`
	Password  string `json:"password"`
	IpAddress string `json:"ip_address"`
	UserAgent string `json:"user_agent"`
}

type AuthenticateUserResponse

type AuthenticateUserResponse struct {
	User  *UserProto `json:"user"`
	Token string     `json:"token"`
}

type CacheService

type CacheService interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
	Invalidate(ctx context.Context, pattern string) error
}

CacheService defines the interface for caching.

type CreateUserRequest

type CreateUserRequest struct {
	Email      string `json:"email"`
	Password   string `json:"password"`
	FirstName  string `json:"first_name"`
	LastName   string `json:"last_name"`
	Role       string `json:"role"`
	Department string `json:"department"`
}

type CreateUserResponse

type CreateUserResponse struct {
	User *UserProto `json:"user"`
}

type Event

type Event struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Timestamp time.Time              `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`
	Source    string                 `json:"source"`
	Version   string                 `json:"version"`
}

Event represents a domain event.

type EventBus

type EventBus interface {
	Publish(ctx context.Context, event Event) error
	Subscribe(ctx context.Context, topic string, handler EventHandler) error
}

EventBus defines the interface for event publishing.

type EventHandler

type EventHandler func(ctx context.Context, event Event) error

EventHandler processes events.

type GetUserRequest

type GetUserRequest struct {
	Id string `json:"id"`
}

type GetUserResponse

type GetUserResponse struct {
	User *UserProto `json:"user"`
}

type Group

type Group struct {
	ID          string                 `json:"id" db:"id"`
	Name        string                 `json:"name" db:"name"`
	Description string                 `json:"description" db:"description"`
	Permissions []Permission           `json:"permissions,omitempty"`
	Metadata    map[string]interface{} `json:"metadata" db:"metadata"`
	CreatedAt   time.Time              `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at" db:"updated_at"`
}

Group represents a user group.

type ListFilter

type ListFilter struct {
	Role        string    `json:"role,omitempty"`
	Department  string    `json:"department,omitempty"`
	IsActive    *bool     `json:"is_active,omitempty"`
	GroupID     string    `json:"group_id,omitempty"`
	CreatedFrom time.Time `json:"created_from,omitempty"`
	CreatedTo   time.Time `json:"created_to,omitempty"`
	SortBy      string    `json:"sort_by,omitempty"`
	SortOrder   string    `json:"sort_order,omitempty"`
	Limit       int       `json:"limit,omitempty"`
	Offset      int       `json:"offset,omitempty"`
}

ListFilter represents user list filtering options.

type ListUsersRequest

type ListUsersRequest struct {
	Role     string `json:"role"`
	IsActive *bool  `json:"is_active"`
	Limit    int32  `json:"limit"`
	Offset   int32  `json:"offset"`
}

type ListUsersResponse

type ListUsersResponse struct {
	Users []*UserProto `json:"users"`
	Total int32        `json:"total"`
}

type MetricsCollector

type MetricsCollector interface {
	IncrementCounter(name string, labels map[string]string)
	RecordDuration(name string, duration time.Duration, labels map[string]string)
	SetGauge(name string, value float64, labels map[string]string)
}

MetricsCollector defines the interface for metrics collection.

type Permission

type Permission struct {
	ID          string    `json:"id" db:"id"`
	Name        string    `json:"name" db:"name"`
	Resource    string    `json:"resource" db:"resource"`
	Action      string    `json:"action" db:"action"`
	Description string    `json:"description" db:"description"`
	CreatedAt   time.Time `json:"created_at" db:"created_at"`
}

Permission represents a system permission.

type Session

type Session struct {
	ID         string                 `json:"id" db:"id"`
	UserID     string                 `json:"user_id" db:"user_id"`
	Token      string                 `json:"token" db:"token"`
	IPAddress  string                 `json:"ip_address" db:"ip_address"`
	UserAgent  string                 `json:"user_agent" db:"user_agent"`
	ExpiresAt  time.Time              `json:"expires_at" db:"expires_at"`
	CreatedAt  time.Time              `json:"created_at" db:"created_at"`
	LastUsedAt time.Time              `json:"last_used_at" db:"last_used_at"`
	Metadata   map[string]interface{} `json:"metadata" db:"metadata"`
}

Session represents a user session.

type UnimplementedUserServiceServer

type UnimplementedUserServiceServer struct{}

UnimplementedUserServiceServer can be embedded to have forward compatible implementations.

func (UnimplementedUserServiceServer) AuthenticateUser

func (UnimplementedUserServiceServer) CreateUser

func (UnimplementedUserServiceServer) GetUser

func (UnimplementedUserServiceServer) ListUsers

func (UnimplementedUserServiceServer) UpdateUser

type UpdateUserRequest

type UpdateUserRequest struct {
	Id        string `json:"id"`
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Role      string `json:"role"`
	IsActive  *bool  `json:"is_active"`
}

type UpdateUserResponse

type UpdateUserResponse struct {
	User *UserProto `json:"user"`
}

type User

type User struct {
	ID             string                 `json:"id" db:"id"`
	Email          string                 `json:"email" db:"email"`
	FirstName      string                 `json:"first_name" db:"first_name"`
	LastName       string                 `json:"last_name" db:"last_name"`
	PasswordHash   string                 `json:"-" db:"password_hash"`
	Role           string                 `json:"role" db:"role"`
	Department     string                 `json:"department,omitempty" db:"department"`
	Phone          string                 `json:"phone,omitempty" db:"phone"`
	Mobile         string                 `json:"mobile,omitempty" db:"mobile"`
	IsActive       bool                   `json:"is_active" db:"is_active"`
	EmailVerified  bool                   `json:"email_verified" db:"email_verified"`
	TwoFactorAuth  bool                   `json:"two_factor_auth" db:"two_factor_auth"`
	Preferences    map[string]interface{} `json:"preferences" db:"preferences"`
	LastLoginAt    *time.Time             `json:"last_login_at,omitempty" db:"last_login_at"`
	LastActivityAt *time.Time             `json:"last_activity_at,omitempty" db:"last_activity_at"`
	CreatedAt      time.Time              `json:"created_at" db:"created_at"`
	UpdatedAt      time.Time              `json:"updated_at" db:"updated_at"`
	DeletedAt      *time.Time             `json:"deleted_at,omitempty" db:"deleted_at"`

	// Relationships
	Groups      []Group      `json:"groups,omitempty"`
	Permissions []Permission `json:"permissions,omitempty"`
	Sessions    []Session    `json:"sessions,omitempty"`
}

User represents a system user.

func (*User) Clone

func (u *User) Clone() *User

Clone creates a deep copy of the user.

func (*User) ToProto

func (u *User) ToProto() *UserProto

ToProto converts the user to protobuf format.

type UserProto

type UserProto struct {
	Id             string `json:"id"`
	Email          string `json:"email"`
	FirstName      string `json:"first_name"`
	LastName       string `json:"last_name"`
	Role           string `json:"role"`
	Department     string `json:"department"`
	Phone          string `json:"phone"`
	Mobile         string `json:"mobile"`
	IsActive       bool   `json:"is_active"`
	EmailVerified  bool   `json:"email_verified"`
	TwoFactorAuth  bool   `json:"two_factor_auth"`
	LastLoginAt    int64  `json:"last_login_at"`
	LastActivityAt int64  `json:"last_activity_at"`
	CreatedAt      int64  `json:"created_at"`
	UpdatedAt      int64  `json:"updated_at"`
}

UserProto represents a user in protobuf format.

type UserRepository

type UserRepository interface {
	Create(ctx context.Context, user *User) error
	GetByID(ctx context.Context, id string) (*User, error)
	GetByEmail(ctx context.Context, email string) (*User, error)
	Update(ctx context.Context, user *User) error
	Delete(ctx context.Context, id string) error
	List(ctx context.Context, filter *ListFilter) ([]*User, error)
	Search(ctx context.Context, query string) ([]*User, error)
	UpdateLastLogin(ctx context.Context, id string, timestamp time.Time) error
	GetByRole(ctx context.Context, role string) ([]*User, error)
}

UserRepository defines the interface for user data access.

type UserService

type UserService struct {
	UnimplementedUserServiceServer
	// contains filtered or unexported fields
}

UserService handles all user-related operations as a microservice.

func NewUserService

func NewUserService(repo UserRepository, cache CacheService, events EventBus, metrics MetricsCollector) *UserService

NewUserService creates a new user service instance.

func (*UserService) AuthenticateUser

AuthenticateUser authenticates a user with email and password.

func (*UserService) CreateUser

CreateUser creates a new user.

func (*UserService) GetUser

func (s *UserService) GetUser(ctx context.Context, req *GetUserRequest) (*GetUserResponse, error)

GetUser retrieves a user by ID.

func (*UserService) ListUsers

func (s *UserService) ListUsers(ctx context.Context, req *ListUsersRequest) (*ListUsersResponse, error)

ListUsers lists users with filtering.

func (*UserService) Start

func (s *UserService) Start(port int) error

Start starts the gRPC server.

func (*UserService) UpdateUser

UpdateUser updates an existing user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL