user

package
v0.0.0-...-d563f25 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongPassword      = errors.New("wrong password")
	ErrWrongPhone         = errors.New("wrong phone")
	ErrPhoneAlreadyExists = errors.New("Phone Already Exists")
)

Errors

Functions

This section is empty.

Types

type FindAllUsersParams

type FindAllUsersParams struct {
	ID    int    `json:"id"`
	Page  int    `json:"page"`
	Limit int    `json:"limit"`
	Phone string `json:"phone"`
	Name  string `json:"name"`
	Token string `json:"token"`
}

FindAllUsersParams params for find all

type LoginParams

type LoginParams struct {
	Phone    string `json:"phone"`
	Password string `json:"password"`
}

LoginParams represent the http request data for login user

type LoginResponse

type LoginResponse struct {
	SessionID string      `json:"sessionId"`
	Claims    interface{} `json:"claims"`
}

LoginResponse represents the response of login function

type Service

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

Service is the domain logic implementation of user Service interface

func NewService

func NewService(
	userStorage Storage,
) *Service

NewService creates a new user AppService

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, params *TransactionParams) (*Users, *types.Error)

CreateUser create user

func (*Service) GetByToken

func (s *Service) GetByToken(ctx context.Context, token string) (*Users, *types.Error)

GetByToken get user by its token

func (*Service) GetUser

func (s *Service) GetUser(ctx context.Context, userID int) (*Users, *types.Error)

GetUser is get user

func (*Service) ListUsers

func (s *Service) ListUsers(ctx context.Context, params *FindAllUsersParams) ([]*Users, int, *types.Error)

ListUsers is listing users

func (*Service) Login

func (s *Service) Login(ctx context.Context, phone string, password string) (*LoginResponse, *types.Error)

Login login

type ServiceInterface

type ServiceInterface interface {
	ListUsers(ctx context.Context, params *FindAllUsersParams) ([]*Users, int, *types.Error)
	GetUser(ctx context.Context, userID int) (*Users, *types.Error)
	CreateUser(ctx context.Context, params *TransactionParams) (*Users, *types.Error)
	Login(ctx context.Context, phone string, password string) (*LoginResponse, *types.Error)
	GetByToken(ctx context.Context, token string) (*Users, *types.Error)
}

ServiceInterface represents the user service interface

type Storage

type Storage interface {
	FindAll(ctx context.Context, params *FindAllUsersParams) ([]*Users, *types.Error)
	FindByID(ctx context.Context, userID int) (*Users, *types.Error)
	FindByPhone(ctx context.Context, phone string) (*Users, *types.Error)
	FindByToken(ctx context.Context, token string) (*Users, *types.Error)
	Insert(ctx context.Context, user *Users) (*Users, *types.Error)
	Update(ctx context.Context, user *Users) (*Users, *types.Error)
	Delete(ctx context.Context, userID int) *types.Error
}

Storage represents the user storage interface

type TransactionParams

type TransactionParams struct {
	RoleID   int    `json:"roleId"`
	Name     string `json:"name"`
	Phone    string `json:"phone"`
	Password string
}

TransactionParams params for transaction

type Users

type Users struct {
	ID             int        `json:"id" db:"id"`
	RoleID         int        `json:"roleId" db:"roleId"`
	Name           string     `json:"name" db:"name"`
	Phone          string     `json:"phone" db:"phone"`
	Password       string     `json:"password" db:"password"`
	Token          *string    `json:"token" db:"token"`
	TokenExpiredAt *time.Time `json:"tokenExpiredAt" db:"tokenExpiredAt"`
	CreatedAt      time.Time  `json:"createdAt" db:"createdAt"`
	UpdatedAt      *time.Time `json:"updatedAt" db:"updatedAt"`
}

Users user

type VerifyParams

type VerifyParams struct {
	Token string `json:"token"`
}

VerifyParams ..

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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