Documentation
¶
Index ¶
Constants ¶
const ( 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" ErrTokenInvalid modelError = "models: token provided is not valid" )
const (
ErrJobIDRequired modelError = "models: job ID is required"
)
const (
ErrNameRequired modelError = "models: name is required"
)
const (
ErrUserIDRequired modelError = "models: user ID is required"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assignment ¶
type Assignment struct { gorm.Model UserID uint `gorm:"not_null"` Job Job `gorm:"not_null"` WeekStart *time.Time }
Assignment represents the assignments table in our DB and is when a user is assigned to a assignment.
type AssignmentDB ¶
type AssignmentDB interface { ByID(id uint) (*Assignment, error) ByUserID(userID uint) ([]Assignment, error) List() ([]Assignment, error) Create(assignment *Assignment) error Update(assignment *Assignment) error Delete(id uint) error }
AssignmentDB is used to interact with the assignments database.
type AssignmentService ¶
type AssignmentService interface { AssignmentDB }
func NewAssignmentService ¶
func NewAssignmentService(db *gorm.DB) AssignmentService
type JobDB ¶
type JobDB interface { ByID(id uint) (*Job, error) List() ([]Job, error) Create(job *Job) error Update(job *Job) error Delete(id uint) error }
JobDB is used to interact with the jobs database.
type JobService ¶
type JobService interface { JobDB }
func NewJobService ¶
func NewJobService(db *gorm.DB) JobService
type MateDB ¶
type MateDB interface { ByID(id uint) (*Mate, error) List() ([]Mate, error) Create(mate *Mate) error Update(mate *Mate) error Delete(id uint) error }
MateDB is used to interact with the mates database.
type MateService ¶
type MateService interface { MateDB }
func NewMateService ¶
func NewMateService(db *gorm.DB) MateService
type Services ¶
type Services struct { Mate MateService Assignment AssignmentService Job JobService User UserService DB *gorm.DB }
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 ¶
AutoMigrate will attempt to automatically migrate all tables
func (*Services) DestructiveReset ¶
DestructiveReset drops all tables and rebuilds them
type ServicesConfig ¶
func WithAssignment ¶
func WithAssignment() ServicesConfig
WithAssignment will use the existing GORM DB connection of the Services object to build and set a AssignmentService.
func WithGorm ¶
func WithGorm(connectionInfo string) ServicesConfig
WithGorm will open a GORM connection with the provided info and attach it to the Services type if there aren't any errors.
func WithJob ¶
func WithJob() ServicesConfig
WithJob will use the existing GORM DB connection of the Services object to build and set a JobService.
func WithLogMode ¶
func WithLogMode(mode bool) ServicesConfig
WithLogMode will set the LogMode of the current GORM DB object associated with the Services type. It is assumed that the DB object will already exist and be initialized properly, so you will want to call something like WithGorm before this config function.
func WithMate ¶
func WithMate() ServicesConfig
func WithUser ¶
func WithUser(pepper, hmacKey string) ServicesConfig
WithUser will use the existing GORM DB connection of the Services object along with the provided pepper and hmacKey to build and set a UserService.
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) // Methods for altering users Create(user *User) error Update(user *User) error Delete(id uint) error }
UserDB is used to interact with the users database.
type UserService ¶
type UserService interface { Authenticate(email, password string) (*User, error) // InitiateReset will complete all the model-related tasks // to start the password reset process for the user with // the provided email address. Once completed, it will // return the token, or an error if there was one. InitiateReset(email string) (string, error) // CompleteReset will complete all the model-related tasks // to complete the password reset process for the user that // the token matches, including updating that user's pw. // If the token has expired, or if it is invalid for any // other reason the ErrTokenInvalid error will be returned. CompleteReset(token, newPw 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, pepper, hmacKey string) UserService