models

package
v0.0.0-...-c470439 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OAuthDropbox = "dropbox"
)

Variables

View Source
var (
	ErrNotFound modelError = "models: resource not found"
	ErrNilModel modelError = "models: given resource is nil"

	// User Errors
	ErrIDInvalid             modelError = "models: invalid id"
	ErrUserNotFound          modelError = "models: user not found"
	ErrPasswordWrong         modelError = "models: wrong password"
	ErrPasswordTooShort      modelError = "models: password too short. Must be at least 8 characters long"
	ErrPasswordRequired      modelError = "models: password is required"
	ErrEmailRequired         modelError = "models: email required"
	ErrEmailInvalid          modelError = "models: invalid email"
	ErrEmailTaken            modelError = "models: email is taken"
	ErrRememberTokenTooShort modelError = "models: remember token is too short"
	ErrRememberTokenRequired modelError = "models: remember token is required"
	ErrRememberTokenInvalid  modelError = "models: remember token is invalid"

	// Gallery Errors
	ErrUserIDRequired modelError = "models: user ID is required"
	ErrTitleRequired  modelError = "models: title is required"

	// OAuth Errors
	ErrOAuthServiceRequired modelError = "models: oauth service is required"
	ErrOAuthTokenRequired   modelError = "models: oauth token is required"
)

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)
	ByUserID(userID uint) ([]Gallery, error)
	Create(gallery *Gallery) error
	Update(gallery *Gallery) error
	Delete(id uint) 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 {
	ByGalleryID(galleryID uint) ([]Image, error)
	Create(galleryID uint, r io.Reader, filename string) error
	Delete(i *Image) error
}

func NewImageService

func NewImageService() ImageService

type OAuth

type OAuth struct {
	gorm.Model
	oauth2.Token
	UserID  uint   `gorm:"not null;unique_index:user_id_service"`
	Service string `gorm:"not null;unique_index:user_id_service"`
}

type OAuthDB

type OAuthDB interface {
	Find(userID uint, service string) (*OAuth, error)
	Create(oauth *OAuth) error
	Delete(id uint) error
}

type OAuthService

type OAuthService interface {
	OAuthDB
}

func NewOAuthService

func NewOAuthService(db *gorm.DB) OAuthService

type Services

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

func NewServices

func NewServices(cfgFuncs ...ServicesConfigFunc) (*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 ServicesConfigFunc

type ServicesConfigFunc func(*Services) error

func WithGalleryService

func WithGalleryService() ServicesConfigFunc

func WithGorm

func WithGorm(dialect, connectionInfo string) ServicesConfigFunc

func WithImageService

func WithImageService() ServicesConfigFunc

func WithLogMode

func WithLogMode(mode bool) ServicesConfigFunc

func WithOAuthService

func WithOAuthService() ServicesConfigFunc

func WithUserService

func WithUserService(pepper, hmacKey string) ServicesConfigFunc

type User

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

func (*User) GenerateToken

func (u *User) GenerateToken() error

type UserDB

type UserDB interface {
	ByID(id uint) (*User, error)
	ByEmail(email string) (*User, error)
	ByRememberToken(token string) (*User, error)

	Create(user *User) error
	Update(user *User) error
	Delete(id uint) error
}

type UserService

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

func NewUserService

func NewUserService(db *gorm.DB, pepper, hmacKey string) UserService

Jump to

Keyboard shortcuts

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