user

package
v0.0.0-...-56fc341 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailRepository

type EmailRepository interface {
	SendAccountVerificationEmail(email, firstname, otp string) error
	SendResetPasswordEmail(email, firstname, otp string) error
}

type ItemVendor

type ItemVendor struct {
	ID     primitive.ObjectID `json:"id" bson:"_id,omitempty"`
	UserID primitive.ObjectID `json:"user_id" bson:"user_id,omitempty"`
	Name   string             `json:"name" bson:"name"`
	Email  string             `json:"email" bson:"email"`
}

type OTPRepository

type OTPRepository interface {
	GenerateSignUpOTP(email string) (string, error)
	GenerateForgotPasswordOTP(email string) (string, error)
	VerifySignUpOTP(email, otpStr string) (bool, error)
	VerifyForgotPasswordOTP(email, otpStr string) (bool, error)
	DeleteOTP(email string) error
}

type Role

type Role string
const (
	Admin    Role = "admin"
	Vendor   Role = "vendor"
	Customer Role = "customer"
)

type TokenRepository

type TokenRepository interface {
	GenerateToken(userId primitive.ObjectID) (*utils.TokenDetails, error)
	SaveToken(userId primitive.ObjectID, td *utils.TokenDetails) error
	DeleteToken(uuid string) error
	IdentifyUser(refreshToken string) (*utils.RefreshDetails, error)
}

type User

type User struct {
	ID          primitive.ObjectID `json:"id" bson:"_id,omitempty"`
	FirstName   string             `json:"first_name" bson:"first_name"`
	LastName    string             `json:"last_name" bson:"last_name"`
	Email       string             `json:"email" bson:"email"`
	Password    string             `json:"-" bson:"password"`
	PhoneNumber string             `json:"phone_number" bson:"phone_number"`
	IsVerified  bool               `json:"is_verified" bson:"is_verified"`
	Addresses   []types.Address    `json:"addresses" bson:"addresses"`
	Role        Role               `json:"role" bson:"role"`
	CreatedAt   time.Time          `json:"created_at" bson:"created_at"`
	UpdatedAt   time.Time          `json:"updated_at" bson:"updated_at"`
}

type UserController

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

func NewUserController

func NewUserController(userServices UserServices) *UserController

func (*UserController) AddAddress

func (uc *UserController) AddAddress(c *gin.Context)

func (*UserController) GetAddress

func (uc *UserController) GetAddress(c *gin.Context)

func (*UserController) GetAddresses

func (uc *UserController) GetAddresses(c *gin.Context)

func (*UserController) GetUsers

func (uc *UserController) GetUsers(c *gin.Context)

func (*UserController) Login

func (uc *UserController) Login(c *gin.Context)

func (*UserController) Logout

func (uc *UserController) Logout(c *gin.Context)

func (*UserController) Profile

func (uc *UserController) Profile(c *gin.Context)

func (*UserController) RefreshToken

func (uc *UserController) RefreshToken(c *gin.Context)

func (*UserController) RemoveAddress

func (uc *UserController) RemoveAddress(c *gin.Context)

func (*UserController) ResendEmailVerificationOTP

func (uc *UserController) ResendEmailVerificationOTP(c *gin.Context)

func (*UserController) ResetPassword

func (uc *UserController) ResetPassword(c *gin.Context)

TODO:: verify the otp before redirecting user to where they can reset their password

func (*UserController) SendForgotPasswordOTP

func (uc *UserController) SendForgotPasswordOTP(c *gin.Context)

func (*UserController) SignUp

func (uc *UserController) SignUp(c *gin.Context)

func (*UserController) UpdateAddress

func (uc *UserController) UpdateAddress(c *gin.Context)

func (*UserController) VerifyUser

func (uc *UserController) VerifyUser(c *gin.Context)

type UserRepo

type UserRepo struct {
	Collection *mongo.Collection
}

func NewUserRepo

func NewUserRepo(collection *mongo.Collection) *UserRepo

func (*UserRepo) CreateUser

func (ur *UserRepo) CreateUser(user *User) error

func (*UserRepo) GetUser

