models

package
v0.0.0-...-a1b9644 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultResetDuration = 1 * time.Hour
)
View Source
const MinBytesPerToken = 32

Variables

View Source
var (
	ErrNotFound   = errors.New("no resource is found")
	ErrEmailTaken = errors.New("email address is already in use")
	ErrPwMismatch = errors.New("mismatching password")
)

Functions

func Migrate

func Migrate(db *sql.DB, dir string) error

func MigrateFS

func MigrateFS(db *sql.DB, migrations fs.FS, dir string) error

func Open

func Open(cfg PostgresCfg) (*sql.DB, error)

Types

type FileError

type FileError struct {
	Issue string
}

func (FileError) Error

func (f FileError) Error() string
type Gallery struct {
	ID     int
	UserID int
	Title  string
}

type GalleryService

type GalleryService struct {
	DB *sql.DB

	ImagesDir string
}

func (*GalleryService) ByID

func (g *GalleryService) ByID(ctx context.Context, id int) (*Gallery, error)

func (*GalleryService) ByUserID

func (g *GalleryService) ByUserID(ctx context.Context, userID int) ([]Gallery, error)

func (*GalleryService) Create

func (g *GalleryService) Create(ctx context.Context, title string, userID int) (*Gallery, error)

func (*GalleryService) CreateImage

func (g *GalleryService) CreateImage(galleryID int, filename string, content io.ReadSeeker) error

func (*GalleryService) Delete

func (g *GalleryService) Delete(ctx context.Context, id int) error

func (*GalleryService) DeleteImage

func (g *GalleryService) DeleteImage(galleryID int, filename string) error

func (*GalleryService) Image

func (g *GalleryService) Image(galleryID int, filename string) (Image, error)

func (*GalleryService) Images

func (g *GalleryService) Images(galleryID int) ([]Image, error)

func (*GalleryService) Update

func (g *GalleryService) Update(ctx context.Context, gallery *Gallery) error

type Image

type Image struct {
	GalleryID int
	Path      string
	Filename  string
}

type NewUser

type NewUser struct {
	Name            string
	Email           string
	Password        string
	ConfirmPassword string
}

type PasswordReset

type PasswordReset struct {
	ID        int
	UserID    int
	Token     string // set only when creating a new session
	TokenHash string
	ExpiresAt time.Time
}

type PasswordResetService

type PasswordResetService struct {
	DB            *sql.DB
	BytesPerToken int
	Duration      time.Duration
}

func (*PasswordResetService) Consume

func (p *PasswordResetService) Consume(ctx context.Context, token string) (*User, error)

func (*PasswordResetService) Create

func (p *PasswordResetService) Create(ctx context.Context, email string) (*PasswordReset, error)

type PostgresCfg

type PostgresCfg struct {
	Host     string
	Port     string
	User     string
	Password string
	Database string
	SSLMode  string
}

func (*PostgresCfg) String

func (c *PostgresCfg) String() string

type Session

type Session struct {
	ID        int
	UserID    int
	Token     string // set only when creating a new session
	TokenHash string
}

type SessionService

type SessionService struct {
	DB            *sql.DB
	BytesPerToken int
}

func (*SessionService) Create

func (s *SessionService) Create(ctx context.Context, userID int) (*Session, error)

func (*SessionService) Delete

func (s *SessionService) Delete(ctx context.Context, token string) error

func (*SessionService) User

func (s *SessionService) User(ctx context.Context, token string) (*User, error)

type User

type User struct {
	ID           int
	Name         string
	Email        string
	PasswordHash string
}

type UserService

type UserService struct {
	DB *sql.DB
}

func (*UserService) Authenticate

func (u *UserService) Authenticate(ctx context.Context, email, password string) (*User, error)

func (*UserService) Create

func (u *UserService) Create(ctx context.Context, newUser NewUser) (*User, error)

func (*UserService) UpdatePassword

func (u *UserService) UpdatePassword(ctx context.Context, userID int, password string) error

Jump to

Keyboard shortcuts

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