user

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: 7 Imported by: 0

Documentation

Overview

Package user provides user repository interfaces for domain persistence.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound indicates that a user was not found
	ErrUserNotFound = domainerrors.New(domainerrors.ErrCodeNotFound, "user not found", nil)
	// ErrEmailAlreadyExists indicates that a user with the given email already exists
	ErrEmailAlreadyExists = domainerrors.New(domainerrors.ErrCodeAlreadyExists, "email already exists", nil)
	// ErrInvalidCredentials indicates that the provided credentials are invalid
	ErrInvalidCredentials = domainerrors.New(domainerrors.ErrCodeAuthentication, "invalid credentials", nil)
	// ErrUserExists indicates that a user with the given email already exists
	ErrUserExists = domainerrors.New(domainerrors.ErrCodeAlreadyExists, "user already exists", nil)
)

Functions

This section is empty.

Types

type Login

type Login struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required"`
}

Login represents a user login request

type LoginResponse added in v0.1.5

type LoginResponse struct {
	User *entities.User
}

LoginResponse represents a user login response

type Repository added in v0.1.5

type Repository interface {
	repository.Repository[*entities.User]
	// GetByEmail gets a user by email
	GetByEmail(ctx context.Context, email string) (*entities.User, error)
	// GetByUsername gets a user by username
	GetByUsername(ctx context.Context, username string) (*entities.User, error)
	// GetByRole gets users by role
	GetByRole(ctx context.Context, role string, offset, limit int) ([]*entities.User, error)
	// GetActiveUsers gets all active users
	GetActiveUsers(ctx context.Context, offset, limit int) ([]*entities.User, error)
	// GetInactiveUsers gets all inactive users
	GetInactiveUsers(ctx context.Context, offset, limit int) ([]*entities.User, error)
}

Repository defines the interface for user storage

type Service

type Service interface {
	SignUp(ctx context.Context, signup *Signup) (*entities.User, error)
	Login(ctx context.Context, login *Login) (*LoginResponse, error)
	Logout(ctx context.Context) error
	GetUserByID(ctx context.Context, id string) (*entities.User, error)
	GetUserByEmail(ctx context.Context, email string) (*entities.User, error)
	UpdateUser(ctx context.Context, user *entities.User) error
	DeleteUser(ctx context.Context, id string) error
	ListUsers(ctx context.Context, offset, limit int) ([]*entities.User, error)
	GetByID(ctx context.Context, id string) (*entities.User, error)
	Authenticate(ctx context.Context, email, password string) (*entities.User, error)
}

Service defines the user service interface

func NewService

func NewService(repo Repository, logger logging.Logger) Service

NewService creates a new user service

type ServiceImpl

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

ServiceImpl implements the Service interface

func (*ServiceImpl) Authenticate added in v0.1.5

func (s *ServiceImpl) Authenticate(ctx context.Context, email, password string) (*entities.User, error)

Authenticate matches the domain.UserService interface

func (*ServiceImpl) DeleteUser

func (s *ServiceImpl) DeleteUser(ctx context.Context, id string) error

DeleteUser deletes a user

func (*ServiceImpl) GetByID

func (s *ServiceImpl) GetByID(ctx context.Context, id string) (*entities.User, error)

GetByID retrieves a user by ID string

func (*ServiceImpl) GetUserByEmail

func (s *ServiceImpl) GetUserByEmail(ctx context.Context, email string) (*entities.User, error)

GetUserByEmail retrieves a user by email

func (*ServiceImpl) GetUserByID

func (s *ServiceImpl) GetUserByID(ctx context.Context, id string) (*entities.User, error)

GetUserByID retrieves a user by ID

func (*ServiceImpl) ListUsers

func (s *ServiceImpl) ListUsers(ctx context.Context, offset, limit int) ([]*entities.User, error)

ListUsers lists all users

func (*ServiceImpl) Login

func (s *ServiceImpl) Login(ctx context.Context, login *Login) (*LoginResponse, error)

Login authenticates a user

func (*ServiceImpl) Logout

func (s *ServiceImpl) Logout(_ context.Context) error

Logout handles user logout

func (*ServiceImpl) SignUp

func (s *ServiceImpl) SignUp(ctx context.Context, signup *Signup) (*entities.User, error)

SignUp registers a new user

func (*ServiceImpl) UpdateUser

func (s *ServiceImpl) UpdateUser(ctx context.Context, user *entities.User) error

UpdateUser updates a user

type Signup

type Signup struct {
	Email           string `json:"email" validate:"required,email"`
	Password        string `json:"password" validate:"required,min=8"`
	ConfirmPassword string `json:"confirm_password" validate:"required,eqfield=password"`
}

Signup represents a user signup request

Jump to

Keyboard shortcuts

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