user

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DomainService

type DomainService interface {
	// ValidateUniqueEmail ensures email uniqueness across the domain
	ValidateUniqueEmail(ctx context.Context, email Email, excludeUserID *UserID) error

	// CanDeleteUser checks if a user can be safely deleted
	CanDeleteUser(ctx context.Context, userID UserID) error
}

DomainService defines domain-specific business logic that doesn't belong to a single entity

func NewDomainService

func NewDomainService(userRepo Repository) DomainService

NewDomainService creates a new domain service instance

type Email

type Email struct {
	// contains filtered or unexported fields
}

Email represents a validated email address

func NewEmail

func NewEmail(email string) (Email, error)

NewEmail creates a new Email value object with validation

func (Email) Equals

func (e Email) Equals(other Email) bool

Equals checks if two Emails are equal

func (Email) String

func (e Email) String() string

String returns the string representation of the Email

type Name

type Name struct {
	// contains filtered or unexported fields
}

Name represents a validated user name

func NewName

func NewName(name string) (Name, error)

NewName creates a new Name value object with validation

func (Name) Equals

func (n Name) Equals(other Name) bool

Equals checks if two Names are equal

func (Name) String

func (n Name) String() string

String returns the string representation of the Name

type Repository

type Repository interface {
	// FindByID retrieves a user by their ID
	FindByID(ctx context.Context, id UserID) (*User, error)

	// FindByEmail retrieves a user by their email address
	FindByEmail(ctx context.Context, email Email) (*User, error)

	// FindAll retrieves users with pagination support
	// limit: maximum number of users to return
	// cursor: pagination cursor (empty string for first page)
	// Returns users and next cursor (empty if no more pages)
	FindAll(ctx context.Context, limit int, cursor string) ([]*User, string, error)

	// Create persists a new user
	Create(ctx context.Context, user *User) error

	// Update modifies an existing user
	Update(ctx context.Context, user *User) error

	// Delete removes a user by their ID
	Delete(ctx context.Context, id UserID) error

	// ExistsByEmail checks if a user with the given email exists
	ExistsByEmail(ctx context.Context, email Email) (bool, error)

	// Count returns the total number of users
	Count(ctx context.Context) (int64, error)
}

Repository defines the interface for user persistence operations

type User

type User struct {
	// contains filtered or unexported fields
}

User represents the user domain entity

func NewUser

func NewUser(email, name string) (*User, error)

NewUser creates a new User entity with validation

func NewUserWithID

func NewUserWithID(id, email, name string, createdAt, updatedAt time.Time) (*User, error)

NewUserWithID creates a User entity with a specific ID (for reconstruction from persistence)

func (*User) CreatedAt

func (u *User) CreatedAt() time.Time

CreatedAt returns when the user was created

func (*User) Email

func (u *User) Email() Email

Email returns the user's email

func (*User) Equals

func (u *User) Equals(other *User) bool

Equals checks if two users are equal based on their ID

func (*User) ID

func (u *User) ID() UserID

ID returns the user's ID

func (*User) Name

func (u *User) Name() Name

Name returns the user's name

func (*User) UpdateEmail

func (u *User) UpdateEmail(email string) error

UpdateEmail updates the user's email with validation

func (*User) UpdateName

func (u *User) UpdateName(name string) error

UpdateName updates the user's name with validation

func (*User) UpdatedAt

func (u *User) UpdatedAt() time.Time

UpdatedAt returns when the user was last updated

func (*User) Validate

func (u *User) Validate() error

Validate performs comprehensive validation of the user entity

type UserID

type UserID struct {
	// contains filtered or unexported fields
}

UserID represents a unique identifier for a user

func GenerateUserID

func GenerateUserID() UserID

GenerateUserID creates a new random UserID

func NewUserID

func NewUserID(id string) (UserID, error)

NewUserID creates a new UserID from a string

func (UserID) Equals

func (id UserID) Equals(other UserID) bool

Equals checks if two UserIDs are equal

func (UserID) String

func (id UserID) String() string

String returns the string representation of the UserID

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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