api

package
v1.6.1-0...-e0dc824 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Location = "Europe/Kyiv"

Variables

This section is empty.

Functions

func FillEmptyDates

func FillEmptyDates(days *[]TimeTableDate, dateStart string, dateEnd string) error

FillEmptyDates fills empty dates in given days slice

For example, we have schedule for 2023-08-21 and 2023-08-23. If there is no lessons for 2023-08-22, API will return schedule only for 2023-08-21 and 2023-08-23. This function will fill empty dates with empty lessons list.

func GetDateFromDayOfYear

func GetDateFromDayOfYear(year int, dayOfYear int) time.Time

GetDateFromDayOfYear returns date from given year and day of year

func GetDateRange

func GetDateRange(date time.Time, range_ int) (time.Time, time.Time)

GetDateRange returns date range from given date and range

For example, we have date 2023-08-21 and range of 10 days. Let's convert it to day of year: 233. Then we will have 230 and 239 (240 not included) days of year of range. So, we will have date range from 2023-08-18 to 2023-08-27.

func ParseISODate

func ParseISODate(date string) (time.Time, error)

ParseISODate parses ISO date string

Types

type Api

type Api interface {
	// GetStructures returns a list of structures
	GetStructures() ([]Structure, error)
	// GetFaculties returns a list of faculties in a structure
	GetFaculties(structureId int) ([]Faculty, error)
	// GetCourses returns a list of courses in a faculty
	GetCourses(facultyId int) ([]Course, error)
	// GetGroups returns a list of groups in a faculty
	GetGroups(facultyId int, course int) ([]Group, error)
	// GetGroupStudents returns a list of students in a group
	GetGroupStudents(groupId int) ([]Student, error)
	// GetCallSchedule returns a call schedule
	GetCallSchedule() (CallSchedule, error)
	// GetGroupSchedule returns a schedule for a group
	// from dateStart to dateEnd (inclusive)
	GetGroupSchedule(groupId int, dateStart string, dateEnd string) (Schedule, error)
	// GetScheduleExtraInfo returns a extra info for a schedule,
	// that can be added by a teacher or university administration.
	//
	// classCode is a TimeTablePeriod.R1 field
	GetScheduleExtraInfo(classCode int, date string) (ScheduleExtraInfo, error)
	// GetGroupScheduleDay returns a schedule for a group for a day
	//
	// Alias for GetGroupSchedule(groupId, date, date).GetDay(date)
	GetGroupScheduleDay(groupId int, date string) (*TimeTableDate, error)
}

Api is a wrapper for mkr.org.ua API requests. Documentation can be found here: https://mkr.org.ua

func NewApi

func NewApi(url string) Api

NewApi creates a new DefaultApi instance

type CallSchedule

type CallSchedule []CallScheduleEntry

func (*CallSchedule) GetCall

func (s *CallSchedule) GetCall(number int) *CallScheduleEntry

type CallScheduleEntry

type CallScheduleEntry struct {
	TimeStart string `json:"timeStart"`
	TimeEnd   string `json:"timeEnd"`
	Number    int    `json:"number"`
	Length    int    `json:"length"`
}

type Course

type Course struct {
	Course int `json:"course"`
}

type DefaultApi

type DefaultApi struct {
	Url     string
	Timeout time.Duration
}

func (DefaultApi) GetCallSchedule

func (a DefaultApi) GetCallSchedule() (CallSchedule, error)

func (DefaultApi) GetCourses

func (a DefaultApi) GetCourses(facultyId int) ([]Course, error)

func (DefaultApi) GetFaculties

func (a DefaultApi) GetFaculties(structureId int) ([]Faculty, error)

func (DefaultApi) GetGroupSchedule

func (a DefaultApi) GetGroupSchedule(groupId int, dateStart string, dateEnd string) (Schedule, error)

func (DefaultApi) GetGroupScheduleDay

func (a DefaultApi) GetGroupScheduleDay(groupId int, date string) (*TimeTableDate, error)

func (DefaultApi) GetGroupStudents

func (a DefaultApi) GetGroupStudents(groupId int) ([]Student, error)

func (DefaultApi) GetGroups

func (a DefaultApi) GetGroups(facultyId int, course int) ([]Group, error)

