models

package
v0.0.0-...-f20b317 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNotFound              modelError   = "models: resource not found"
	ErrIDInvalid             privateError = "models: ID provided was invalid"
	ErrPasswordIncorrect     modelError   = "models: incorrect password"
	ErrRememberTokenTooShort privateError = "models: remember token must be at least 32 bytes"
	ErrRememberRequired      privateError = "models: remember token required"
	ErrEmailRequired         modelError   = "Email address is required"
	ErrEmailInvalid          modelError   = "Email address is not valid"
	ErrEmailTaken            modelError   = "models: email address is already taken"
	ErrPasswordMinLength     modelError   = "Password must be 8 characters long"
	ErrPasswordRequired      modelError   = "Password is required"
	ErrUserIDRequired        privateError = "models: user does not have id"
	ErrTitleRequired         modelError   = "A title is required for your gallery"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	gorm.Model
	ID      uint   `gorm:"primaryKey"`
	UserId  uint   `gorm:"not_null;index"`
	Lon     string `gorm:"not null; unique"`
	Lat     string `gorm:"not null; unique"`
	Name    string `gorm:"not null"`
	IsSaved bool   `gorm:"not null"`
}

type LocationDB

type LocationDB interface {
	Create(location *Location) error
	Delete(id uint) error
	FindByLonAndLat(lon, lat float64) (Location, error)
	GetByUserId(userId uint) ([]Location, error)
}

type LocationService

type LocationService interface {
	LocationDB
}

func NewLocationService

func NewLocationService(db *gorm.DB) LocationService

type Services

type Services struct {
	User     UserService
	Location LocationService
	// contains filtered or unexported fields
}

func NewServices

func NewServices(connectionInfo string) *Services

func (*Services) AutoMigrate

func (s *Services) AutoMigrate() error

Will attempt to automigrate all database tables

type User

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

User model which stores user name, email address, password hash, and remember hash in the PSQL database.

type UserDB

type UserDB interface {
	// Methods for querying for single users
	ByID(id uint) (*User, error)
	ByEmail(email string) (*User, error)
	ByRemember(token string) (*User, error)

	// CRUD operations for user
	Create(user *User) error
	Update(user *User) error
	Delete(id uint) error
	GetAllUsers() ([]User, error)
}

UserDB is used to interact with the database. As a general rule, any error but ErrNotFound should result in a 500 error

type UserService

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

UserService is a set of methods used to manipulate and work with the user model

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