/* 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" pubtypes "git.zervo.org/zervo/goskola24api/types" ) func GetTeachers(school pubtypes.School, checkAvailability bool) (_result []pubtypes.Teacher, _error error) { if checkAvailability && !school.AvailableData.HasTeachers { return nil, errors.New("availability check failed: school does not provide teacher data") } filters := types.RequestFilters{ Class: false, Course: false, Group: false, Period: false, Room: false, Student: false, Subject: false, Teacher: true, } responseMap, err := GetGenericSelection(school, filters) if err != nil { return nil, errors.New("failed to get teachers: " + err.Error()) } // Extract teachers as []interface{} teachersRaw, ok := responseMap["teachers"].([]interface{}) if !ok { return nil, errors.New("missing or invalid \"teachers\" field in response") } // Convert raw teachers into usable teacher type var teachers []pubtypes.Teacher for _, teacherRaw := range teachersRaw { teacherMap, ok := teacherRaw.(map[string]interface{}) if !ok { return nil, errors.New("unexpected room format") } // Map to struct teacher := pubtypes.Teacher{ FirstName: func() string { val, _ := teacherMap["firstName"].(string); return val }(), LastName: func() string { val, _ := teacherMap["lastName"].(string); return val }(), FullName: func() string { val, _ := teacherMap["fullName"].(string); return val }(), FriendlyId: func() string { val, _ := teacherMap["id"].(string); return val }(), TeacherId: func() string { val, _ := teacherMap["personGuid"].(string); return val }(), IsActive: func() bool { val, _ := teacherMap["isActiveUser"].(bool); return val }(), Integrity: func() bool { val, _ := teacherMap["integrity"].(bool); return val }(), Reported: func() bool { val, _ := teacherMap["reported"].(bool); return val }(), ReadOnly: func() bool { val, _ := teacherMap["readOnly"].(bool); return val }(), } teachers = append(teachers, teacher) } return teachers, nil }