Documentation ¶
Index ¶
- Constants
- Variables
- func AllWhitespace(s string) bool
- func Close()
- func DayUpdate(d *Day) error
- func DeleteDay(did DayID) error
- func DeleteDiscussion(did DiscussionID) error
- func DeleteLocation(lid LocationID) error
- func DeleteUser(userid UserID) error
- func DiscussionIterate(f func(*DiscussionFull) error) error
- func DiscussionIterateUser(userid UserID, f func(*DiscussionFull) error) (err error)
- func DiscussionSetPossibleSlots(discussionid DiscussionID, pslots []SlotID) error
- func DiscussionSetPublic(discussionid DiscussionID, public bool) error
- func DiscussionUpdate(disc *Discussion) error
- func IsEmailAddress(s string) bool
- func IsValidationError(err error) bool
- func Load(opt EventOptions) error
- func LocationUpdate(l *Location) error
- func MakePossibleSlots(len int) []bool
- func MakeSchedule(opt SearchOptions) error
- func NewDiscussion(disc *Discussion) error
- func SchedLastUpdate() string
- func TestGenerateInterest()
- func TestPopulate()
- func TimetableSet(tt *Timetable) error
- func TimetableSetLockedSlots(pslots []SlotID) error
- func UserIterate(f func(u *User) error) error
- func UserUpdate(userNext, modifier *User, currentPassword, newPassword string) error
- type Day
- type DayID
- type Discussion
- type DiscussionFull
- type DiscussionID
- type DisplaySlot
- type EventOptions
- type EventStore
- type Location
- type LocationID
- type SchedState
- type SearchAlgo
- type SearchOptions
- type Slot
- type SlotID
- type TZLocation
- type Time
- type Timetable
- type TimetableDay
- type TimetableDiscussion
- type TimetableSlot
- type User
- func (u *User) CheckPassword(password string) bool
- func (user *User) GetInterest(disc *Discussion) (int, error)
- func (user *User) GetLocationTZ() (TZLocation, error)
- func (u *User) MayEditDiscussion(d *Discussion) bool
- func (u *User) MayEditUser(tgt *User) bool
- func (user *User) SetInterest(disc *Discussion, interest int) error
- func (user *User) SetVerified(isVerified bool) error
- type UserID
- type ValidationError
Constants ¶
const ( DbFilename = "data/event.sqlite" AdminUsername = "admin" )
const ( SearchHeuristicOnly = SearchAlgo("heuristic") //SearchGenetic = SearchAlgo("genetic") SearchRandom = SearchAlgo("random") )
const ( SchedStateCurrent = SchedState(iota) SchedStateModified SchedStateRunning )
const ( TestUsers = 8 TestDisc = 6 TestSlots = 4 )
const (
InterestMax = 100
)
Variables ¶
var ( ErrInternal = ValidationError(errors.New("Internal server error")) ErrCredentialsIncorrect = ValidationError(errors.New("We couldn’t find a user with the supplied username and password combination")) ErrUserNotFound = errors.New("UserID not found") ErrDiscussionNotFound = errors.New("DiscussionID not found") ErrLocationNotFound = errors.New("LocationID not found") ErrDayNotFound = errors.New("DayID not found") ErrUserOrDiscussionNotFound = errors.New("UserID or DiscussionID not found") )
Functions ¶
func AllWhitespace ¶
func DeleteDiscussion ¶
func DeleteDiscussion(did DiscussionID) error
func DeleteUser ¶
func DiscussionIterate ¶
func DiscussionIterate(f func(*DiscussionFull) error) error
func DiscussionIterateUser ¶
func DiscussionIterateUser(userid UserID, f func(*DiscussionFull) error) (err error)
FIXME: This will simply do nothing if the userid doesn't exist. It would be nice for the caller to distinguish between "User does not exist" and "User has no discussions".
func DiscussionSetPossibleSlots ¶
func DiscussionSetPossibleSlots(discussionid DiscussionID, pslots []SlotID) error
func DiscussionSetPublic ¶
func DiscussionSetPublic(discussionid DiscussionID, public bool) error
Sets the given discussion ID to public or private.
If public is true, it copies the title and description into the "approved" title and description, so that it will be visible even after being modified.
If public is false, it hides the discussion entirely, by both setting 'IsPublic' to false, but also clearing the approved title and description.
func DiscussionUpdate ¶
func DiscussionUpdate(disc *Discussion) error
Updates discussion's Title, Description, and Owner.
If the owner (or the new owner, if that's being changed) is verifed, then IsPublic will be set to 'true', and ApprovedTitle and ApprovedDescription will be set from Title and Description as well.
If the owner (or new owner) is not verified, then IsPublic will be set to false, and only Title and Description will be modified.
func IsEmailAddress ¶
func IsValidationError ¶
func Load ¶
func Load(opt EventOptions) error
func MakePossibleSlots ¶
func MakeSchedule ¶
func MakeSchedule(opt SearchOptions) error
func NewDiscussion ¶
func NewDiscussion(disc *Discussion) error
Restrictions: - Can't already have too many discussions - Title can't be empty - Description can't be empty - Title unique (enforced by SQL)
func SchedLastUpdate ¶
func SchedLastUpdate() string
func TestGenerateInterest ¶
func TestGenerateInterest()
Try to emulate "realistic" interest, where people will be like one another. - Create four "unique" people at the beginning, with random interests - Afterwards, choose someone randomly to emulate 90% of the time. - When emulating somebody, choose like them 7/8 times
func TestPopulate ¶
func TestPopulate()
func TimetableSet ¶
Set the timetable. This will compare the timetable to the one currently in the database, creating, deleting, or updating days and slots as necessary.
If a <day, slot> combination disappears, the schedule entries for that day will be deleted; otherwise they will remain. If a <day, slot> combination which is locked would be deleted, an error will be returned instead.
Dealing with time zones and so on is the concern of the caller.
func TimetableSetLockedSlots ¶
func UserIterate ¶
Iterate over all users, calling f(u) for each user.
func UserUpdate ¶
UserUpdate will update "user-facing" data associated with the user. This includes RealName, Email, Company, Description, and Location. It can also inlude the password *via* the new/currentPassword fields (not the HashedPassword field).
UserUpdate will *not* update Username, IsAdmin or IsVerified. IsVerified should be updated with SetVerified instead.
If newPassword is "", HashedPassword will not be changed. If newPassword is non-null, currentPassword will be checked against modifier.HashedPassword.
Types ¶
type Discussion ¶
type Discussion struct { DiscussionID DiscussionID Owner UserID Title string Description string ApprovedTitle string ApprovedDescription string // Is this discussion publicly visible? // If true, 'Title' and 'Description' should be shown to everyone. // If false: // admin and owner should see 'Title' and 'Description' // Everyone else should either see 'Approved*', or nothing at all (if nothing has been approved) IsPublic bool }
func (*Discussion) GetMaxScore ¶
func (d *Discussion) GetMaxScore() (int, error)
GetMaxScore returns the maximum possible score a discussion could have if everyone attended; that is, the sum of all the interests expressed.
func (*Discussion) GetURL ¶
func (d *Discussion) GetURL() string
func (*Discussion) Location ¶
func (d *Discussion) Location() Location
func (*Discussion) Slot ¶
func (d *Discussion) Slot() (IsFinal bool, Time string)
type DiscussionFull ¶
type DiscussionFull struct { Discussion OwnerInfo User Location Location Time Time IsFinal bool PossibleSlots []DisplaySlot }
func DiscussionFindByIdFull ¶
func DiscussionFindByIdFull(discussionid DiscussionID) (*DiscussionFull, error)
type DiscussionID ¶
type DiscussionID string
type DisplaySlot ¶
DisplaySlot used both for discussion possible slots, as well as for schedule locked slots.
func DiscussionGetPossibleSlots ¶
func DiscussionGetPossibleSlots(did DiscussionID) ([]DisplaySlot, error)
func TimetableGetLockedSlots ¶
func TimetableGetLockedSlots() []DisplaySlot
type EventOptions ¶
type EventStore ¶
func (*EventStore) Load ¶
func (store *EventStore) Load(opt EventOptions) error
type Location ¶
type Location struct { LocationID LocationID LocationName string LocationURL string IsPlace bool Capacity int }
func LocationGetAll ¶
type LocationID ¶
type LocationID int
func NewLocation ¶
func NewLocation(l *Location) (LocationID, error)
type SearchAlgo ¶
type SearchAlgo string
type SearchOptions ¶
type TZLocation ¶
Location is database-scannable wrapper around time.Location
func LoadLocation ¶
func LoadLocation(name string) (TZLocation, error)
This is a wrapper around time.LoadLocation which returns a database-scannable Location
func (*TZLocation) Scan ¶
func (l *TZLocation) Scan(src interface{}) error
type Time ¶
func ParseInLocation ¶
func ParseInLocation(layout, value string, loc TZLocation) (Time, error)
type Timetable ¶
type Timetable struct {
Days []TimetableDay
}
Placement: Specific days, times, rooms
func GetTimetable ¶
func GetTimetable(tfmt string, tzl *TZLocation) (tt Timetable, err error)
GetTimetable will get a structured form of the entire timetable. If tfmt is non-empty, TimetableStot.TimeDisplay will be formatted with the specified time. If tzl is non-nil, the location will be converted to that location before displaying.
type TimetableDay ¶
type TimetableDay struct { DayName string IsFinal bool Slots []TimetableSlot }
type TimetableDiscussion ¶
type TimetableSlot ¶
type TimetableSlot struct { Time Time // NB: Must duplicate this so that sqlx's StructScan doesn't get confused TimeDisplay string IsBreak bool // Which room will each discussion be in? // (Separate because placement and scheduling are separate steps) Discussions []TimetableDiscussion }
type User ¶
type User struct { UserID UserID HashedPassword string Username string IsAdmin bool IsVerified bool // Has entered the verification code Location TZLocation RealName string Email string Company string Description string }
func UserFindByUsername ¶
Return nil for user not present
func UserFindRandom ¶
func UserGetAll ¶
func (*User) CheckPassword ¶
func (*User) GetInterest ¶
func (user *User) GetInterest(disc *Discussion) (int, error)
func (*User) GetLocationTZ ¶
func (user *User) GetLocationTZ() (TZLocation, error)
func (*User) MayEditDiscussion ¶
func (u *User) MayEditDiscussion(d *Discussion) bool
func (*User) MayEditUser ¶
func (*User) SetInterest ¶
func (user *User) SetInterest(disc *Discussion, interest int) error
func (*User) SetVerified ¶
type ValidationError ¶
type ValidationError error