data

package
v0.0.0-...-e77dc18 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromJSON

func FromJSON(i interface{}, r io.Reader) error

FromJSON deserializes the object from JSON string given in the io.Reader to the given interface

func NewConnection

func NewConnection(config *utils.Configurations, logger hclog.Logger) (*sqlx.DB, error)

NewConnection creates the connection to the database

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

ToJSON serializes the given interface into a string based JSON format

Types

type AuthRepository

type AuthRepository interface {
	Create(ctx context.Context, user *User) error
	GetUserByEmail(ctx context.Context, email string) (*User, error)
	GetUserByID(ctx context.Context, userID string) (*User, error)
	UpdateUsername(ctx context.Context, user *User) error
	StoreVerificationData(ctx context.Context, verificationData *VerificationData) error
	GetVerificationData(ctx context.Context, email string, verificationDataType VerificationDataType) (*VerificationData, error)
	UpdateUserVerificationStatus(ctx context.Context, email string, status bool) error
	DeleteVerificationData(ctx context.Context, email string, verificationDataType VerificationDataType) error
	UpdatePassword(ctx context.Context, userID string, password string, tokenHash string) error
}

AuthRepository is an interface for the storage implementation of the auth service

type Exercise

type Exercise struct {
	UID                 string        `json:"uid" db:"uid"`
	UserID              string        `json:"user_id,omitempty" db:"user_id"`
	Name                string        `json:"name,omitempty" db:"name"`
	Duration            time.Duration `json:"duration,omitempty" db:"duration"`
	Relax               time.Duration `json:"relax,omitempty" db:"relax"`
	Count               int32         `json:"count,omitempty" db:"count"`
	NumberOfSets        int32         `json:"number_of_sets,omitempty" db:"number_of_sets"`
	NumberOfRepetitions int32         `json:"number_of_repetitions,omitempty" db:"number_of_repetitions"`
	Type                int32         `json:"type,omitempty" db:"type"`
	Image               string        `json:"image,omitempty" db:"image"`
	Video               string        `json:"video,omitempty" db:"video"`
	Description         string        `json:"description,omitempty" db:"description"`
	Technique           string        `json:"technique,omitempty" db:"technique"`
	Mistake             string        `json:"mistake,omitempty" db:"mistake"`
	Weight              int32         `json:"weight,omitempty" db:"weight"`
	CreatedAt           time.Time     `json:"createdat" db:"createdat"`
	UpdatedAt           time.Time     `json:"updatedat" db:"updatedat"`
}

type ExerciseSlice

type ExerciseSlice []Exercise

func (*ExerciseSlice) Scan

func (s *ExerciseSlice) Scan(src interface{}) error

Make the Exercise struct implement the sql.Scanner interface. This method simply decodes a JSON-encoded value into the struct fields.

func (ExerciseSlice) Value

func (a ExerciseSlice) Value() (driver.Value, error)

Make the Exercise struct implement the driver.Valuer interface. This method simply returns the JSON-encoded representation of the struct.

type MemoryRepository

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

MemoryRepository has the implementation of the memory methods.

func NewAuthMemoryRepository

func NewAuthMemoryRepository(logger hclog.Logger) *MemoryRepository

NewAuthMemoryRepository returns a new PostgresRepository instance

func (*MemoryRepository) Create

func (repo *MemoryRepository) Create(ctx context.Context, user *User) error

Create inserts the given user into the database

func (*MemoryRepository) DeleteVerificationData

func (repo *MemoryRepository) DeleteVerificationData(ctx context.Context, email string, verificationDataType VerificationDataType) error

DeleteVerificationData deletes a used verification data

func (*MemoryRepository) GetUserByEmail

func (repo *MemoryRepository) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail retrieves the user object having the given email, else returns error

func (*MemoryRepository) GetUserByID

func (repo *MemoryRepository) GetUserByID(ctx context.Context, userID string) (*User, error)

GetUserByID retrieves the user object having the given ID, else returns error

