user

package
v0.0.5-dev Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type User

type User struct {
	ID                     uuid.UUID      `json:"id" gorm:"primaryKey;type:uuid"`
	Username               string         `json:"username" gorm:"uniqueIndex;not null"`
	Email                  string         `json:"email" gorm:"uniqueIndex;not null"`
	Password               string         `json:"-" gorm:"not null"`
	VerifiedAt             sql.NullTime   `json:"-"`
	VerificationToken      string         `json:"-" gorm:"uniqueIndex;not null"`
	PasswordResetToken     sql.NullString `json:"-" gorm:"uniqueIndex"`
	PasswordResetExpiresAt time.Time      `json:"-"`
	IsAdmin                bool           `json:"is_admin" gorm:"not null"`
	Lang                   string         `json:"lang" gorm:"not null"`
	CreatedAt              time.Time      `json:"created_at"`
	UpdatedAt              time.Time      `json:"updated_at"`
	DeletedAt              gorm.DeletedAt `json:"-" gorm:"index"`
}

Represents the 'User' object.

func (*User) BeforeCreate

func (user *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate will set default values for the user.

func (*User) BeforeUpdate

func (user *User) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate will set default values for the user.

type UserRepository

type UserRepository interface {
	GetUsers(ctx context.Context) (*[]User, error)
	GetUser(ctx context.Context, userID uuid.UUID) (*User, error)
	GetUserByEmail(ctx context.Context, userEmail string) (*User, error)
	GetUserByUsername(ctx context.Context, username string) (*User, error)
	CreateUser(ctx context.Context, user *User) error
	UpdateUser(ctx context.Context, userID uuid.UUID, user *User) error
	DeleteUser(ctx context.Context, userID uuid.UUID) error
	GetFirstUser(ctx context.Context) (*User, error)
	GetUserByVerificationToken(ctx context.Context, verificationToken string) (*User, error)
	SetUserVerified(ctx context.Context, userID uuid.UUID) error
	SetPasswordResetToken(ctx context.Context, userID uuid.UUID, token string, expiresAt time.Time) error
	GetUserByPasswordResetToken(ctx context.Context, token string) (*User, error)
}

Our repository will implement these methods.

func NewUserRepository

func NewUserRepository(dbConnection *gorm.DB) UserRepository

Create a new repository with MariaDB as the driver.

type UserService

type UserService interface {
	GetUsers(ctx context.Context) (*[]User, error)
	GetUser(ctx context.Context, userID uuid.UUID) (*User, error)
	GetUserByEmail(ctx context.Context, userEmail string) (*User, error)
	GetUserByUsername(ctx context.Context, username string) (*User, error)
	CreateUser(ctx context.Context, user *User) error
	UpdateUser(ctx context.Context, userID uuid.UUID, user *User) error
	DeleteUser(ctx context.Context, userID uuid.UUID) error
	IsFirstUser(ctx context.Context) (bool, error)
	GetUserByEmailOrUsername(ctx context.Context, emailOrUsername string) (*User, error)
	VerifyUser(ctx context.Context, verificationToken string) error
	SetPasswordResetToken(ctx context.Context, userID uuid.UUID, token string, expiresAt time.Time) error
	ResetPassword(ctx context.Context, token string, password string) error
}

Our use-case or service will implement these methods.

func NewUserService

func NewUserService(r UserRepository) UserService

Create a new 'service' or 'use-case' for 'User' entity.

Jump to

Keyboard shortcuts

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