func (DefaultApi) GetScheduleExtraInfo

func (a DefaultApi) GetScheduleExtraInfo(classCode int, date string) (ScheduleExtraInfo, error)

func (DefaultApi) GetStructures

func (a DefaultApi) GetStructures() ([]Structure, error)

type Faculty

type Faculty struct {
	Id        int    `json:"id"`
	ShortName string `json:"shortName"`
	FullName  string `json:"fullName"`
}

type ForbiddenError

type ForbiddenError struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Code    int    `json:"code"`
	Status  int    `json:"status"`
}

ForbiddenError is an error returned by the API when status code is 403

func (*ForbiddenError) Error

func (e *ForbiddenError) Error() string

type Group

type Group struct {
	Id            int    `json:"id"`
	Name          string `json:"name"`
	Course        int    `json:"course"`
	Priority      int    `json:"priority"`
	EducationForm int    `json:"educationForm"`
}

type HTTPApiError

type HTTPApiError struct {
	Code int
	Body string
	Err  error
}

HTTPApiError is an error returned by the API when status code is not 200

func (*HTTPApiError) Error

func (e *HTTPApiError) Error() string

type InternalServerError

type InternalServerError struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Code    int    `json:"code"`
	Status  int    `json:"status"`
}

InternalServerError is an error returned by the API when status code is 500

func (*InternalServerError) Error

func (e *InternalServerError) Error() string

type Schedule

type Schedule []TimeTableDate

func (*Schedule) GetDay

func (s *Schedule) GetDay(date string) *TimeTableDate

type ScheduleExtraInfo

type ScheduleExtraInfo struct {
	Html string `json:"html"`
}

type Structure

type Structure struct {
	Id        int    `json:"id"`
	ShortName string `json:"shortName"`
	FullName  string `json:"fullName"`
}

type Student

type Student struct {
	Id         int    `json:"id"`
	FirstName  string `json:"firstName"`
	SecondName string `json:"secondName"`
	LastName   string `json:"lastName"`
}

func (*Student) GetFullName

func (stud *Student) GetFullName() string

type TimeTableDate

type TimeTableDate struct {
	Date    string            `json:"date"`
	Lessons []TimeTableLesson `json:"lessons"`
}

func (*TimeTableDate) GetLesson

func (day *TimeTableDate) GetLesson(number int) *TimeTableLesson

GetLesson returns a lesson with a specific number from a day.

type TimeTableLesson

type TimeTableLesson struct {
	Number  int               `json:"number"`
	Periods []TimeTablePeriod `json:"periods"`
}

type TimeTablePeriod

type TimeTablePeriod struct {
	R1           int `json:"r1"`
	Rz14         int `json:"rz14"`
	Rz15         int `json:"rz15"`
	R5           int `json:"r5"`
	DisciplineId int `json:"disciplineId"`
	// Disabled because it can sometimes be bool instead of int,
	// which causes errors. University's fault.
	//EducationDisciplineId int    `json:"educationDisciplineId"`
	DisciplineFullName  string `json:"disciplineFullName"`
	DisciplineShortName string `json:"disciplineShortName"`
	Classroom           string `json:"classroom"`
	TimeStart           string `json:"timeStart"`
	TimeEnd             string `json:"timeEnd"`
	TeachersName        string `json:"teachersName"`
	TeachersNameFull    string `json:"teachersNameFull"`
	Type                int    `json:"type"`
	TypeStr             string `json:"typeStr"`
	DateUpdated         string `json:"dateUpdated"`
	NonstandardTime     bool   `json:"nonstandardTime"`
	Groups              string `json:"groups"`
	ChairName           string `json:"chairName"`
	ExtraText           bool   `json:"extraText"`
	LessonYear          int    `json:"lessonYear"`
	Semester            int    `json:"semester"`
}

type UnauthorizedError

type UnauthorizedError struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Code    int    `json:"code"`
	Status  int    `json:"status"`
}

UnauthorizedError is an error returned by the API when status code is 401

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

type ValidationError

type ValidationError struct {
	Fields []ValidationErrorField `json:"fields"`
}

ValidationError is an error returned by the API when status code is 422. It means that the request body is invalid

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationErrorField

type ValidationErrorField struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

ValidationErrorField is a field of ValidationError

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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