models

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: AGPL-3.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteSignup added in v1.5.5

func CompleteSignup(DB db.Database, userHash, collection, email, password string) error

CompleteSignup sets a user's email and password and verifies an user. Collection is usually /users

Types

type Comment

type Comment struct {
	ID        uuid.UUID `firestore:"id"`
	Rating    int       `firestore:"rating"`
	Body      string    `firestore:"body"`
	Edited    bool      `firestore:"edited"`
	Timestamp time.Time `firestore:"last_update"`
	Upvotes   int       `firestore:"upvotes"`
	Downvotes int       `firestore:"downvotes"`
	Reports   int       `firestore:"reports"`

	Verified bool `firestore:"verified,omitempty"`

	User string `firestore:"-"` // not stored just used for hashing
}

Comment is the DTO for a comment

func (Comment) Hash

func (c Comment) Hash() string

Hash returns SHA256(userID), where userID is the the ID of the user who made the comment

This is made this way so that looking up comments is easy and fast.

type CommentRating

type CommentRating struct {
	ID     uuid.UUID `firestore:"id"`
	Upvote bool      `firestore:"upvote"`

	ProfessorHash  string `firestore:"professor"`
	Subject        string `firestore:"subject"`
	Course         string `firestore:"course"`
	Specialization string `firestore:"specialization"`
}

CommentRating is the DTO for a comment rating, it contains offering data and the rating evaluation

func (CommentRating) Hash

func (cr CommentRating) Hash() string

Hash returns the ID associated to the rated comment

type CommentReport

type CommentReport struct {
	ID     uuid.UUID `firestore:"id"`
	Report string    `firestore:"report"`

	ProfessorHash  string `firestore:"professor"`
	Subject        string `firestore:"subject"`
	Course         string `firestore:"course"`
	Specialization string `firestore:"specialization"`
}

CommentReport is the DTO for a comment report, it contains offering data and the report

func (CommentReport) Hash

func (cr CommentReport) Hash() string

Hash returns the UUID associated to the reported comment

type Course

type Course struct {
	Name string `firestore:"name"`

	Code           string `firestore:"code"`
	Specialization string `firestore:"specialization"`

	Shift        string            `firestore:"shift"`
	SubjectCodes map[string]string `firestore:"subjects"`

	Subjects []Subject `firestore:"-"`

	// institute code, just used for querying, TODO: actually collect this in the scraper
	Institute string `firestore:"-"`
}

Course is the DTO for a course Example: {"Bacharelado em Ciências de Computação", "55041", []Subjects{...}, map[string]string{"SMA0356": "Cálculo IV", ...}}

func NewCourseFromController

func NewCourseFromController(course *controllers.InstituteCourse) *Course

NewCourseFromController is a constructor. It takes a course controller and returns a model.

func (Course) Hash

func (c Course) Hash() string

Hash returns SHA256(concat(course, specialization))

func (Course) Insert

func (c Course) Insert(DB db.Database, collection string) error

Insert sets a course to a given collection. This is usually /institutes/#institute/courses

func (Course) Update

func (c Course) Update(DB db.Database, collection string) error

Update sets a course to a given collection

type Institute

type Institute struct {
	Name string `firestore:"name"`
	Code string `firestore:"code"`

	// Attributes only used to nest collected data by uspy-scraper
	Courses    []Course    `firestore:"-"`
	Professors []Professor `firestore:"-"`
}

Institute represents an institute or collection of courses

func NewInstituteFromController

func NewInstituteFromController(controller *controllers.Institute) *Institute

NewInstituteFromController is a constructor. It takes a institute controller and returns a model.

func (Institute) Hash

func (i Institute) Hash() string

Hash returns SHA256(code)

func (Institute) Insert

func (i Institute) Insert(DB db.Database, collection string) error

Insert sets an institute to a given collection. This is usually /institutes

func (Institute) Update

func (i Institute) Update(DB db.Database, collection string) error

Update sets an institute to a given collection. This is usually /institutes

type Major

type Major struct {
	Code           string `firestore:"course"`
	Specialization string `firestore:"specialization"`
}

Major is the DTO for a course/major. It represents a tuple (course, specialization)

It is used for storing which courses a user has records of

func NewMajorFromController

func NewMajorFromController(major *controllers.Major) *Major

