data

package
v0.0.0-...-8dc1090 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AnnouncementTypeText       = 0 // just informative
	AnnouncementTypeFullOff    = 1 // no classes at all
	AnnouncementTypeBreakStart = 2 // start of a break (inclusive of that day!)
	AnnouncementTypeBreakEnd   = 3 // end of a break (exclusive of that day!)
)

The available announcement types.

View Source
const (
	ProviderDataAnnouncements = (1 << 0)
	ProviderDataEvents        = (1 << 1)

	ProviderDataAll = ProviderDataAnnouncements | ProviderDataEvents
)
View Source
const FallbackBackground = "FFD3BD"

FallbackBackground is the background color of a word that does not have an associated prefix.

View Source
const FallbackColor = "000000"

FallbackColor is the text color of a word that does not have an associated prefix.

Variables

View Source
var DB *sql.DB
View Source
var DefaultPrefixes = []Prefix{
	{
		ID:         -1,
		Background: "4C6C9B",
		Color:      "FFFFFF",
		Words:      []string{"HW", "Read", "Reading"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "9ACD32",
		Color:      "FFFFFF",
		Words:      []string{"Project"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "C3A528",
		Color:      "FFFFFF",
		Words:      []string{"Report", "Essay", "Paper", "Write"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "FFA500",
		Color:      "FFFFFF",
		Words:      []string{"Quiz", "PopQuiz", "GradedHW", "GradedHomework"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "EE5D1E",
		Color:      "FFFFFF",
		Words:      []string{"Quest"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "DC143C",
		Color:      "FFFFFF",
		Words:      []string{"Test", "Final", "Exam", "Midterm"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "2AC0F1",
		Color:      "FFFFFF",
		Words:      []string{"ICA", "FieldTrip"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "2AF15E",
		Color:      "FFFFFF",
		Words:      []string{"Study", "Memorize"},
		TimedEvent: true,
		Default:    true,
	},
	{
		ID:         -1,
		Background: "000000",
		Color:      "00FF00",
		Words:      []string{"Trojun", "Hex"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "5000BC",
		Color:      "FFFFFF",
		Words:      []string{"OptionalHW", "Challenge"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "000099",
		Color:      "FFFFFF",
		Words:      []string{"Presentation", "Prez"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "123456",
		Color:      "FFFFFF",
		Words:      []string{"BuildSession", "Build"},
		TimedEvent: true,
		Default:    true,
	},
	{
		ID:         -1,
		Background: "5A1B87",
		Color:      "FFFFFF",
		Words:      []string{"Meeting", "Meet"},
		TimedEvent: true,
		Default:    true,
	},
	{
		ID:         -1,
		Background: "01B501",
		Color:      "FFFFFF",
		Words:      []string{"Begin", "Start", "Do"},
		TimedEvent: true,
		Default:    true,
	},
	{
		ID:         -1,
		Background: "E34000",
		Color:      "FFFFFF",
		Words:      []string{"Apply", "Application", "Deadline"},
		Default:    true,
	},
	{
		ID:         -1,
		Background: "3F4146",
		Color:      "FFFFFF",
		Words:      []string{"Form", "File", "Submit", "Upload"},
		Default:    true,
	},
}

DefaultPrefixes is the list of prefixes that all users start out with.

View Source
var (
	ErrNotFound = errors.New("data: not found")
)
View Source
var RedisClient *redis.Client

Functions

func DeleteEmailToken

func DeleteEmailToken(token EmailToken) error

DeleteEmailToken deletes the given email token.

func GetDataForSchool

func GetDataForSchool(school *School, user *User) (map[string]interface{}, error)

GetDataForSchool returns the data associated with the User's enrollment in the given School.

func SaveEmailToken

func SaveEmailToken(token EmailToken) error

SaveEmailToken saves the given email token with a default expiry.

func UserExistsWithEmail

func UserExistsWithEmail(email string) (bool, int, error)

UserExistsWithEmail checks for a user with the given email address. If one exists, it returns the ID of that user.

Types

type Application

type Application struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	AuthorName  string `json:"authorName"`
	ClientID    string `json:"clientId"`
	CallbackURL string `json:"callbackUrl"`
}

An Application describes a third-party application designed to integrate with MyHomeworkSpace.

type ApplicationAuthorization

type ApplicationAuthorization struct {
	ID            int    `json:"id"`
	ApplicationID int    `json:"applicationId"`
	Name          string `json:"name"`
	AuthorName    string `json:"authorName"`
}

An ApplicationAuthorization describes a user's authorization of an application's access to their account.

type DetailedSchoolError

type DetailedSchoolError struct {
	Code    string
	Details map[string]interface{}
}

DetailedSchoolError is a type of Error that occurs when a school provider wants to communicate data back to the client along with an error. This is useful for multi-step enrollments, where more information is required from the user.

func (DetailedSchoolError) Error

func (e DetailedSchoolError) Error() string

type EmailToken

type EmailToken struct {
	Token    string         `json:"token"`
	Type     EmailTokenType `json:"type"`
	Metadata string         `json:"metadata"`
	UserID   int            `json:"userID"`
}

An EmailToken is used for situations like an email change or a password reset, where a confirmation email must be sent.

func GetEmailToken

func GetEmailToken(token string) (EmailToken, error)

GetEmailToken fetches the given email token.

type EmailTokenType

type EmailTokenType int

An EmailTokenType describes different types of email token

const (
	EmailTokenNone EmailTokenType = iota
	EmailTokenResetPassword
	EmailTokenChangeEmail
	EmailTokenVerifyEmail
)

Define the default EmailTokenType.

type Event

type Event struct {
	ID            int                          `json:"id"`
	UniqueID      string                       `json:"uniqueId"`
	SeriesID      string                       `json:"seriesId"`
	SeriesName    string                       `json:"seriesName"`
	Name          string                       `json:"name"`
	Start         int                          `json:"start"`
	End           int                          `json:"end"`
	StartTimezone string                       `json:"startTimezone"`
	EndTimezone   string                       `json:"endTimezone"`
	RecurRule     *RecurRule                   `json:"recurRule"`
	Tags          map[EventTagType]interface{} `json:"tags"`
	Source        int                          `json:"source"`
	UserID        int                          `json:"userId"`
}

An Event is an event on a user's calendar. It could be from their schedule, homework, or manually added.

func (*Event) CalculateTimes

func (e *Event) CalculateTimes(until time.Time) ([]time.Time, error)

CalculateTimes returns a list of all times the given event will take place, using its RecurRule information.

type EventAction

type EventAction struct {
	Icon string `json:"icon"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

An EventAction is an action that can be performed on an Event; for example, a link to open a class's website.

type EventChange

type EventChange struct {
	EventID string `json:"eventID"`
	Cancel  bool   `json:"cancel"`
	UserID  int    `json:"userID"`
}

An EventChange is a modification a user makes to an Event that came from a provider.

type EventTagType

type EventTagType int

An EventTagType describes the type of an event tag.

const (
	EventTagReserved EventTagType = iota
	EventTagDescription
	EventTagHomework
	EventTagTermID
	EventTagClassID
	EventTagOwnerID
	EventTagOwnerName
	EventTagDayNumber
	EventTagBlock
	EventTagBuildingName
	EventTagRoomNumber
	EventTagLocation
	EventTagReadOnly
	EventTagShortName
	EventTagActions
	EventTagCancelled
	EventTagCancelable
	EventTagSection
	EventTagOriginalStart
	EventTagOriginalEnd
	EventTagHideBuildingName
	EventTagHomeworkClass
)

The available event tags.

type Feedback

type Feedback struct {
	ID            int    `json:"id"`
	UserID        int    `json:"userid"`
	Type          string `json:"type"`
	Text          string `json:"text"`
	Timestamp     string `json:"timestamp"`
	UserName      string `json:"userName"`
	UserEmail     string `json:"userEmail"`
	HasScreenshot bool   `json:"hasScreenshot"`
	UserAgent     string `json:"userAgent"`
}

type Homework

type Homework struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Due      string `json:"due"`
	Desc     string `json:"desc"`
	Complete int    `json:"complete"`
	ClassID  int    `json:"classId"`
	UserID   int    `json:"userId"`
}

type HomeworkClass

type HomeworkClass struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Teacher   string `json:"teacher"`
	Color     string `json:"color"`
	SortIndex int    `json:"sortIndex"`
	UserID    int    `json:"userId"`
}

A HomeworkClass is a class that can be associated with Homework items.

func GetClassesForUser

func GetClassesForUser(user *User) ([]HomeworkClass, error)

GetClassesForUser gets all HomeworkClasses for the given user.

type OffBlock

type OffBlock struct {
	StartID   int       `json:"startId"`
	EndID     int       `json:"endId"`
	Start     time.Time `json:"-"`
	End       time.Time `json:"-"`
	StartText string    `json:"start"`
	EndText   string    `json:"end"`
	Name      string    `json:"name"`
	Grade     int       `json:"grade"`
}

An OffBlock is a period of time that's marked off on a calendar, such as a holiday.

type PlannerAnnouncement

type PlannerAnnouncement struct {
	ID    int    `json:"id"`
	Date  string `json:"date"`
	Text  string `json:"text"`
	Grade int    `json:"grade"`
	Type  int    `json:"type"`
}

type PlannerFriday

type PlannerFriday struct {
	ID    int    `json:"id"`
	Date  string `json:"date"`
	Index int    `json:"index"`
}

type Pref

type Pref struct {
	ID    int    `json:"id"`
	Key   string `json:"key"`
	Value string `json:"value"`
}

func GetPrefForUser

func GetPrefForUser(key string, userID int) (Pref, error)

GetPrefForUser fetches the Pref with the given key for the given user.

type Prefix

type Prefix struct {
	ID         int      `json:"id"`
	Background string   `json:"background"`
	Color      string   `json:"color"`
	Words      []string `json:"words"`
	TimedEvent bool     `json:"timedEvent"`
	Default    bool     `json:"default"`
}

A Prefix defines a group of words that get automatically recognized (for example: HW, Test, Quiz)

func GetPrefixesForUser

func GetPrefixesForUser(user *User) ([]Prefix, error)

GetPrefixesForUser returns a list of all prefixes for the given user, factoring in schools and custom settings.

type Provider

type Provider interface {
	ID() string
	Name() string
	GetData(db *sql.DB, user *User, location *time.Location, startTime time.Time, endTime time.Time, dataType ProviderDataType) (ProviderData, error)
}

A Provider is a source of calendar data (events, announcements, etc)

func GetProvidersForUser

func GetProvidersForUser(db *sql.DB, user *User) ([]Provider, error)

GetProvidersForUser returns a list of calendar providers associated with the given user

type ProviderData

type ProviderData struct {
	Announcements []PlannerAnnouncement `json:"announcements"`
	Events        []Event               `json:"events"`
}

A ProviderData struct contains all data returned by a Provider for a given time

type ProviderDataType

type ProviderDataType uint8

ProviderDataType describes the different types of data that can be requested from a Provider.

type RecurFrequency

type RecurFrequency int

A RecurFrequency describes how often an event recurs.

const (
	RecurFrequencyDaily RecurFrequency = iota
	RecurFrequencyWeekly
	RecurFrequencyMonthly
	RecurFrequencyYearly
)

Define the default RecurFrequencies.

type RecurRule

type RecurRule struct {
	ID          int            `json:"id"`
	EventID     int            `json:"eventId"`
	Frequency   RecurFrequency `json:"frequency"`
	Interval    int            `json:"interval"`
	ByDayString string         `json:"-"`
	ByDay       []time.Weekday `json:"byDay"`
	ByMonthDay  int            `json:"byMonthDay"`
	ByMonth     time.Month     `json:"byMonth"`
	Until       string         `json:"until"`
}

A RecurRule struct contains information about how an event recurs. Inspired by the iCal RRULE system.

type School

type School interface {
	ID() string
	Name() string
	ShortName() string
	UserDetails() string
	EmailAddress() string
	EmailDomain() string
	Prefixes() []Prefix

	CalendarProvider() Provider

	Hydrate(data map[string]interface{}) error

	GetSettings(db *sql.DB, user *User) (map[string]interface{}, error)
	SetSettings(db *sql.DB, user *User, settings map[string]interface{}) (*sql.Tx, map[string]interface{}, error)

	Enroll(tx *sql.Tx, user *User, params map[string]interface{}) (map[string]interface{}, error)
	Unenroll(tx *sql.Tx, user *User) error
	NeedsUpdate(db *sql.DB) (bool, error)
}

School is an interface implemented by all schools that a user can connect to their account

func GetSchoolsForUser

func GetSchoolsForUser(user *User) ([]School, error)

GetSchoolsForUser returns a list of schools that the given user is enrolled in, excluding disabled schools.

type SchoolError

type SchoolError struct {
	Code string
}

SchoolError is a type of Error that occurs due to invalid data or a similar condition. It's used to distinguish from internal server errors.

func (SchoolError) Error

func (e SchoolError) Error() string

type SchoolInfo

type SchoolInfo struct {
	EnrollmentID int    `json:"enrollmentID"`
	SchoolID     string `json:"schoolID"`
	Enabled      bool   `json:"enabled"`
	DisplayName  string `json:"displayName"`
	ShortName    string `json:"shortName"`
	UserDetails  string `json:"userDetails"`
	EmailAddress string `json:"emailAddress"`
	School       School `json:"-"`
	UserID       int    `json:"userID"`
}

SchoolInfo is a struct that holds information about a school. It's used to hold data in a format that the JSON package can then marshal out to the client.

type SchoolRegistry

type SchoolRegistry interface {
	GetAllSchools() []School
	GetSchoolByEmailDomain(domain string) (School, error)
	GetSchoolByID(id string) (School, error)
	Register(school School)
}

SchoolRegistry is an interface implemented by the central registry in the schools package

var MainRegistry SchoolRegistry

type SchoolResult

type SchoolResult struct {
	SchoolID    string `json:"schoolID"`
	DisplayName string `json:"displayName"`
	ShortName   string `json:"shortName"`
}

SchoolResult is a struct that holds information about a school that was searched for. (e.g. by email domain) It's used to hold data in a format that the JSON package can then marshal out to the client.

type Tab

type Tab struct {
	ID     int    `json:"id"`
	Slug   string `json:"slug"`
	Icon   string `json:"icon"`
	Label  string `json:"label"`
	Target string `json:"target"`
}

func GetTabsByUserID

func GetTabsByUserID(userID int) ([]Tab, error)

GetTabsByUserID fetches all tabs that the given user has access to.

type User

type User struct {
	ID                 int          `json:"id"`
	Name               string       `json:"name"`
	Email              string       `json:"email"`
	PasswordHash       string       `json:"-"`
	Type               string       `json:"type"`
	Features           string       `json:"features"`
	Level              int          `json:"level"`
	EmailVerified      bool         `json:"emailVerified"`
	ShowMigrateMessage int          `json:"showMigrateMessage"`
	CreatedAt          int          `json:"createdAt"`
	LastLoginAt        int          `json:"lastLoginAt"`
	Schools            []SchoolInfo `json:"schools"`
}

func GetUserByID

func GetUserByID(id int) (User, error)

GetUserByID fetches data for the given user ID.

Jump to

Keyboard shortcuts

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