models

package
v0.0.0-...-900bee6 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNotFound                 = privateError("resource not found")
	ErrIDInvalid                = privateError("ID has an invalid value")
	ErrUserPasswordHashRequired = privateError("password hash is required")
	ErrUserRememberHashRequired = privateError("remember hash is required")
	ErrUserRememberTooShort     = privateError("remember token must be at least 32 bytes long")
	ErrRecipeUserIDRequired     = privateError("user ID is required")
	ErrUserPasswordRequired     = publicError("password is required")
	ErrUserEmailRequired        = publicError("email is required")
	ErrUserNameRequired         = publicError("full name is required")
	ErrUserPasswordTooShort     = publicError("password must be at least 8 characters long")
	ErrUserEmailInvalid         = publicError("email provided has an invalid format")
	ErrUserEmailTaken           = publicError("email is already taken")
	ErrUserCredentialsInvalid   = publicError("email or password provided is invalid")
	ErrRecipeTitleRequired      = publicError("recipe title is required")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	RecipeID 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(uint, io.Reader, string) error
	ByRecipeID(uint) ([]Image, error)
	Delete(*Image) error
}

func NewImageService

func NewImageService() ImageService

type Recipe

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

func (*Recipe) ImagesSplitN

func (r *Recipe) ImagesSplitN(n int) [][]Image

type RecipeDB

type RecipeDB interface {
	ByID(uint) (*Recipe, error)
	ByUserID(uint) ([]Recipe, error)
	Create(*Recipe) error
	Update(*Recipe) error
}

type RecipeService

type RecipeService interface {
	RecipeDB
}

func NewRecipesService

func NewRecipesService(db *gorm.DB) RecipeService

type Services

type Services struct {
	User   UserService
	Recipe RecipeService
	Image  ImageService
	// contains filtered or unexported fields
}

func NewServices

func NewServices(cfgs ...ServicesConfig) (*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 ServicesConfig

type ServicesConfig func(*Services) error

func WithGorm

func WithGorm(connInfo string) ServicesConfig

func WithImage

func WithImage() ServicesConfig

func WithLogMode

func WithLogMode(enabled bool) ServicesConfig

func WithRecipe

func WithRecipe() ServicesConfig

func WithUser

func WithUser(hmacKey, pepper string) ServicesConfig

type User

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

type UserDB

type UserDB interface {
	ByID(uint) (*User, error)
	ByEmail(string) (*User, error)
	ByRemember(string) (*User, error)
	Create(*User) error
	Update(*User) error
}

type UserService

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

func NewUserService

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

Jump to

Keyboard shortcuts

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