event

package
v0.0.0-...-3bd2f2d Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbFilename    = "data/event.sqlite"
	AdminUsername = "admin"
)
View Source
const (
	SearchHeuristicOnly = SearchAlgo("heuristic")
	//SearchGenetic       = SearchAlgo("genetic")
	SearchRandom = SearchAlgo("random")
)
View Source
const (
	SchedStateCurrent = SchedState(iota)
	SchedStateModified
	SchedStateRunning
)
View Source
const (
	TestUsers = 8
	TestDisc  = 6
	TestSlots = 4
)
View Source
const (
	InterestMax = 100
)

Variables

View Source
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 AllWhitespace(s string) bool

func Close

func Close()

func DayUpdate

func DayUpdate(d *Day) error

DayUpdate: Set d.DayID's fields

func DeleteDay

func DeleteDay(did DayID) error

DeleteDay

func DeleteDiscussion

func DeleteDiscussion(did DiscussionID) error

func DeleteLocation

func DeleteLocation(lid LocationID) error

DeleteLocation

func DeleteUser

func DeleteUser(userid UserID) error

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 IsEmailAddress(s string) bool

func IsValidationError

func IsValidationError(err error) bool

func Load

func Load(opt EventOptions) error

func LocationUpdate

func LocationUpdate(l *Location) error

LocationUpdate

func MakePossibleSlots

func MakePossibleSlots(len int) []bool

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

func TimetableSet(tt *Timetable) error

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 TimetableSetLockedSlots(pslots []SlotID) error

func UserIterate

func UserIterate(f func(u *User) error) error

Iterate over all users, calling f(u) for each user.

func UserUpdate

func UserUpdate(userNext, modifier *User, currentPassword, newPassword string) error

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 Day

type Day struct {
	DayID
	DayName string
}

func DayFindByID

func DayFindByID(did DayID) (*Day, error)

/ DayFindById

type DayID

type DayID int

func NewDay

func NewDay(d *Day) (DayID, error)

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

type DisplaySlot struct {
	SlotID      SlotID
	SlotTime    Time
	TimeDisplay string
	Checked     bool
}

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 EventOptions struct {
	AdminPwd        string
	DefaultLocation string
	// contains filtered or unexported fields
}

type EventStore

type EventStore struct {
	*sqlx.DB
	// contains filtered or unexported fields
}

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 LocationFindById

func LocationFindById(lid LocationID) (*Location, error)

/ LocationFindById

func LocationGetAll

func LocationGetAll() (locations []Location, err error)

type LocationID

type LocationID int

func NewLocation

func NewLocation(l *Location) (LocationID, error)

type SchedState

type SchedState int

func SchedGetState

func SchedGetState() SchedState

type SearchAlgo

type SearchAlgo string

type SearchOptions

type SearchOptions struct {
	Async          bool
	Algo           SearchAlgo
	Validate       bool
	DebugLevel     int
	SearchDuration time.Duration
	Debug          *log.Logger
}

type Slot

type Slot struct {
	SlotID
	DayID
	SlotIDX  int
	SlotTime string
	IsBreak  bool
	IsLocked bool
}

type SlotID

type SlotID string

type TZLocation

type TZLocation struct {
	*time.Location
}

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

func (TZLocation) Value

func (l TZLocation) Value() (driver.Value, error)

type Time

type Time struct {
	time.Time
}

func Date

func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time

func ParseInLocation

func ParseInLocation(layout, value string, loc TZLocation) (Time, error)

func (*Time) Scan

func (t *Time) Scan(src interface{}) error

func (Time) Value

func (t Time) Value() (driver.Value, 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 TimetableDiscussion struct {
	DiscussionID DiscussionID
	Title        string
	Attendees    int
	Score        int
	LocationName string
	LocationURL  string
}

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 UserFind

func UserFind(userid UserID) (*User, error)

func UserFindByUsername

func UserFindByUsername(username string) (*User, error)

Return nil for user not present

func UserFindRandom

func UserFindRandom() (*User, error)

func UserGetAll

func UserGetAll() ([]User, error)

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

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 (u *User) MayEditUser(tgt *User) bool

func (*User) SetInterest

func (user *User) SetInterest(disc *Discussion, interest int) error

func (*User) SetVerified

func (user *User) SetVerified(isVerified bool) error

type UserID

type UserID string

func NewUser

func NewUser(password string, user *User) (UserID, error)

type ValidationError

type ValidationError error

Jump to

Keyboard shortcuts

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