user

package
v0.0.0-...-6ecc318 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound      = errors.New("user not found")
	ErrDB                = errors.New("DB error")
	ErrUpdateUserFailed  = errors.New("update user failed")
	ErrUserAlreadyExist  = errors.New("user already exist")
	ErrGenPasswordFailed = errors.New("generate password failed")
	ErrCreateUserFailed  = errors.New("create user failed")
	ErrPermissionDeny    = errors.New("permission deny")
)

Functions

This section is empty.

Types

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword string `validate:"required" json:"old_password"`
	NewPassword string `validate:"required" json:"new_password"`
}

type Gender

type Gender int
const (
	MALE   Gender = 1
	FEMALE Gender = 2
	OTHER  Gender = 3
)

type Handler

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

func NewHandler

func NewHandler(srv service) *Handler

func (*Handler) DeleteUser

func (h *Handler) DeleteUser(w http.ResponseWriter, r *http.Request)

func (*Handler) FindUserById

func (h *Handler) FindUserById(w http.ResponseWriter, r *http.Request)

func (*Handler) GetAllUsers

func (h *Handler) GetAllUsers(w http.ResponseWriter, r *http.Request)

func (*Handler) Register

func (h *Handler) Register(w http.ResponseWriter, r *http.Request)

func (*Handler) Routes

func (h *Handler) Routes() []router.Route

func (*Handler) Update

func (h *Handler) Update(w http.ResponseWriter, r *http.Request)

type MongoDBRepository

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

func NewMongoDBRepository

func NewMongoDBRepository(session *mgo.Session) *MongoDBRepository

func (*MongoDBRepository) CheckEmailIsRegisted

func (m *MongoDBRepository) CheckEmailIsRegisted(ctx context.Context, email string) error

func (*MongoDBRepository) Create

func (m *MongoDBRepository) Create(ctx context.Context, user User) (string, error)

func (*MongoDBRepository) Delete

func (m *MongoDBRepository) Delete(ctx context.Context, id string) error

func (*MongoDBRepository) FindUserByEmail

func (m *MongoDBRepository) FindUserByEmail(ctx context.Context, email string) (*User, error)

func (*MongoDBRepository) FindUserById

func (m *MongoDBRepository) FindUserById(ctx context.Context, id string) (*User, error)

func (*MongoDBRepository) GetAllUsers

func (m *MongoDBRepository) GetAllUsers(ctx context.Context) ([]*User, error)

func (*MongoDBRepository) Update

func (m *MongoDBRepository) Update(ctx context.Context, user User) error

type RegisterRequest

type RegisterRequest struct {
	FirstName string `validate:"required" json:"first_name"`
	LastName  string `validate:"required" json:"last_name"`
	Gender    Gender `validate:"gte=0,lte=2" json:"gender"`
	Email     string `validate:"required,email" json:"email"`
	Password  string `validate:"required" json:"password"`
}

type Service

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

func NewService

func NewService(repo repository, policy policyService) *Service

func (*Service) ChangePassword

func (s *Service) ChangePassword(ctx context.Context, req ChangePasswordRequest) error

func (*Service) DeleteUser

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

func (*Service) FindUserByEmail

func (s *Service) FindUserByEmail(ctx context.Context, email string) (*types.UserInfo, error)

func (*Service) FindUserById

func (s *Service) FindUserById(ctx context.Context, id string) (*types.UserInfo, error)

func (*Service) GetAllUsers

func (s *Service) GetAllUsers(ctx context.Context) ([]*types.UserInfo, error)

func (*Service) Register

func (s *Service) Register(ctx context.Context, req RegisterRequest) (string, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, id string, req UpdateInfoRequest) error

type UpdateInfoRequest

type UpdateInfoRequest struct {
	FirstName string `validate:"required" json:"first_name"`
	LastName  string `validate:"required" json:"last_name"`
	Gender    Gender `validate:"gte=0,lte=2" json:"gender"`
}

type User

type User struct {
	ID        string    `bson:"_id"`
	FirstName string    `bson:"first_name"`
	LastName  string    `bson:"last_name"`
	Gender    Gender    `bson:"gender"`
	Email     string    `bson:"email"`
	Role      string    `bson:"role"`
	Password  string    `bson:"password"`
	Locked    bool      `bson:"locked"`
	CreatedAt time.Time `bson:"created_at"`
	UpdatedAt time.Time `bson:"updated_at"`
}

func (*User) ConvertUserToUserInfo

func (u *User) ConvertUserToUserInfo() *types.UserInfo

func (*User) TrimSecrectUserInfo

func (u *User) TrimSecrectUserInfo() *User

Jump to

Keyboard shortcuts

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