views

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = Error{Code: "invalid_credentials", Message: "Login ou senha incorretos."}
	ErrInvalidAuthCode    = Error{Code: "invalid_auth_code", Message: "Esse código de autenticação não é válido ou está obsoleto."}
	ErrInvalidEmail       = Error{Code: "invalid_email", Message: "Esse e-mail já está cadastrado."}
	ErrInvalidUser        = Error{Code: "invalid_user", Message: "Esse usuário já está cadastrado."}
	ErrUnverifiedUser     = Error{Code: "unverified_user", Message: "Seu e-mail precisa ser verificado para utilizar o USPY."}
	ErrBannedUser         = Error{Code: "banned_user", Message: "Infelizmente sua conta foi banida."}
	ErrWrongPassword      = Error{Code: "invalid_password", Message: "Senha incorreta"}
	ErrInvalidUpdate      = Error{Code: "invalid_update", Message: "Você não pode atualizar seu histórico utilizando a chave de outro usuário."}
	ErrOther              = Error{Code: "other", Message: "Ocorreu um erro inesperado."}
)

Errors returned in response objects

Functions

func SortOfferings

func SortOfferings(results []*Offering)

SortOfferings takes a list of offerings and sorts them

It sorts based on the approval and neutral ratings values of each offering. If this value is equal in both objects, it uses the disapproval and amount of years as a tiebreaker

Types

type Comment

type Comment struct {
	ID        uuid.UUID `json:"uuid"`
	Rating    int       `json:"rating"`
	Body      string    `json:"body"`
	Edited    bool      `json:"edited"`
	Timestamp time.Time `json:"timestamp"`
	Upvotes   int       `json:"upvotes"`
	Downvotes int       `json:"downvotes"`
	Verified  bool      `json:"verified"`
}

Comment is the response view object for a comment

func NewCommentFromModel

func NewCommentFromModel(model *models.Comment) *Comment

NewCommentFromModel is a constructor. It takes a comment model and returns its response view object.

It may panic is the timestamp cannot be generated using the America/Sao_Paulo timezone.

type CommentRating

type CommentRating struct {
	Type string `json:"type"`
}

CommentRating is the response view object for a comment rating.

func NewCommentRatingFromModel

func NewCommentRatingFromModel(model *models.CommentRating) *CommentRating

NewCommentRatingFromModel is a constructor. It takes a comment rating model and returns its response view object.

type Course

type Course struct {
	Name           string            `json:"name"`
	Code           string            `json:"code"`
	Specialization string            `json:"specialization"`
	Shift          string            `json:"shift"`
	SubjectCodes   map[string]string `json:"subjects,omitempty"`
}

Course is the response view object for a course

func NewCourseFromModel

func NewCourseFromModel(course *models.Course) *Course

NewCourseFromModel is a constructor. It takes a course model and returns its response view object.

type CurriculumResult

type CurriculumResult struct {
	// Subject data
	Name string `json:"name"`
	Code string `json:"code"`

	// Record data (only present if Completed is true)
	Grade     float64 `json:"grade,omitempty"`
	Frequency int     `json:"frequency,omitempty"`
	Status    string  `json:"status,omitempty"`

	Completed bool `json:"completed"`
}

CurriculumResult is the response view object for a curriculum query made for a given user

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Error is the default error struct used. It contains the error code and message

type Institute

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

Institute is the response view object for a institute

func NewInstituteFromModel

func NewInstituteFromModel(model *models.Institute) *Institute

NewInstituteFromModel is a constructor. It takes an institute model and returns its response view object.

type Major

type Major struct {
	Code           string `json:"code"`
	Specialization string `json:"specialization"`
	Name           string `json:"name"`
}

Major is the response view object for a user's major / enrolled courses

