data

package
v0.0.0-...-c937191 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeActivation     = "activation"
	ScopeAuthentication = "authentication"
)

Variables

View Source
var AnonymousUser = &User{}
View Source
var ErrInvalidRuntimeFormat = errors.New("invalid runtime format")
View Source
var (
	ErrRecordNotFound = errors.New("record not found")
)

Functions

This section is empty.

Types

type Filters

type Filters struct {
	Page     int    `validate:"gt=0,max=10_000_000"`
	PageSize int    `validate:"gt=0,max=100"`
	Sort     string `validate:"oneof=id title year runtime -id -title -year -runtime"`
}

type Metadata

type Metadata struct {
	CurrentPage  int   `json:"current_page,omitempty"`
	PageSize     int   `json:"page_size,omitempty"`
	FirstPage    int   `json:"first_page,omitempty"`
	LastPage     int   `json:"last_page,omitempty"`
	TotalRecords int64 `json:"total_records,omitempty"`
}

type Models

type Models struct {
	Movies      MovieModel
	Users       UserModel
	Tokens      TokenModel
	Permissions PermissionModel
}

func NewModels

func NewModels(db *gorm.DB) Models

type Movie

type Movie struct {
	gorm.Model
	Title   string         `json:"title" gorm:"index:,type:gin,expression:to_tsvector('english'\\,title)"`
	Year    int32          `json:"year"`
	Runtime Runtime        `json:"runtime" gorm:"type:int"`
	Genres  pq.StringArray `json:"genres" gorm:"type:text[];index:,type:gin"`
	Version int32          `json:"version" gorm:"default:1"`
}

type MovieModel

type MovieModel struct {
	DB *gorm.DB
}

func (MovieModel) Delete

func (m MovieModel) Delete(id int64) error

Add a placeholder method for deleting a specific record from the movies table.

func (MovieModel) Get

func (m MovieModel) Get(id int64) (*Movie, error)

Add a placeholder method for fetching a specific record from the movies table.

func (MovieModel) GetAll

func (m MovieModel) GetAll(title string, genres []string, filters Filters) ([]*Movie, Metadata, error)

func (MovieModel) Insert

func (m MovieModel) Insert(movie *Movie) error

Add a placeholder method for inserting a new record in the movies table.

func (MovieModel) Update

func (m MovieModel) Update(movie *Movie) error

Add a placeholder method for updating a specific record in the movies table.

type Permission

type Permission struct {
	ID   uuid.UUID      `json:"id" gorm:"default:gen_random_uuid()"`
	Code pq.StringArray `json:"code" gorm:"type:text[]"`
}

func (Permission) Include

func (p Permission) Include(code string) bool

type PermissionModel

type PermissionModel struct {
	DB *gorm.DB
}

func (*PermissionModel) AddForUser

func (m *PermissionModel) AddForUser(userID uint, codes ...string) error

func (*PermissionModel) GetAllForUser

func (m *PermissionModel) GetAllForUser(userID uint) (*Permission, error)

type Runtime

type Runtime int32

func (Runtime) GormDataType

func (runtime Runtime) GormDataType() string

func (Runtime) MarshalJSON

func (r Runtime) MarshalJSON() ([]byte, error)

func (*Runtime) UnmarshalJSON

func (r *Runtime) UnmarshalJSON(jsonValue []byte) error

type Token

type Token struct {
	Hash      []byte    `json:"-" gorm:"primaryKey"`
	Plaintext string    `json:"token"`
	UserID    uint      `json:"-"`
	User      User      `json:"-"`
	Expiry    time.Time `json:"expiry"`
	Scope     string    `json:"-" gorm:"not null"`
}

func (*Token) Validate

func (t *Token) Validate() error

type TokenModel

type TokenModel struct {
	DB *gorm.DB
}

func (*TokenModel) DeleteAllForUser

func (m *TokenModel) DeleteAllForUser(scope string, userID uint) error

func (*TokenModel) Insert

func (m *TokenModel) Insert(token *Token) error

func (*TokenModel) New

func (m *TokenModel) New(userID uint, ttl time.Duration, scope string) (*Token, error)

type User

type User struct {
	gorm.Model
	UUID        uuid.UUID    `json:"uuid" gorm:"type:uuid"`
	Name        string       `json:"name" validate:"required"`
	Email       string       `json:"email" gorm:"unique" validate:"required,email"`
	Password    string       `json:"-" validate:"required,min=8,max=72"`
	Activated   bool         `json:"activated"`
	Permissions []Permission `json:"permissions" gorm:"many2many:users_permissions"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

func (*User) CheckPassword

func (u *User) CheckPassword() bool

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

func (*User) Validate

func (u *User) Validate() error

type UserModel

type UserModel struct {
	DB *gorm.DB
}

func (*UserModel) Delete

func (m *UserModel) Delete(id int64) error

func (*UserModel) GetAll

func (m *UserModel) GetAll() ([]User, error)

func (*UserModel) GetByEmail

func (m *UserModel) GetByEmail(email string) (*User, error)

func (*UserModel) GetForToken

func (m *UserModel) GetForToken(tokenScope, tokenPlaintext string) (*User, error)

func (*UserModel) Insert

func (m *UserModel) Insert(user *User) error

func (*UserModel) Update

func (m *UserModel) Update(user *User) error

Jump to

Keyboard shortcuts

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