Documentation ¶
Overview ¶
Package models represents the objects and services that can modify them. It does not provide implementations for those services so that they can be made database independent.
TODO I feel like the difference between a service and a store is not all that clear.
TODO I'm not really convinced this is the best way to structure our data
Index ¶
Constants ¶
const ( DecisionAwaiting = iota DecisionRejected DecisionWaitlist DecisionAccepted )
const ( RoleHacker = iota RoleSponsor RoleExec )
const RSVPExpiryTime = 3 * 24 * time.Hour
Variables ¶
var ( ErrAnnouncementMessageEmpty = &ModelError{"Announcement message is empty.", flash.Error} ErrAnnouncementIDEmpty = &ModelError{"Announcement ID is empty.", flash.Error} ErrNoAnnouncements = &ModelError{"No announcements in database.", flash.Info} ErrAnnouncementNotFound = &ModelError{"Announcement not found.", flash.Info} )
Authentication errors
var ( ErrMissingSchool = &ModelError{"Please enter your school's name.", flash.Info} ErrMissingMajor = &ModelError{"Please enter your major.", flash.Info} ErrMissingGraduationYear = &ModelError{"Please enter your graduation year.", flash.Info} ErrMissingGender = &ModelError{"Please enter your gender.", flash.Info} ErrMissingGithub = &ModelError{"Please enter your GitHub username.", flash.Info} ErrMissingPhone = &ModelError{"Please enter your phone number.", flash.Info} ErrMissingWhyBM = &ModelError{"Please enter why you want to come to BoilerMake.", flash.Info} ErrMissingLocation = &ModelError{"Please enter your Location.", flash.Info} ErrMissingOtherSchool = &ModelError{"Please enter your school's name.", flash.Info} ErrMissingOtherMajor = &ModelError{"Please enter your major.", flash.Info} ErrMissingTACAgree = &ModelError{"Please agree to the terms and conditions.", flash.Info} ErrMissingFirstName = &ModelError{"Please enter your first name.", flash.Info} ErrMissingLastName = &ModelError{"Please enter your last name.", flash.Info} // Validation errors when form paring ErrMissingResume = &ModelError{"Please upload a resume.", flash.Info} ErrResumeTooLarge = &ModelError{"Resume upload is too large.", flash.Info} // Raffle errors ErrRaffleEmpty = &ModelError{"Please enter a raffle.", flash.Info} ErrInvalidRaffle = &ModelError{"That raffle code doesn't exist.", flash.Info} ErrTime = &ModelError{"This raffle has expired.", flash.Info} ErrRaffleClaimed = &ModelError{"You have already claimed this raffle.", flash.Info} // Invalid raffle access ErrRaffleAccessDenied = &ModelError{"Unfortunately, our raffle is for BM VIII participants only. We hope to see you next year!", flash.Info} )
Validation errors
var ( ErrRaffleCodeEmpty = &ModelError{"Raffle code is empty", flash.Error} ErrStartTimeEmpty = &ModelError{"Start Time is missing", flash.Error} ErrInvalidStartTime = &ModelError{"Incorrect format for start time", flash.Error} ErrEndTimeEmpty = &ModelError{"End Time is missing", flash.Error} ErrInvalidEndTime = &ModelError{"Incorrect format for end time", flash.Error} ErrPointsEmpty = &ModelError{"Points is missing", flash.Error} ErrInvalidPoints = &ModelError{"Incorrect format for points", flash.Error} ErrDuplicateRaffle = &ModelError{"This raffle code already exists", flash.Error} ErrInvalidPointsToAdd = &ModelError{"Incorrect format for points to add", flash.Error} )
Raffle errors
var ( ErrMissingShirtSize = &ModelError{"Please enter your shirt size.", flash.Info} ErrExpired = &ModelError{"Your RSVP has expired. Contact team@boilermake.org if you think this was in error.", flash.Error} )
var ( ErrUserNotFound = &ModelError{"User not found.", flash.Info} ErrEmailInUse = &ModelError{"Email is already in use.", flash.Info} ErrRequiredField = &ModelError{"Required field is missing.", flash.Info} ErrIncorrectLogin = &ModelError{"Email or password is incorrect.", flash.Info} ErrNotLoggedIn = &ModelError{"Please log in or create an account first.", flash.Info} ErrAlreadyLoggedIn = &ModelError{"You're already logged in.", flash.Info} ErrInvalidConfirmationCode = &ModelError{"Email confirmation code no longer valid.", flash.Info} )
Authentication errors
var ( ErrEmptyEmail = &ModelError{"Email is empty", flash.Info} ErrInvalidEmail = &ModelError{"Email is invalid", flash.Info} ErrEmailNotFound = &ModelError{"We don't recognize that email.", flash.Info} ErrEmptyPassword = &ModelError{"Password is empty", flash.Info} ErrEmptyPasswordConfirm = &ModelError{"Password confirmation is empty", flash.Info} ErrEmptyFirstName = &ModelError{"First name is empty", flash.Info} ErrEmptyLastName = &ModelError{"Last name is empty", flash.Info} ErrPasswordConfirm = &ModelError{"Password and confirmation password do not match", flash.Info} ErrPasswordTooShort = &ModelError{"Password must be at least 3 characters", flash.Info} )
Validation errors
var ( ErrInvalidToken = &ModelError{"Password reset token is invalid", flash.Info} ErrExpiredToken = &ModelError{"Password reset token has expired", flash.Info} )
Password Reset errors
Functions ¶
This section is empty.
Types ¶
type Announcement ¶
type Announcement struct { ID int `json:"id"` Message string `json:"message"` CreatedAt time.Time `json:"createdAt"` }
An Announcement is an announcement stored in the database.
type AnnouncementService ¶
type AnnouncementService interface { Create(message string) error GetByID(id int) (*Announcement, error) GetCurrent() (*Announcement, error) DeleteByID(id int) error GetAllAnnouncements() ([]*Announcement, error) }
An AnnouncementService defines an interface between the announcement model and the db representation.
type Application ¶
type Application struct { ID int Decision int EmailedDecision bool UserID int RSVP bool AcceptedAt time.Time CheckedInAt time.Time School string OtherSchool string Major string OtherMajor string GraduationYear string FirstName string LastName string ResumeFile string Resume *multipart.FileHeader // Stored in S3, not db Phone string Gender string Github string Location string IsFirstHackathon bool WhyBM string ProjIdea string Is18OrOlder bool MLHCodeOfConduct bool MLHContestAndPrivacy bool CheckedInStatus bool Points int }
An Application is an application. What do you want from me?
func (*Application) FromFormData ¶
func (a *Application) FromFormData(r *http.Request) error
FromFormData converts an application from a request's FormData to a models.Application struct.
func (*Application) Validate ¶
func (a *Application) Validate() error
Validate checks if an Application has all the necessary fields. Validation of resume uploads happens in application_service.go.
type ApplicationService ¶
type ApplicationService interface { CreateOrUpdate(a *Application) error GetByUserID(uid int) (*Application, error) GetApplicationCount() int CheckIn(a *Application) error AddPointsToUser(uid int, points int) error }
An ApplicationService defines an interface between the Application struct (AKA the model) and its representation in our database. Abstracting it to an interface makes it database independent, which helps with testing.
type EmailModel ¶
type EmailModel struct {
Email string `json:"email"`
}
EmailModel struct for password reset emails
type ModelError ¶
func (ModelError) Error ¶
func (e ModelError) Error() string
func (ModelError) GetType ¶
func (e ModelError) GetType() int
type PasswordResetPayload ¶
type PasswordResetPayload struct { UserToken string `json:"token"` NewPassword string `json:"newPassword"` }
PasswordResetPayload struct for resetting passwords
type RSVP ¶
type RSVP struct { ID int UserID int WillAttend bool OnCampus bool ShirtSize string StreetAddr string City string State string Country string ZipCode string }
func (*RSVP) FromFormData ¶
FromFormData converts an RSVP from a requests's FormData to a models.RSVP struct.
type RSVPService ¶
An RSVPService defines an interface between the RSVP struct and its representation in our database.
type Raffle ¶
type Raffle struct { Code string `json:"string"` // parse as string and convert to int in db StartTime string `json:"startTime"` EndTime string `json:"endTime"` Points string `json:"points"` }
A Raffle is a raffle stored in the raffles table
func (*Raffle) FromFormData ¶
FromFormData builds raffle struct
type RaffleService ¶
type RaffleService interface { Create(ra *Raffle) error GetById(id string) (*Raffle, error) ClaimRaffle(userId int, raffleId string) error }
A RaffleService defines interface between the rsvp model and database representation of the raffles table
type User ¶
type User struct { ID int `json:"id"` // NOT NULL Role int `json:"role"` // NOT NULL Email string `json:"email"` // NOT NULL // Password and PasswordConfirm should only ever be in memory, never in the db Password string `json:"password"` PasswordConfirm string `json:"passwordConfirm"` PasswordHash string `json:"-"` // NOT NULL IsActive bool `json:"isActive"` ConfirmationCode string `json:"confirmationCode"` }
A User is an account stored in the database.
func (*User) CheckPassword ¶
CheckPassword compares a User's hashed password to a string.
func (*User) FromFormData ¶
FromFormData converts a user from a request's FormData to a models.User struct.
func (*User) HashPassword ¶
HashPassword hashes a User's password and sets its PasswordHash field. It also empties its Password and PasswordConfirm fields.
func (*User) SetSession ¶
SetSession sets all the session values for a user
type UserService ¶
type UserService interface { Signup(u *User) (int, string, error) Login(u *User) error GetByID(id int) (*User, error) GetByEmail(email string) (*User, error) GetByCode(code string) (*User, error) Update(u *User) error GetPasswordReset(email string) (string, error) ResetPassword(token string, newPassword string) error GetUserCount() int }
A UserService defines an interface between the user struct (AKA the model) and its representation in our database. Abstracting it to an interface makes it database independent, which helps with testing.