NewMajorFromController is a constructor. It takes a major controller and returns a model.

func (Major) Hash

func (m Major) Hash() string

Hash returns SHA256(concat(course, specialization))

func (Major) Insert

func (m Major) Insert(DB db.Database, collection string) error

Insert sets a major to a given collection. This is usually /users/#user/majors

func (Major) Update

func (m Major) Update(DB db.Database, collection string) error

Update is a dummy method for a major

type Offering

type Offering struct {
	CodPes string `firestore:"-"`
	Code   string `firestore:"-"`

	Professor string   `firestore:"professor"`
	Years     []string `firestore:"years"`
}

Offering is the DTO for an offering of a subject Since it is inside a subcollection of a subject, it does not have subject data

It contains some properties that are not mapped to firestore for internal logic and data collection purposes.

func (Offering) Hash

func (off Offering) Hash() string

Hash returns SHA256(professor_code)

func (Offering) Insert

func (off Offering) Insert(DB db.Database, collection string) error

Insert sets an offering to a given collection. This is usually /subjects/#subject/offerings

func (Offering) Update

func (off Offering) Update(DB db.Database, collection string) error

Update sets an offering to a given collection

type OfferingStats

type OfferingStats struct {
	Approval    int
	Disapproval int
	Neutral     int
}

OfferingStats represents the evaluation stats for an offering.

It is not a DTO and is only used in internal logic.

type Professor

type Professor struct {
	CodPes     string `firestore:"-"`
	CodPesHash string `firestore:"-"` // used only when the ID is unknown

	Name string `firestore:"name"`

	Offerings []Offering `firestore:"-"`
}

Professor is an object that represents a USP professor

It is not a DTO and is only used for data collection purposes

func (Professor) Hash added in v1.5.5

func (p Professor) Hash() string

Hash returns SHA256(professor_code)

func (Professor) Insert

func (p Professor) Insert(DB db.Database, collection string) error

Insert sets a Professor to a given collection. This is usually /institutes/#institute/professors/#professor

func (Professor) Update

func (p Professor) Update(DB db.Database, collection string) error

Update sets a Professor to a given collection

type Record

type Record struct {
	Subject        string `firestore:"-"`
	Course         string `firestore:"-"`
	Specialization string `firestore:"-"`

	Year     int `firestore:"-"`
	Semester int `firestore:"-"`

	Grade     float64 `firestore:"grade"`
	Status    string  `firestore:"status,omitempty"`
	Frequency int     `firestore:"frequency,omitempty"`
}

Record is a DTO for a user's subject grade record

It contains some properties that are not mapped to the database and solely used for internal, contextual logic.

func (Record) Hash

func (mf Record) Hash() string

Hash returns SHA256(concat(record_year, record_semester))

This is done in this way so that if a user has more than one record for a given subject, they differ by when the subject was taken.

func (Record) Insert

func (mf Record) Insert(DB db.Database, collection string) error

Insert sets a record to a given collection. This is usually /users/#user/final_scores/#final_score/records

func (Record) Update

func (mf Record) Update(DB db.Database, collection string) error

Update is a dummy method for a record

type Requirement

type Requirement struct {
	Subject string `firestore:"code"`
	Name    string `firestore:"name"`
	Strong  bool   `firestore:"strong"`
}

Requirement represents a subject requirement

It is nested inside a subject DTO and not mapped directly to a document

type Stats added in v1.5.2

type Stats struct {
	Users     StatsEntry `firestore:"users"`
	Grades    StatsEntry `firestore:"grades"`
	Subjects  StatsEntry `firestore:"subjects"`
	Offerings StatsEntry `firestore:"offerings"`
	Comments  StatsEntry `firestore:"comments"`
}

Stats is a DTO for the database stats

func (Stats) Insert added in v1.5.2

func (s Stats) Insert(DB db.Database, collection string) error

Insert sets the stats counters

func (Stats) Update added in v1.5.2

func (s Stats) Update(DB db.Database, collection string) error

Update updates the user and grades count

Other data is not updated here to avoid heavy operations Use uspy-scraper to sync count of scraped data

type StatsEntry added in v1.5.2

type StatsEntry struct {
	Name  string `firestore:"name"`
	Count int    `firestore:"count"`

	LastUpdate time.Time `firestore:"last_update"`
}