func (*MemoryRepository) GetVerificationData

func (repo *MemoryRepository) GetVerificationData(ctx context.Context, email string, verificationDataType VerificationDataType) (*VerificationData, error)

GetVerificationData retrieves the stored verification code.

func (*MemoryRepository) StoreVerificationData

func (repo *MemoryRepository) StoreVerificationData(ctx context.Context, verificationData *VerificationData) error

StoreVerificationData adds a mail verification data to db

func (*MemoryRepository) UpdatePassword

func (repo *MemoryRepository) UpdatePassword(ctx context.Context, userID string, password string, tokenHash string) error

UpdatePassword updates the user password

func (*MemoryRepository) UpdateUserVerificationStatus

func (repo *MemoryRepository) UpdateUserVerificationStatus(ctx context.Context, email string, status bool) error

UpdateUserVerificationStatus updates user verification status to true

func (*MemoryRepository) UpdateUsername

func (repo *MemoryRepository) UpdateUsername(ctx context.Context, user *User) error

UpdateUsername updates the username of the given user

type ParametersUser

type ParametersUser struct {
	UID           string         `json:"uid" db:"uid"`
	UserID        string         `json:"user_id,omitempty" db:"user_id"`
	UserName      string         `json:"username,omitempty" db:"username"`
	Weight        int32          `json:"weight,omitempty" db:"weight"`
	Height        int32          `json:"height,omitempty" db:"height"`
	Age           int32          `json:"age,omitempty" db:"age"`
	Gender        int32          `json:"gender,omitempty" db:"gender"`
	Activity      int32          `json:"activity,omitempty" db:"activity"`
	Diet          int32          `json:"diet,omitempty" db:"diet"`
	DesiredWeight int32          `json:"desired_weight,omitempty" db:"desired_weight"`
	Eat           int32          `json:"eat,omitempty" db:"eat"`
	Image         sql.NullString `json:"image,omitempty" db:"image"`
	CreatedAt     time.Time      `json:"createdat" db:"createdat"`
	UpdatedAt     time.Time      `json:"updatedat" db:"updatedat"`
}

ParametersUser ...

type PostgresRepository

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

PostgresRepository has the implementation of the db methods.

func NewAuthPostgresRepository

func NewAuthPostgresRepository(db *sqlx.DB, logger hclog.Logger) *PostgresRepository

NewAuthPostgresRepository returns a new PostgresRepository instance

func (*PostgresRepository) Create

func (repo *PostgresRepository) Create(ctx context.Context, user *User) error

Create inserts the given user into the database

func (*PostgresRepository) DeleteVerificationData

func (repo *PostgresRepository) DeleteVerificationData(ctx context.Context, email string, verificationDataType VerificationDataType) error

DeleteVerificationData deletes a used verification data

func (*PostgresRepository) GetUserByEmail

func (repo *PostgresRepository) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail retrieves the user object having the given email, else returns error

func (*PostgresRepository) GetUserByID

func (repo *PostgresRepository) GetUserByID(ctx context.Context, userID string) (*User, error)

GetUserByID retrieves the user object having the given ID, else returns error

func (*PostgresRepository) GetVerificationData

func (repo *PostgresRepository) GetVerificationData(ctx context.Context, email string, verificationDataType VerificationDataType) (*VerificationData, error)

GetVerificationData retrieves the stored verification code.

func (*PostgresRepository) StoreVerificationData

func (repo *PostgresRepository) StoreVerificationData(ctx context.Context, verificationData *VerificationData) error

StoreVerificationData adds a mail verification data to db

func (*PostgresRepository) UpdatePassword

func (repo *PostgresRepository) UpdatePassword(ctx context.Context, userID string, password string, tokenHash string) error

UpdatePassword updates the user password

func (*PostgresRepository) UpdateUserVerificationStatus

func (repo *PostgresRepository) UpdateUserVerificationStatus(ctx context.Context, email string, status bool) error

UpdateUserVerificationStatus updates user verification status to true

