Documentation
¶
Index ¶
- Variables
- type Login
- type LoginResponse
- type Repository
- type Service
- type ServiceImpl
- func (s *ServiceImpl) Authenticate(ctx context.Context, email, password string) (*User, error)
- func (s *ServiceImpl) DeleteUser(ctx context.Context, id string) error
- func (s *ServiceImpl) GetByID(ctx context.Context, id string) (*User, error)
- func (s *ServiceImpl) GetUserByEmail(ctx context.Context, email string) (*User, error)
- func (s *ServiceImpl) GetUserByID(ctx context.Context, id string) (*User, error)
- func (s *ServiceImpl) GetUserIDFromToken(ctx context.Context, token string) (string, error)
- func (s *ServiceImpl) IsTokenBlacklisted(ctx context.Context, token string) (bool, error)
- func (s *ServiceImpl) ListUsers(ctx context.Context) ([]User, error)
- func (s *ServiceImpl) Login(ctx context.Context, login *Login) (*LoginResponse, error)
- func (s *ServiceImpl) Logout(ctx context.Context, refreshToken string) error
- func (s *ServiceImpl) SignUp(ctx context.Context, signup *Signup) (*User, error)
- func (s *ServiceImpl) UpdateUser(ctx context.Context, user *User) error
- func (s *ServiceImpl) ValidateToken(ctx context.Context, token string) error
- type Signup
- type TokenPair
- type User
Constants ¶
This section is empty.
Variables ¶
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) // ErrInvalidToken indicates that the provided token is invalid ErrInvalidToken = domainerrors.New(domainerrors.ErrCodeInvalidToken, "invalid token", nil) // ErrTokenExpired indicates that the provided token has expired ErrTokenExpired = domainerrors.New(domainerrors.ErrCodeInvalidToken, "token has expired", nil) )
var ErrInvalidUserID = errors.New("invalid user ID")
ErrInvalidUserID indicates that the provided user ID is invalid
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 the user login request
type LoginResponse ¶ added in v0.1.5
LoginResponse represents the response from a successful login
type Repository ¶ added in v0.1.5
type Repository 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) ([]User, error)
GetByIDString(ctx context.Context, id string) (*User, error)
}
Repository defines the interface for user storage (renamed from Store for consistency)
type Service ¶
type Service interface {
SignUp(ctx context.Context, signup *Signup) (*User, error)
Login(ctx context.Context, login *Login) (*LoginResponse, error)
Logout(ctx context.Context, refreshToken string) error
GetUserByID(ctx context.Context, id string) (*User, error)
GetUserByEmail(ctx context.Context, email string) (*User, error)
UpdateUser(ctx context.Context, user *User) error
DeleteUser(ctx context.Context, id string) error
ListUsers(ctx context.Context) ([]User, error)
GetByID(ctx context.Context, id string) (*User, error)
ValidateToken(ctx context.Context, token string) error
GetUserIDFromToken(ctx context.Context, token string) (string, error)
IsTokenBlacklisted(ctx context.Context, token string) (bool, error)
Authenticate(ctx context.Context, email, password string) (*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
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) GetUserByEmail ¶
GetUserByEmail retrieves a user by email
func (*ServiceImpl) GetUserByID ¶
GetUserByID retrieves a user by ID
func (*ServiceImpl) GetUserIDFromToken ¶
GetUserIDFromToken extracts the user ID from a token
func (*ServiceImpl) IsTokenBlacklisted ¶
IsTokenBlacklisted checks if a token is blacklisted
func (*ServiceImpl) ListUsers ¶
func (s *ServiceImpl) ListUsers(ctx context.Context) ([]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(ctx context.Context, refreshToken string) error
Logout blacklists a refresh token
func (*ServiceImpl) UpdateUser ¶
func (s *ServiceImpl) UpdateUser(ctx context.Context, user *User) error
UpdateUser updates a user
func (*ServiceImpl) ValidateToken ¶
func (s *ServiceImpl) ValidateToken(ctx context.Context, token string) error
ValidateToken validates a token
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,match=password"`
FirstName string `json:"first_name" validate:"required"`
LastName string `json:"last_name" validate:"required"`
}
Signup represents the user signup request
type TokenPair ¶
type TokenPair struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
}
TokenPair represents a pair of access and refresh tokens
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 in the system
func (*User) BeforeCreate ¶ added in v0.2.0
BeforeCreate is a GORM hook that runs before creating a user
func (*User) BeforeUpdate ¶ added in v0.2.0
BeforeUpdate is a GORM hook that runs before updating a user
func (*User) CheckPassword ¶
CheckPassword verifies if the provided password matches the user's hashed password
func (*User) SetPassword ¶
SetPassword hashes and sets the user's password