diff --git a/README.md b/README.md index 222d5b2..e351b86 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,24 @@ WARNING: Use with caution. I am yet to find a host/school that provides this dat **_error**: < error > Holds standard error data if errors were encountered. +## GetClasses(school, checkAvailability) (_result, _error) + +Retrieves all classes in a school. + +A class is a group of people, typically taking one or more courses together. + +### Parameters + +**school**: < [School](#school) > School to get students from. + +**checkAvailability**: < bool > If stored availability data should be used to skip requests for unavailable data. + +### Returns + +**_result**: < [] [Class](#class) > Array of available classes. + +**_error**: < error > Holds standard error data if errors were encountered. + # Types @@ -167,6 +185,8 @@ Defines types of data available on a specific entity. Represents a room. +### Fields + **Name**: < string > Friendlyname of the room. **RoomId**: < string > ID of the room (GUID). @@ -177,6 +197,8 @@ Represents a room. Represents a teacher. +### Fields + **FirstName**: < string > Teacher's first name. **LastName**: < string > Teacher's last name. @@ -193,4 +215,34 @@ Represents a teacher. **Reported**: < bool > Purpose unknown. -**ReadOnly**: < bool > Purpose unknown. \ No newline at end of file +**ReadOnly**: < bool > Purpose unknown. + +## Class + +Represents a group of people, usually taking a course together. + +### Fields + +**Name**: < string > Friendlyname of the class. + +**ClassId**: < string > ID of the class (GUID). + +**AbsenceMessageNotDeliveredCount**: < int > Purpose unknown. + +**IsResponsible**: < bool > Purpose unknown. + +**IsClass**: < bool > Purpose unknown. + +**IsAdmin**: < bool > Purpose unknown. + +**IsPrincipal**: < bool > Purpose unknown. + +**IsMentor**: < bool > Purpose unknown. + +**IsPreschoolGroup**: < bool > Purpose unkown. + +**Teachers**: < any > Teachers, typically mentors, for the class. WARNING: Currently untyped, use with caution. + +**SubstituteTeacherId**: < any > Teacher ID of substitute teacher (if any). See [Teacher](#teacher). + +**TeacherChangeStudents**: < int > Purpose unknown. \ No newline at end of file diff --git a/cmd/goskola24api/main.go b/cmd/goskola24api/main.go index 321c82e..3ac0318 100644 --- a/cmd/goskola24api/main.go +++ b/cmd/goskola24api/main.go @@ -22,7 +22,10 @@ func main() { schools, _ := api.GetSchools() for _, school := range schools { - fmt.Println(school.AvailableData) + fmt.Println(school.Name) + if school.AvailableData.HasCourses { + fmt.Println("School has data") + } } rooms, err := api.GetRooms(schools[4], true) @@ -43,12 +46,14 @@ func main() { fmt.Println(teacher.FullName) } - students, err := api.GetStudents(schools[4], true) + classes, err := api.GetClasses(schools[4], true) if err != nil { fmt.Println(err.Error()) } - fmt.Println(students) + for _, class := range classes { + fmt.Println(class.Name) + } fmt.Println(key) } diff --git a/internal/requests/get_classes.go b/internal/requests/get_classes.go new file mode 100644 index 0000000..28313b9 --- /dev/null +++ b/internal/requests/get_classes.go @@ -0,0 +1,89 @@ +/* +GoSkola24API +Copyright (C) 2024, Marco Vitchi Thulin + +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License version 3 +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License version 3 for more details. + +This program incorporates external libraries for certain functionalities. +These libraries are covered by their respective licenses, and their usage +agreements are as outlined in their respective documentation or source +code. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +package requests + +import ( + "errors" + + "git.zervo.org/zervo/GoSkola24API/internal/types" + pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types" +) + +func GetClasses(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Class, _error error) { + if checkAvailability && !school.AvailableData.HasClasses { + return nil, errors.New("availability check failed: school does not provide class data") + } + + filters := types.RequestFilters{ + Class: true, + Course: false, + Group: false, + Period: false, + Room: false, + Student: false, + Subject: false, + Teacher: false, + } + + responseMap, err := GetGenericSelection(school, filters) + if err != nil { + return nil, errors.New("failed to get classes: " + err.Error()) + } + + // Extract classes as []interface{} + classesRaw, ok := responseMap["classes"].([]interface{}) + if !ok { + return nil, errors.New("missing or invalid \"classes\" field in response") + } + + // Convert raw classes into usable class type + var classes []pubtypes.Class + for _, classRaw := range classesRaw { + classMap, ok := classRaw.(map[string]interface{}) + if !ok { + return nil, errors.New("unexpected room format") + } + + // Create class instance from data + class := pubtypes.Class{ + Name: func() string { val, _ := classMap["groupName"].(string); return val }(), + ClassId: func() string { val, _ := classMap["groupGuid"].(string); return val }(), + AbsenceMessageNotDeliveredCount: func() int { val, _ := classMap["absenceMessageNotDeliveredCount"].(int); return val }(), + IsResponsible: func() bool { val, _ := classMap["isResponsible"].(bool); return val }(), + IsClass: func() bool { val, _ := classMap["isClass"].(bool); return val }(), + IsAdmin: func() bool { val, _ := classMap["isAdmin"].(bool); return val }(), + IsPrincipal: func() bool { val, _ := classMap["isPrincipal"].(bool); return val }(), + IsMentor: func() bool { val, _ := classMap["isMentor"].(bool); return val }(), + IsPreschoolGroup: func() bool { val, _ := classMap["isPreschoolGroup"].(bool); return val }(), + Teachers: classMap["teachers"], // TODO: MAKE TYPED + SubstituteTeacherId: func() string { val, _ := classMap["substituteTeacherGuid"].(string); return val }(), + TeacherChangeStudents: func() int { val, _ := classMap["teacherChangeStudentsInGroup"].(int); return val }(), + } + + classes = append(classes, class) + } + + return classes, nil +} diff --git a/pkg/goskola24api/skola24api.go b/pkg/goskola24api/skola24api.go index 211e600..fc942df 100644 --- a/pkg/goskola24api/skola24api.go +++ b/pkg/goskola24api/skola24api.go @@ -52,3 +52,7 @@ func (api Skola24API) GetTeachers(school pubtypes.School, checkAvailability bool func (api Skola24API) GetStudents(school pubtypes.School, checkAvailability bool) (_result any, _error error) { return requests.GetStudents(school, checkAvailability) } + +func (api Skola24API) GetClasses(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Class, _error error) { + return requests.GetClasses(school, checkAvailability) +} diff --git a/pkg/goskola24api/types/classes.go b/pkg/goskola24api/types/classes.go new file mode 100644 index 0000000..586cfff --- /dev/null +++ b/pkg/goskola24api/types/classes.go @@ -0,0 +1,40 @@ +/* +GoSkola24API +Copyright (C) 2024, Marco Vitchi Thulin + +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License version 3 +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License version 3 for more details. + +This program incorporates external libraries for certain functionalities. +These libraries are covered by their respective licenses, and their usage +agreements are as outlined in their respective documentation or source +code. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +package types + +type Class struct { + Name string `json:"name"` + ClassId string `json:"classId"` + AbsenceMessageNotDeliveredCount int `json:"absenceMessageNotDeliveredCount"` + IsResponsible bool `json:"isResponsible"` + IsClass bool `json:"isClass"` + IsAdmin bool `json:"isAdmin"` + IsPrincipal bool `json:"isPrincipal"` + IsMentor bool `json:"isMentor"` + IsPreschoolGroup bool `json:"isPreschoolGroup"` + Teachers any `json:"teachers"` // TODO: MAKE TYPED + SubstituteTeacherId string `json:"substituteTeacherId"` + TeacherChangeStudents int `json:"teacherChangeStudents"` +}