models

package
v0.0.0-...-786acf3 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrOrgRequired    modelError = "models: org is required"
	ErrUserIDRequired modelError = "models: id is required"
)

Variables

View Source
var (
	ErrNotFound          modelError = "models: resource not found"
	ErrIDInvalid         modelError = "models: ID provided was invalid"
	ErrPasswordIncorrect modelError = "models: incorrect " + "password provided"
	ErrPasswordTooShort  modelError = "models: password must " + "be at least 8 characters long"
	ErrPasswordRequired  modelError = "models: password is required"
	ErrEmailRequired     modelError = "models: email address is " + "required"
	ErrEmailInvalid      modelError = "models: email address is " + "not valid"
	ErrEmailTaken        modelError = "models: email address is " + "already taken"
	ErrRememberRequired  modelError = "models: remember token " + "is required"
	ErrRememberTooShort  modelError = "models: remember token " + "must be at least 32 bytes"
)

Functions

This section is empty.

Types

type Integration

type Integration struct {
	gorm.Model
	UserID uint   `gorm:"not_null;index"`
	Org    string `gorm:"not_null"`
	Token  string `gorm:"not_null"`
}

Integration represents the integration a user can upload

type IntegrationDB

type IntegrationDB interface {
	ByID(id uint) (*Integration, error)
	ByUserID(userID uint) ([]Integration, error)
	Create(integration *Integration) error
	Update(integration *Integration) error
	Delete(id uint) error
}

IntegrationDB is for CRUD operations involving the table

type IntegrationService

type IntegrationService interface {
	IntegrationDB
}

IntegrationService is for interacting with the Integration table

func NewIntegrationService

func NewIntegrationService(db *gorm.DB) IntegrationService

NewIntegrationService returns a IntegrationService for use with the Integration table object(s)

type Services

type Services struct {
	Integration IntegrationService
	User        UserService
	// contains filtered or unexported fields
}

Services contains all the available services offered by the web application

func NewServices

func NewServices(cfgs ...ServicesConfig) (*Services, error)

NewServices now will accept a list of config functions to run. Each function will accept a pointer to the current Services object as its only argument and will edit that object inline and return an error if there is one. Once we have run all configs we will return the Services object.

func (*Services) AutoMigrate

func (s *Services) AutoMigrate() error

AutoMigrate will attempt to automatically migrate all tables

func (*Services) Close

func (s *Services) Close() error

Close the database connection

func (*Services) DestructiveReset

func (s *Services) DestructiveReset() error

DestructiveReset drops all tables and rebuilds them

type ServicesConfig

type ServicesConfig func(*Services) error

ServicesConfig is really just a function, but I find using types like this are easier to read in my source code.

func WithGorm

func WithGorm(dialect, connectionInfo string) ServicesConfig

func WithIntegration

func WithIntegration() ServicesConfig

func WithLogMode

func WithLogMode(mode bool) ServicesConfig

func WithUser

func WithUser(pepper, hmacKey string) ServicesConfig

type User

type User struct {
	gorm.Model
	UserName     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"`
	Limit        int    `gorm:"not null"`
}

User contains the data of what a user is

type UserDB

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

	// Methods for altering users
	Create(user *User) error
	Update(user *User) error
	Delete(id uint) error
}

UserDB is for interacting with the users database.

type UserService

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

UserService is for working with the user model

func NewUserService

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

NewUserService returns a connection to the DB

Jump to

Keyboard shortcuts

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