service

package
v0.0.0-...-5811bfc Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidEmailFormat    = errors.New("Invalid email format. Check RFC 5322.")
	ErrInvalidPasswordFormat = errors.New("Password format: Min. 8 chars, atleast 1 number" +
		"1 lowercase char, 1 uppercase char, 1 special char")
	ErrEmailExists          = errors.New("This email already exists.")
	ErrInvalidEmailPassword = errors.New("Invalid email/password combination.")
	ErrNilUser              = errors.New("Nil user.")
	ErrInvalidToken         = errors.New("Invalid token.")
	ErrInvalidLog           = errors.New("Invalid log.")
	ErrNoLogInsert          = errors.New("Insertion failed, check logs.")
	ErrNoLogUpdate          = errors.New("Update failed, check logs.")
	ErrNoLogFetch           = errors.New("Fetching failed, check logs.")
)

Functions

This section is empty.

Types

type Service

type Service struct {
	Repo      repository.Repository
	Conn      redis.Conn
	JwtSecret []byte
	Logger    *zap.Logger
}

func (*Service) CreateLog

func (service *Service) CreateLog(ctx context.Context, l *entity.Log) error

CreateLog will insert a new log in the database

func (*Service) EndLog

func (service *Service) EndLog(ctx context.Context, userId string, id string, endTime int64) error

EndLog will update a log's endTime

func (*Service) GetLogsInRange

func (service *Service) GetLogsInRange(ctx context.Context, userId string, startTime int64, endTime int64) (*[]entity.Log, error)

GetLogsInRange will fetch all logs for the user within the given range of startTime and endTime.

func (*Service) GetPendingLogs

func (service *Service) GetPendingLogs(ctx context.Context, userId string) (*[]entity.Log, error)

GetPendingLogs will fetch pending logs from DB for the given user.

func (*Service) Login

func (service *Service) Login(ctx context.Context, u *entity.User) (string, error)

Login creates a new JWT and returns it if there is no error.

func (*Service) Logout

func (service *Service) Logout(ctx context.Context, token string) error

Logout will put the JWT in the cache which acts as a blacklist.

func (*Service) Signup

func (service *Service) Signup(ctx context.Context, u *entity.User) error

Signup creates a new user in the database if all the checks pass.

func (*Service) StartLog

func (service *Service) StartLog(ctx context.Context, l *entity.Log) error

StartLog will create a new log in the database with endTime as 0

func (*Service) VerifyAndDecodeToken

func (service *Service) VerifyAndDecodeToken(ctx context.Context, token string) (string, error)

VerifyAndDecodeToken will get the payload we need if the token is valid.

Jump to

Keyboard shortcuts

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