user

package
v0.0.0-...-10519c5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitHTTPEndpoints

func InitHTTPEndpoints(g *echo.Group, cnt *HTTPController)

Types

type HTTPController

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

func NewHTTPController

func NewHTTPController(svc *Service) *HTTPController

func (*HTTPController) Login

func (cnt *HTTPController) Login(c echo.Context) error

func (*HTTPController) Register

func (cnt *HTTPController) Register(c echo.Context) error

type LoginRequest

type LoginRequest struct {
	Username string `json:"username" validate:"min=4"`
	Password string `json:"password" validate:"min=6"`
}

type NewUserOpts

type NewUserOpts struct {
	Username       string
	Email          string
	HashedPassword []byte
}

type PostgresRepo

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

func NewPostgresRepo

func NewPostgresRepo(db *pgxpool.Pool) *PostgresRepo

func (*PostgresRepo) Create

func (r *PostgresRepo) Create(ctx context.Context, user *User) error

func (*PostgresRepo) Delete

func (r *PostgresRepo) Delete(ctx context.Context, id string) error

func (*PostgresRepo) Get

func (r *PostgresRepo) Get(ctx context.Context, id string) (*User, error)

func (*PostgresRepo) GetByUsername

func (r *PostgresRepo) GetByUsername(ctx context.Context, username string) (*User, error)

func (*PostgresRepo) Update

func (r *PostgresRepo) Update(ctx context.Context, user *User) error

type RegisterRequest

type RegisterRequest struct {
	Username string `json:"username" validate:"min=4"`
	Email    string `json:"email" validate:"email"`
	Password string `json:"password" validate:"min=6"`
}

type Repo

type Repo interface {
	Create(context.Context, *User) error
	GetByUsername(ctx context.Context, username string) (*User, error)
	Get(ctx context.Context, id string) (*User, error)
	Delete(ctx context.Context, id string) error
	Update(ctx context.Context, user *User) error
}

type Service

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

func NewService

func NewService(repo Repo) *Service

func (*Service) CheckPassword

func (s *Service) CheckPassword(ctx context.Context, username string, password string) error

func (*Service) Create

func (s *Service) Create(ctx context.Context, dto NewUserOpts) error

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (UserResponse, error)

func (*Service) GetByUsername

func (s *Service) GetByUsername(ctx context.Context, username string) (UserResponse, error)

type User

type User struct {
	ID             string
	Username       string
	Email          string
	HashedPassword []byte
	About          string

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

func NewUser

func NewUser(opts NewUserOpts) *User

func (*User) UpdateAbout

func (u *User) UpdateAbout(about string)

func (*User) UpdateEmail

func (u *User) UpdateEmail(email string)

func (*User) UpdatePassword

func (u *User) UpdatePassword(hashedPassword []byte)

type UserResponse

type UserResponse struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	About    string `json:"about"`

	CreatedAt time.Time `json:"createdAt"`
}

UserResponse represent user information that will be sent to outside of this module

func ToUserResponse

func ToUserResponse(u *User) UserResponse

Jump to

Keyboard shortcuts

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