func (*PostgresRepository) UpdateUsername

func (repo *PostgresRepository) UpdateUsername(ctx context.Context, user *User) error

UpdateUsername updates the username of the given user

type Trening

type Trening struct {
	UID       string        `json:"uid" db:"uid"`
	UserID    string        `json:"user_id,omitempty" db:"user_id"`
	Name      string        `json:"name,omitempty"  db:"name"`
	Exercises ExerciseSlice `json:"exercises,omitempty"  db:"exercises"`
	Interval  time.Duration `json:"interval,omitempty"  db:"interval"`
	Type      int           `json:"type,omitempty" db:"type"`
	Status    int           `json:"status,omitempty" db:"status"`
	Date      time.Time     `json:"date" db:"date"`
	CreatedAt time.Time     `json:"createdat" db:"createdat"`
	UpdatedAt time.Time     `json:"updatedat" db:"updatedat"`
}

type TreningRepository

type TreningRepository interface {
	GetUserByID(ctx context.Context, userID string) (*User, error)
	CreateUserParams(ctx context.Context, userParams *ParametersUser) error
	GetUserParamsByID(ctx context.Context, userID string) (*ParametersUser, error)
	UpdateUserParams(ctx context.Context, userParams *ParametersUser) error
	UpdateUserImage(ctx context.Context, userParams *ParametersUser) error
	CreateExercise(ctx context.Context, exercise *Exercise) error
	ListExercise(ctx context.Context, userID string) (res []Exercise, err error)
	CreateTrening(ctx context.Context, trening *Trening) error
	ListTrening(ctx context.Context, userID string, status int) (res []Trening, err error)
	UpdateTreningStatus(ctx context.Context, trening *Trening) error
	DetailTrening(ctx context.Context, userID string, uid string) (res Trening, err error)
	UpdateTreningExercises(ctx context.Context, trening *Trening) error
}

TreningRepository ...

func NewTreningPostgresRepository

func NewTreningPostgresRepository(db *sqlx.DB, logger hclog.Logger) TreningRepository

NewTreningPostgresRepository returns a new TreningPostgresRepository instance

type User

type User struct {
	ID         string    `json:"id" sql:"id"`
	Email      string    `json:"email" validate:"required" sql:"email"`
	Password   string    `json:"password" validate:"required" sql:"password"`
	Username   string    `json:"username" sql:"username"`
	TokenHash  string    `json:"tokenhash" sql:"tokenhash"`
	IsVerified bool      `json:"isverified" sql:"isverified"`
	CreatedAt  time.Time `json:"createdat" sql:"createdat"`
	UpdatedAt  time.Time `json:"updatedat" sql:"updatedat"`
}

User is the data type for user object

type Validation

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

Validation is the type for validator

func NewValidation

func NewValidation() *Validation

NewValidation returns a Validator instance

func (*Validation) Validate

func (v *Validation) Validate(i interface{}) ValidationErrors

Validate method validates the given struct based on the validate tags and returns validation error if any

type ValidationError

type ValidationError struct {
	validator.FieldError
}

ValidationError wraps the validator FieldError so we do not expose this to outside code

func (ValidationError) Error

func (v ValidationError) Error() string

Error provides the string format of the validation error

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a wrapper for list of ValidationError

func (ValidationErrors) Errors

func (v ValidationErrors) Errors() []string

Errors convert the ValidationErrors slice into string slice

type VerificationData

type VerificationData struct {
	Email     string               `json:"email" validate:"required" sql:"email"`
	Code      string               `json:"code" validate:"required" sql:"code"`
	ExpiresAt time.Time            `json:"expiresat" sql:"expiresat"`
	Type      VerificationDataType `json:"type" sql:"type"`
}

VerificationData represents the type for the data stored for verification.

type VerificationDataType

type VerificationDataType int

VerificationDataType ...

const (
	MailConfirmation VerificationDataType = iota + 1
	PassReset
)

Jump to

Keyboard shortcuts

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