It unites model information from a course and a major (major models don't have the name property)

func NewMajorFromModels

func NewMajorFromModels(major *models.Major, course *models.Course) *Major

NewMajorFromModels takes the course and major models and unites them into a view object

type Offering

type Offering struct {
	ProfessorName string   `json:"professor"`
	ProfessorCode string   `json:"code"`
	Years         []string `json:"years"`

	Approval    float64 `json:"approval"`
	Neutral     float64 `json:"neutral"`
	Disapproval float64 `json:"disapproval"`
}

Offering is the response view object for an offering

It contains time information and some stats

func NewOfferingFromModel

func NewOfferingFromModel(ID string, model *models.Offering, approval, disapproval, neutral int) *Offering

NewOfferingFromModel is a constructor. It takes a model and returns its response view object.

It also requires the ID of the professor in the current context and their approval stats

func NewPartialOfferingFromModel

func NewPartialOfferingFromModel(ID string, model *models.Offering) *Offering

NewPartialOfferingFromModel is a constructor. It takes an offering model and returns its view response object

It is partial because it leaves stats data empty for the given offering This is used in public offering endpoints

type Professor added in v1.5.5

type Professor struct {
	Name string `json:"name"`
	Hash string `json:"code"`
}

Professor is the response view object for a professor

func NewProfessorFromModel added in v1.5.5

func NewProfessorFromModel(prof *models.Professor) *Professor

NewProfessorFromModel is a constructor. It takes a professor model and returns its view object

type Profile

type Profile struct {
	User       string    `json:"user"`
	Name       string    `json:"name"`
	LastUpdate time.Time `json:"last_update"`
}

Profile is the response view object for a logged user

It is used to display the Greeting information ("Hello ____")

func NewProfile

func NewProfile(user, name string, lastUpdate time.Time) *Profile

NewProfile returns a new view profile object from user data

type Record

type Record struct {
	Code           string `json:"code,omitempty"`
	Name           string `json:"name,omitempty"`
	Course         string `json:"course,omitempty"`
	Specialization string `json:"specialization,omitempty"`
	Reviewed       bool   `json:"reviewed"`

	Grade     float64 `json:"grade"`
	Status    string  `json:"status"`
	Frequency int     `json:"frequency"`

	Semester int `json:"semester,omitempty"`
	Year     int `json:"year,omitempty"`
}

Record is the response view object for a user subject record

It contains three types of data: - optional basic subject data - record data (grade, status, frequency) - optinal time data

func NewRecordFromModel

func NewRecordFromModel(model *models.Record) *Record

NewRecordFromModel is a constructor. It takes a model and returns its response view object.

type Requirement

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

Requirement represents a subject requirement

type Stats added in v1.5.2

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

Stats is the response view object for a stats lookup

func NewStatsFromModel added in v1.5.2

func NewStatsFromModel(stats *models.Stats) *Stats

NewStatsFromModel is a constructor. It takes a model stats and returns its response view object.

type Subject

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

Subject is the response view object for a subject

It mostly contains static data that is collected from JupiterWeb Except for Stats, which is a property calculated by user reviews

func NewSubjectFromModel

func NewSubjectFromModel(model *models.Subject) *Subject

NewSubjectFromModel is a constructor. It takes a model subject and returns its response view object.

type SubjectGraph

type SubjectGraph struct {
	Predecessors [][]Requirement `json:"predecessors"`
	Successors   []Requirement   `json:"successors"`
}

SubjectGraph is the response view object for a subjects predecessors and successors graph

Predecessors represents the subjects that need to be taken before a given subject Successors represents the successors that need to be taken after a given subject

type SubjectReview

type SubjectReview struct {
	Review map[string]interface{} `json:"categories"`
}

SubjectReview is the response view object for a subject review

It only contains a map with review categories and their associated values. These values are usually boolean

func NewSubjectReviewFromModel

func NewSubjectReviewFromModel(model *models.SubjectReview) *SubjectReview

NewSubjectReviewFromModel is a constructor. It takes a SubjectReview model and returns its view response object.

type SubjectSibling added in v1.5.9

type SubjectSibling struct {
	Code     string `json:"code"`
	Name     string `json:"name"`
	Optional bool   `json:"optional"`
}

func NewSubjectSibling added in v1.5.9

func NewSubjectSibling(model *models.Subject) *SubjectSibling

type Transcript

type Transcript struct {
	Grades []Record `json:"grades"`
	Name   string   `json:"name"`
	Nusp   string   `json:"nusp"`
}

Transcript is the view response object for a users' history of grades, e.g. their progress

It contains basic user info that is used solely as identifiers along with their grades data that is used to generate the subjects grades distribution

func NewTranscript

func NewTranscript(model *iddigital.Transcript) *Transcript

NewTranscript is a constructor. It takes a model object and returns its response view object.

type TranscriptYear

type TranscriptYear struct {
	Year      int   `json:"year"`
	Semesters []int `json:"semesters"`
}

TranscriptYear is the response view object for a when the user's transcript years is queried

Jump to

Keyboard shortcuts

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