commit d570b5a3d41f01d70a537f45b89017cf0c4f3bf9 Author: zervo Date: Thu Nov 21 18:41:28 2024 +0100 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a02751 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# GoSkola24API + +Go module for easy interaction with the Skola24 API. \ No newline at end of file diff --git a/cmd/goskola24api/main.go b/cmd/goskola24api/main.go new file mode 100644 index 0000000..b72dd7c --- /dev/null +++ b/cmd/goskola24api/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + + "git.zervo.org/zervo/GoSkola24API/internal/utility" + "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api" +) + +func main() { + key, _ := utility.GetRendererKey() + + api := goskola24api.Skola24API{ + Host: "avesta.skola24.se", + } + + _, err := api.GetTerms() + if err != nil { + fmt.Println(err.Error()) + } + + schools, _ := api.GetSchools() + + for _, school := range schools { + fmt.Println(school.AvailableData) + } + + rooms, err := api.GetRooms(schools[4], true) + if err != nil { + fmt.Println(err.Error()) + } + + fmt.Println(rooms) + + for _, room := range rooms { + fmt.Println(room.Name) + } + + fmt.Println(key) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7a38a0b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.zervo.org/zervo/GoSkola24API + +go 1.22.5 diff --git a/internal/requests/get_generic_selection.go b/internal/requests/get_generic_selection.go new file mode 100644 index 0000000..1379797 --- /dev/null +++ b/internal/requests/get_generic_selection.go @@ -0,0 +1,54 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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" + "git.zervo.org/zervo/GoSkola24API/internal/utility" + pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types" +) + +func GetGenericSelection(school pubtypes.School, filters types.RequestFilters) (_result map[string]interface{}, _error error) { + request := types.RequestSelectionBase{ + HostName: school.HostName, + UnitGuid: school.SchoolId, + Filters: filters, + } + + response, err := utility.Request(request, "get/timetable/selection") + if err != nil { + return nil, errors.New("could not get selection: " + err.Error()) + } + + // Assert the response type to a map[string]interface{} + responseMap, ok := response.(map[string]interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + + return responseMap, nil +} diff --git a/internal/requests/get_rooms.go b/internal/requests/get_rooms.go new file mode 100644 index 0000000..3e1ce24 --- /dev/null +++ b/internal/requests/get_rooms.go @@ -0,0 +1,91 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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" + "fmt" + + "git.zervo.org/zervo/GoSkola24API/internal/types" + pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types" +) + +func GetRooms(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Room, _error error) { + if checkAvailability && !school.AvailableData.HasRooms { + return nil, errors.New("availability check failed: school does not provide room data") + } + + filters := types.RequestFilters{ + Class: false, + Course: false, + Group: false, + Period: false, + Room: true, + Student: false, + Subject: false, + Teacher: false, + } + + responseMap, err := GetGenericSelection(school, filters) + if err != nil { + return nil, errors.New("failed to get rooms: " + err.Error()) + } + + fmt.Println(school) + fmt.Println(responseMap) + + // Extract rooms as []interface{} + roomsRaw, ok := responseMap["rooms"].([]interface{}) + if !ok { + return nil, errors.New("missing or invalid \"rooms\" field in response") + } + + fmt.Println(roomsRaw) + + // Convert raw rooms into usable room type + var rooms []pubtypes.Room + for _, roomRaw := range roomsRaw { + roomMap, ok := roomRaw.(map[string]interface{}) + if !ok { + return nil, errors.New("unexpected room format") + } + + // Extract fields from each room + roomName, _ := roomMap["name"].(string) + roomId, _ := roomMap["eid"].(string) + external, _ := roomMap["external"].(bool) + + // Map to struct + room := pubtypes.Room{ + Name: roomName, + RoomId: roomId, + External: external, + } + + rooms = append(rooms, room) + } + + return rooms, nil +} diff --git a/internal/requests/get_schools.go b/internal/requests/get_schools.go new file mode 100644 index 0000000..414d0a6 --- /dev/null +++ b/internal/requests/get_schools.go @@ -0,0 +1,121 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 . +*/ + +// I'm aware this code is really weird and not optimised. I changed approach multiple times in the middle of it and am too lazy to fix it. It works though. + +package requests + +import ( + "errors" + + "git.zervo.org/zervo/GoSkola24API/internal/types" + "git.zervo.org/zervo/GoSkola24API/internal/utility" + pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types" +) + +func GetSchools(api_host string) (_result []pubtypes.School, _error error) { + request := types.RequestSchools{ + GetTimetableViewerUnitsRequest: types.RequestSchoolsHost{ + HostName: api_host, + }, + } + + response, err := utility.Request(request, "services/skola24/get/timetable/viewer/units") + if err != nil { + return nil, errors.New("could not get schools: " + err.Error()) + } + + // Assert the response type to a map[string]interface{} + responseMap, ok := response.(map[string]interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + + // Assert getTimetableViewerUnitsResponse to a type + timetableMap, ok := responseMap["getTimetableViewerUnitsResponse"].(map[string]interface{}) + if !ok { + return nil, errors.New("missing or invalid \"getTimetableViewerUnitsResponse\" field in response") + } + + // Get hostname + hostname, ok := timetableMap["hostName"].(string) + if !ok { + return nil, errors.New("missing or invalid \"hostName\" field in response") + } + + // Extract units as []interface{} + unitsRaw, ok := timetableMap["units"].([]interface{}) + if !ok { + return nil, errors.New("missing or invalid \"units\" field in response") + } + + // Convert units into a proper type + var units []pubtypes.School + for _, unitRaw := range unitsRaw { + unitMap, ok := unitRaw.(map[string]interface{}) + if !ok { + return nil, errors.New("unexpected unit format") + } + + // Extract fields from each unit + unitGuid, _ := unitMap["unitGuid"].(string) + unitId, _ := unitMap["unitId"].(string) + allowCalendarExport, _ := unitMap["allowCalendarExport"].(bool) + anonMap, _ := unitMap["anonymous"].(map[string]interface{}) + + // Same for anonymous units + hasClasses, _ := anonMap["classes"].(bool) + hasCourses, _ := anonMap["courses"].(bool) + hasGroups, _ := anonMap["groups"].(bool) + hasResources, _ := anonMap["resources"].(bool) + hasRooms, _ := anonMap["rooms"].(bool) + hasStudents, _ := anonMap["students"].(bool) + hasSubjects, _ := anonMap["subjects"].(bool) + hasTeachers, _ := anonMap["teachers"].(bool) + + availableData := pubtypes.DataAvailability{ + HasClasses: hasClasses, + HasCourses: hasCourses, + HasGroups: hasGroups, + HasResources: hasResources, + HasRooms: hasRooms, + HasStudents: hasStudents, + HasSubjects: hasSubjects, + HasTeachers: hasTeachers, + } + + // Map to the struct + unit := pubtypes.School{ + Name: unitId, + SchoolId: unitGuid, + HostName: hostname, + AllowCalendarExport: allowCalendarExport, + AvailableData: availableData, + } + + units = append(units, unit) + } + + return units, nil +} diff --git a/internal/requests/get_terms.go b/internal/requests/get_terms.go new file mode 100644 index 0000000..3d7f026 --- /dev/null +++ b/internal/requests/get_terms.go @@ -0,0 +1,91 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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" + "git.zervo.org/zervo/GoSkola24API/internal/utility" + pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types" +) + +func GetTerms(api_host string) (_result pubtypes.Terms, _error error) { + request := types.RequestTerms{ + HostName: api_host, + CheckSchoolYearsFeatures: false, + } + + response, err := utility.Request(request, "get/active/school/years") + if err != nil { + return pubtypes.Terms{}, errors.New("could not get terms: " + err.Error()) + } + + // Assert the response type to a map[string]interface{} + responseMap, ok := response.(map[string]interface{}) + if !ok { + return pubtypes.Terms{}, errors.New("unexpected response type") + } + + // Assert useSchoolYearsFeatures to bool + useYears, ok := responseMap["useSchoolYearsFeatures"].(bool) + if !ok { + useYears = false + } + + // Extract the "activeSchoolYears" value using type assertion + extractedYears, ok := responseMap["activeSchoolYears"].([]interface{}) + if !ok { + return pubtypes.Terms{}, errors.New("missing or invalid \"activeSchoolYears\" field in response") + } + + var schoolTerms []pubtypes.SchoolTerm + + // Iterate over the school years + for _, year := range extractedYears { + yearMap, ok := year.(map[string]interface{}) + if !ok { + return pubtypes.Terms{}, errors.New("unexpected type in activeSchoolYears slice") + } + + // Map to the struct + schoolTerm := pubtypes.SchoolTerm{ + Start: yearMap["from"].(string), + TermId: yearMap["guid"].(string), + Name: yearMap["name"].(string), + End: yearMap["to"].(string), + } + + schoolTerms = append(schoolTerms, schoolTerm) + } + + // Assemble result + result := pubtypes.Terms{ + ActiveTerms: schoolTerms, + UseSchoolYearsFeatures: useYears, + } + + return result, nil +} diff --git a/internal/types/data_key.go b/internal/types/data_key.go new file mode 100644 index 0000000..afcff9c --- /dev/null +++ b/internal/types/data_key.go @@ -0,0 +1,29 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 DataRenderKey struct { + Key string `json:"key"` +} diff --git a/internal/types/filters.go b/internal/types/filters.go new file mode 100644 index 0000000..46f7f61 --- /dev/null +++ b/internal/types/filters.go @@ -0,0 +1,36 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 RequestFilters struct { + Class bool `json:"class"` + Course bool `json:"course"` + Group bool `json:"group"` + Period bool `json:"period"` + Room bool `json:"room"` + Student bool `json:"student"` + Subject bool `json:"subject"` + Teacher bool `json:"teacher"` +} diff --git a/internal/types/req_schools.go b/internal/types/req_schools.go new file mode 100644 index 0000000..f2e6664 --- /dev/null +++ b/internal/types/req_schools.go @@ -0,0 +1,33 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 RequestSchoolsHost struct { + HostName string `json:"hostName"` +} + +type RequestSchools struct { + GetTimetableViewerUnitsRequest RequestSchoolsHost `json:"getTimetableViewerUnitsRequest"` +} diff --git a/internal/types/req_selection_base.go b/internal/types/req_selection_base.go new file mode 100644 index 0000000..6655204 --- /dev/null +++ b/internal/types/req_selection_base.go @@ -0,0 +1,31 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 RequestSelectionBase struct { + HostName string `json:"hostName"` + UnitGuid string `json:"unitGuid"` + Filters RequestFilters `json:"filters"` +} diff --git a/internal/types/req_terms.go b/internal/types/req_terms.go new file mode 100644 index 0000000..5272014 --- /dev/null +++ b/internal/types/req_terms.go @@ -0,0 +1,30 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 RequestTerms struct { + HostName string `json:"hostName"` + CheckSchoolYearsFeatures bool `json:"checkSchoolYearsFeatures"` +} diff --git a/internal/types/response.go b/internal/types/response.go new file mode 100644 index 0000000..fc95366 --- /dev/null +++ b/internal/types/response.go @@ -0,0 +1,34 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 BaseResponse struct { + Error interface{} `json:"error"` + Data interface{} `json:"data"` + Exception interface{} `json:"exception"` + Validation []interface{} `json:"validation"` + SessionExpires interface{} `json:"sessionExpires"` + NeedSessionRefresh bool `json:"needSessionRefresh"` +} diff --git a/internal/utility/key.go b/internal/utility/key.go new file mode 100644 index 0000000..c94a163 --- /dev/null +++ b/internal/utility/key.go @@ -0,0 +1,50 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 utility + +import ( + "errors" +) + +func GetRendererKey() (_key string, _error error) { + response, err := Request(nil, "get/timetable/render/key") + if err != nil { + return "", errors.New("could not get render key: " + err.Error()) + } + + // Assert the response type to a map[string]interface{} + responseMap, ok := response.(map[string]interface{}) + if !ok { + return "", errors.New("unexpected response type") + } + + // Extract the "key" value using type assertion + keyValue, ok := responseMap["key"].(string) + if !ok { + return "", errors.New("missing or invalid \"key\" field in response") + } + + return keyValue, nil +} diff --git a/internal/utility/request.go b/internal/utility/request.go new file mode 100644 index 0000000..a0cf6a1 --- /dev/null +++ b/internal/utility/request.go @@ -0,0 +1,76 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 utility + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + + "git.zervo.org/zervo/GoSkola24API/internal/types" +) + +func Request(data any, endpoint string) (_response interface{}, _error error) { + const xscope string = "8a22163c-8662-4535-9050-bc5e1923df48" // Might need to change this + + var url string = fmt.Sprintf("https://web.skola24.se/api/%s", endpoint) + + // Enconde JSON + jsonRequest, err := json.Marshal(data) + + if err != nil { + return nil, errors.New("could not encode json: " + err.Error()) + } + + // Create the POST request + postRequest, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonRequest)) + postRequest.Header.Add("Content-Type", "application/json") + postRequest.Header.Add("X-Scope", xscope) + + if err != nil { + return nil, errors.New("could not create request: " + err.Error()) + } + + // Send the POST request + response, err := http.DefaultClient.Do(postRequest) + + if err != nil { + return nil, errors.New("request failed: " + err.Error()) + } + + // Read body + defer response.Body.Close() + bodyBytes, _ := io.ReadAll(response.Body) + + // Unmarshal response + var responseData types.BaseResponse + json.Unmarshal(bodyBytes, &responseData) + + // Return as raw bytes (let consumer do type assertion) + return responseData.Data, nil +} diff --git a/pkg/goskola24api/skola24api.go b/pkg/goskola24api/skola24api.go new file mode 100644 index 0000000..92ea490 --- /dev/null +++ b/pkg/goskola24api/skola24api.go @@ -0,0 +1,46 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 goskola24api + +import ( + "git.zervo.org/zervo/GoSkola24API/internal/requests" + pubtypes "git.zervo.org/zervo/GoSkola24API/pkg/goskola24api/types" +) + +type Skola24API struct { + Host string +} + +func (api Skola24API) GetTerms() (_result pubtypes.Terms, _error error) { + return requests.GetTerms(api.Host) +} + +func (api Skola24API) GetSchools() (_result []pubtypes.School, _error error) { + return requests.GetSchools(api.Host) +} + +func (api Skola24API) GetRooms(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Room, _error error) { + return requests.GetRooms(school, checkAvailability) +} diff --git a/pkg/goskola24api/types/rooms.go b/pkg/goskola24api/types/rooms.go new file mode 100644 index 0000000..acefb2a --- /dev/null +++ b/pkg/goskola24api/types/rooms.go @@ -0,0 +1,31 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 Room struct { + Name string `json:"name"` + RoomId string `json:"roomId"` + External bool `json:"external"` +} diff --git a/pkg/goskola24api/types/schools.go b/pkg/goskola24api/types/schools.go new file mode 100644 index 0000000..b649547 --- /dev/null +++ b/pkg/goskola24api/types/schools.go @@ -0,0 +1,44 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 School struct { + Name string `json:"name"` + SchoolId string `json:"schoolId"` + HostName string `json:"hostName"` + AllowCalendarExport bool `json:"allowCalendarExport"` + AvailableData DataAvailability `json:"availableData"` +} + +type DataAvailability struct { + HasClasses bool `json:"hasClasses"` + HasCourses bool `json:"hasCourses"` + HasGroups bool `json:"hasGroups"` + HasResources bool `json:"hasResources"` + HasRooms bool `json:"hasRooms"` + HasStudents bool `json:"hasStudents"` + HasSubjects bool `json:"hasSubjects"` + HasTeachers bool `json:"hasTeachers"` +} diff --git a/pkg/goskola24api/types/terms.go b/pkg/goskola24api/types/terms.go new file mode 100644 index 0000000..4c2fedf --- /dev/null +++ b/pkg/goskola24api/types/terms.go @@ -0,0 +1,37 @@ +/* +GoSkola24API +Copyright (C) 2024, Zervó Zadachin + +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 SchoolTerm struct { + Start string `json:"start"` + TermId string `json:"termId"` + Name string `json:"name"` + End string `json:"end"` +} + +type Terms struct { + ActiveTerms []SchoolTerm `json:"activeSchoolYears"` + UseSchoolYearsFeatures bool `json:"useSchoolYearsFeatures"` +}