entities

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package entities provides domain entities that represent the core business objects in the application, including users, forms, and other domain models.

Index

Constants

View Source
const (
	// MinPasswordLength is the minimum length required for passwords
	MinPasswordLength = 8
)

Variables

View Source
var (
	// ErrInvalidEmail represents an invalid email format error
	ErrInvalidEmail = errors.New("invalid email format")
	// ErrInvalidPassword represents an invalid password error
	ErrInvalidPassword = errors.New("password must be at least 8 characters")
)

Functions

This section is empty.

Types

type User

type User struct {
	ID             string         `json:"id" gorm:"column:uuid;primaryKey;type:uuid;default:gen_random_uuid()"`
	Email          string         `json:"email" gorm:"uniqueIndex;not null;size:255"`
	HashedPassword string         `json:"-" gorm:"column:hashed_password;not null;size:255"`
	FirstName      string         `json:"first_name" gorm:"not null;size:100"`
	LastName       string         `json:"last_name" gorm:"not null;size:100"`
	Role           string         `json:"role" gorm:"not null;size:50;default:user"`
	Active         bool           `json:"active" gorm:"not null;default:true"`
	CreatedAt      time.Time      `json:"created_at" gorm:"not null;autoCreateTime"`
	UpdatedAt      time.Time      `json:"updated_at" gorm:"not null;autoUpdateTime"`
	DeletedAt      gorm.DeletedAt `json:"-" gorm:"index"`
}

User represents a user entity

func NewUser added in v0.1.5

func NewUser(email, password, firstName, lastName string) (*User, error)

NewUser creates a new user instance with validation

func (*User) Activate added in v0.1.5

func (u *User) Activate()

Activate marks the user as active

func (*User) AfterFind added in v0.1.5

func (u *User) AfterFind(_ *gorm.DB) error

AfterFind is a GORM hook that runs after finding a user

func (*User) BeforeCreate added in v0.1.5

func (u *User) BeforeCreate(_ *gorm.DB) error

BeforeCreate is a GORM hook that runs before creating a user

func (*User) BeforeUpdate added in v0.1.5

func (u *User) BeforeUpdate(_ *gorm.DB) error

BeforeUpdate is a GORM hook that runs before updating a user

func (*User) CheckPassword added in v0.1.5

func (u *User) CheckPassword(password string) bool

CheckPassword verifies if the provided password matches the user's hashed password

func (*User) Deactivate added in v0.1.5

func (u *User) Deactivate()

Deactivate marks the user as inactive

func (*User) GetFullName added in v0.1.5

func (u *User) GetFullName() string

GetFullName returns the user's full name

func (*User) GetID added in v0.1.5

func (u *User) GetID() string

GetID returns the user's ID

func (*User) SetID added in v0.1.5

func (u *User) SetID(id string)

SetID sets the user's ID

func (*User) SetPassword added in v0.1.5

func (u *User) SetPassword(password string) error

SetPassword hashes and sets the user's password

func (*User) TableName added in v0.1.5

func (u *User) TableName() string

TableName specifies the table name for the User model

func (*User) UpdateProfile added in v0.1.5

func (u *User) UpdateProfile(firstName, lastName string)

UpdateProfile updates the user's profile information

func (*User) Validate added in v0.1.5

func (u *User) Validate() error

Validate performs validation on the user entity

func (*User) ValidatePassword added in v0.1.5

func (u *User) ValidatePassword(password string) error

ValidatePassword validates a password

Jump to

Keyboard shortcuts

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