models

package
v0.0.0-...-3263382 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNotFound          modelError = "models: resource not found"
	ErrIDInvalid         modelError = "models: ID provided was invalid"
	ErrPasswordIncorrect modelError = "models: incorrect password provided"
	ErrEmailTaken        modelError = "models: email address is already taken"
	ErrPasswordRequired  modelError = "models: password is required"
	ErrRememberRequired  modelError = "models: remember token is required"
	ErrRememberTooShort  modelError = "models: remember token must be at least 32 bytes"
	ErrBadRequst         modelError = "models: bad request param"
)
View Source
const (
	ErrUserIDRequired modelError = "models: user ID is required"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Gallery struct {
	gorm.Model
	UserID uint    `gorm:"not null;index"`
	Title  string  `gorm:"not null"`
	Images []Image `gorm:"-"`
}

func (*Gallery) ImagesSplitN

func (g *Gallery) ImagesSplitN(n int) [][]Image

type GalleryDB

type GalleryDB interface {
	ByID(id uint) (*Gallery, error)
	Create(gallery *Gallery) error
	Update(gallery *Gallery) error
	Delete(id uint) error
	ByUserID(userID uint) ([]Gallery, error)
}

type GalleryService

type GalleryService interface {
	GalleryDB
}

func NewGalleryService

func NewGalleryService(db *gorm.DB) GalleryService

type Image

type Image struct {
	GalleryID uint
	Filename  string
}

func (*Image) Path

func (i *Image) Path() string

func (*Image) RelativePath

func (i *Image) RelativePath() string

type ImageService

type ImageService interface {
	Create(galleryID uint, r io.Reader, filename string) error
	ByGalleryID(galleryID uint) ([]Image, error)
	Delete(image *Image) error
}

func NewImageService

func NewImageService() ImageService

type Services

type Services struct {
	Gallery GalleryService
	User    UserService
	Image   ImageService
	// contains filtered or unexported fields
}

func NewServices

func NewServices() (*Services, error)

func (*Services) AutoMigrate

func (s *Services) AutoMigrate() error

func (*Services) Close

func (s *Services) Close() error

func (*Services) DestructiveReset

func (s *Services) DestructiveReset() error

type User

type User struct {
	gorm.Model
	Name         string
	Email        string `gorm:"not null;unique_index"`
	Password     string `gorm:"-"`
	PasswordHash string `gorm:"not null"`
	Remember     string `gorm:"-"`
	RememberHash string `gorm:"not null;unique_index"`
}

type UserDB

type UserDB interface {
	ByID(id uint) (*User, error)
	ByEmail(email string) (*User, error)
	ByRemember(token string) (*User, error)
	Create(user *User) error
	Update(user *User) error
	Delete(id uint) error
}

type UserService

type UserService interface {
	UserDB
	Authenticate(email, password string) (*User, error)
}

func NewUserService

func NewUserService(db *gorm.DB) UserService

Jump to

Keyboard shortcuts

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