func (ur *UserRepo) GetUser(filter interface{}) (*User, error)

func (*UserRepo) GetUsers

func (ur *UserRepo) GetUsers(filter interface{}) ([]*User, error)

func (*UserRepo) IsExists

func (ur *UserRepo) IsExists(email string) (bool, error)

func (*UserRepo) UpdateUser

func (ur *UserRepo) UpdateUser(filter interface{}, update interface{}, opts ...*options.UpdateOptions) error

type UserRepository

type UserRepository interface {
	IsExists(email string) (bool, error)
	CreateUser(user *User) error
	UpdateUser(filter interface{}, update interface{}, opts ...*options.UpdateOptions) error
	GetUser(filter interface{}) (*User, error)
	GetUsers(filter interface{}) ([]*User, error)
}

type UserService

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

func NewUserService

func NewUserService(userRepository UserRepository,
	otpRepository OTPRepository, emailRepository EmailRepository, tokenRepository TokenRepository) *UserService

func (*UserService) AddAddress

func (us *UserService) AddAddress(userid primitive.ObjectID, address types.Address) *errors.AppError

func (*UserService) GetAddress

func (us *UserService) GetAddress(userid, addressid primitive.ObjectID) (*types.Address, *errors.AppError)

func (*UserService) GetAddresses

func (us *UserService) GetAddresses(userid primitive.ObjectID) ([]types.Address, *errors.AppError)

func (*UserService) GetUsers

func (us *UserService) GetUsers() ([]*User, *errors.AppError)

func (*UserService) Login

func (us *UserService) Login(email, password string) (*User, *utils.TokenDetails, *errors.AppError)

func (*UserService) Logout

func (us *UserService) Logout(accessUuid string) *errors.AppError

func (*UserService) Profile

func (us *UserService) Profile(userId primitive.ObjectID) (*User, *errors.AppError)

func (*UserService) RefreshToken

func (us *UserService) RefreshToken(refreshToken string) (*utils.TokenDetails, *errors.AppError)

func (*UserService) RemoveAddress

func (us *UserService) RemoveAddress(userid, addressid primitive.ObjectID) *errors.AppError

func (*UserService) ResendEmailVerificationOTP

func (us *UserService) ResendEmailVerificationOTP(email string) *errors.AppError

func (*UserService) ResetPassword

func (us *UserService) ResetPassword(email, otp, password string) *errors.AppError

func (*UserService) SendForgotPasswordOTP

func (us *UserService) SendForgotPasswordOTP(email string) *errors.AppError

func (*UserService) SignUpAndSendVerificationEmail

func (us *UserService) SignUpAndSendVerificationEmail(user *User) *errors.AppError

func (*UserService) UpdateAddress

func (us *UserService) UpdateAddress(userid, addressid primitive.ObjectID, address types.Address) *errors.AppError

func (*UserService) VerifyUser

func (us *UserService) VerifyUser(email, otp string) *errors.AppError

type UserServices

type UserServices interface {
	SignUpAndSendVerificationEmail(user *User) *errors.AppError
	VerifyUser(email, otp string) *errors.AppError
	Login(email, password string) (*User, *utils.TokenDetails, *errors.AppError)
	Profile(userId primitive.ObjectID) (*User, *errors.AppError)
	Logout(accessUuid string) *errors.AppError
	SendForgotPasswordOTP(email string) *errors.AppError
	ResetPassword(email, otp, password string) *errors.AppError
	RefreshToken(refreshToken string) (*utils.TokenDetails, *errors.AppError)
	ResendEmailVerificationOTP(email string) *errors.AppError
	AddAddress(userid primitive.ObjectID, address types.Address) *errors.AppError
	RemoveAddress(userid, addressid primitive.ObjectID) *errors.AppError
	GetAddresses(userid primitive.ObjectID) ([]types.Address, *errors.AppError)
	GetAddress(userid, addressid primitive.ObjectID) (*types.Address, *errors.AppError)
	UpdateAddress(userid, addressid primitive.ObjectID, address types.Address) *errors.AppError
	GetUsers() ([]*User, *errors.AppError)
}

Jump to

Keyboard shortcuts

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