user

package
v0.0.0-...-bcfd2cf Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService(r *postgres.Pg) *service

NewService instantiates a new Service layer for customer

func Routes

func Routes(g *echo.Group, s Service)

Routes mounts user routes on the main group

Types

type Model

type Model struct {
	gorm.Model
	ID        uuid.UUID `json:"id" gorm:"primarykey;index;unique"`
	Email     string    `json:"email" validate:"required,email" gorm:"index"`
	Username  string    `json:"username" validate:"required" gorm:"index"`
	Password  string    `json:"password" validate:"required,min=10"`
	FirstName string    `json:"first_name" validate:"required,min=2"`
	LastName  string    `json:"last_name" validate:"required,min=2"`

	LastLogin time.Time `json:"last_login" validate:""`

	IsActive  bool           `json:"is_active,omitempty" gorm:"default:false"`
	Lang      string         `json:"lang,omitempty" gorm:"default:'en'"`
	IsBlocked bool           `json:"is_blocked" gorm:"default:false"`
	APIKeys   pq.StringArray `json:"api_keys,omitempty" gorm:"type:varchar(255)[]"`

	Preferences preferences.Model `gorm:"constraint:OnDelete:CASCADE;foreignKey:UserID"`
	Analysis    []analysis.Model  `gorm:"constraint:OnDelete:CASCADE;foreignKey:UserID"`

} //@name User

Model user struct with validation

func (*Model) BeforeCreate

func (m *Model) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate encrypt the password before creating

func (*Model) TableName

func (m *Model) TableName() string

TableName defines default table name

type Service

type Service interface {
	GetUser(ID string) (user *Model, err error)
	GetUserByEmail(email string) (user *Model, err error)
	CreateUser(user *Model) (err error)
	NewLogin(ID string) (time.Time, error)
	NewAPIKey(ID, key string) (err error)
}

Service interface exports available methods for user service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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