StatsEntry represents a simple counter

type Subject

type Subject struct {
	Code             string                   `firestore:"code"`
	CourseCode       string                   `firestore:"course"`
	Specialization   string                   `firestore:"specialization"`
	Name             string                   `firestore:"name"`
	Description      string                   `firestore:"desc"`
	Semester         int                      `firestore:"semester"`
	ClassCredits     int                      `firestore:"class"`
	AssignCredits    int                      `firestore:"assign"`
	TotalHours       string                   `firestore:"hours"`
	Requirements     map[string][]Requirement `firestore:"requirements"`
	TrueRequirements []Requirement            `firestore:"true_requirements"`
	Optional         bool                     `firestore:"optional"`
	Stats            map[string]int           `firestore:"stats"`
}

Subject is the DTO for a subject.

It is probably one of the most used objects.

func NewSubjectFromController

func NewSubjectFromController(sub *controllers.Subject) *Subject

NewSubjectFromController is a constructor. It takes a subject controller and returns a model.

func (Subject) Hash

func (s Subject) Hash() string

Hash returns SHA256(concat(code, course, specialization))

func (Subject) Insert

func (s Subject) Insert(DB db.Database, collection string) error

Insert sets a subject to a given collection. This is usually /subjects

func (Subject) Update

func (s Subject) Update(DB db.Database, collection string) error

Update sets a subject to a given collection. This is usually /subjects

This method prohibits from changing the stats map

type SubjectReview

type SubjectReview struct {
	Subject        string `firestore:"-"`
	Course         string `firestore:"-"`
	Specialization string `firestore:"-"`

	Review map[string]interface{} `firestore:"categories"`
}

SubjectReview is the DTO for a subject review/evaluation made by an user

func NewSubjectReviewFromController

func NewSubjectReviewFromController(controller *controllers.SubjectReview) *SubjectReview

NewSubjectReviewFromController is a constructor. It takes a controller and returns a model.

func (SubjectReview) Hash

func (sr SubjectReview) Hash() string

Hash returns SHA256(concat(subject, course, specialization))

func (SubjectReview) Insert

func (sr SubjectReview) Insert(DB db.Database, collection string) error

Insert sets an offering to a given collection. This is usually /users/#user/subject_reviews

type User

type User struct {
	ID     string `firestore:"-"`
	IDHash string `firestore:"-"` // used only when the ID is unknown

	Name string `firestore:"-"`

	// NameHash is AES encrypted since it has to be decrypted
	NameHash string `firestore:"name"`

	// EmailHash is SHA256 encrypted because it must be queried in signup
	EmailHash string `firestore:"email"`

	Verified bool `firestore:"verified"` // Email verification
	Banned   bool `firestore:"banned"`

	// bcrypt hashing cause password is more sensitive
	PasswordHash string `firestore:"password"`

	LastUpdate      time.Time        `firestore:"last_update"`
	TranscriptYears map[string][]int `firestore:"transcript_years"` // map of years as keys and array of semesters as values
}

User is the DTO for a registered user

It also contains non mapped properties used for internal contextual logic.

func NewUser

func NewUser(ID, name string, lastUpdate time.Time, transcriptYears map[string][]int) (*User, error)

NewUser creates a new user. It takes raw data and processes all the encrypted data

User email verification is also bypassed in dev or local environments

func (User) Hash

func (u User) Hash() string

Hash returns SHA256(user_id)

func (User) Insert

func (u User) Insert(DB db.Database, collection string) error

Insert sets a user object to a given collection. This is usually /users

func (User) Update

func (u User) Update(DB db.Database, collection string) error

Update sets a user object to a given collection. This is usually /users

This method only allows updating the password TODO: Use MergeWithout to specifically mention non-updatable fields

type UserComment

type UserComment struct {
	Comment `firestore:"comment"`

	ProfessorHash  string `firestore:"professor"`
	Subject        string `firestore:"subject"`
	Course         string `firestore:"course"`
	Specialization string `firestore:"specialization"`
}

UserComment is the DTO for a user comment

It is a replica of the comment object, but stored in the context of the user instead of the offering

func (UserComment) Hash

func (uc UserComment) Hash() string

Hash returns SHA256(concat(subject, course, specialization, professor_hash))

Note here that professor_hash is a hex sha256 value and not their numeric id.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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