mirror of
https://github.com/Xevion/banner.git
synced 2025-12-09 06:06:31 -06:00
Begin scaffolding remaining API routes
This commit is contained in:
126
api.go
126
api.go
@@ -1,37 +1,140 @@
|
|||||||
package banner
|
package banner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getCourseMeetingTime(term int, crn int) MeetingTimeResponse {
|
var (
|
||||||
url := buildURL("searchResults/getFacultyMeetingTimes", map[string]string{
|
sessionID string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
sessionID = RandomString(5) + strconv.Itoa(int(time.Now().UnixMilli()))
|
||||||
|
log.Printf("Session ID: %s", sessionID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /classSearch/getTerms?searchTerm=&offset=1&max=10&_=1702069154094
|
||||||
|
func GetTerms() {
|
||||||
|
req := BuildRequest("GET", "classSearch/getTerms", map[string]string{
|
||||||
|
"searchTerm": "",
|
||||||
|
"offset": "1",
|
||||||
|
"max": "10",
|
||||||
|
"_": strconv.Itoa(int(time.Now().UnixMilli())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /classSearch/get_partOfTerm?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070282288
|
||||||
|
func GetPartOfTerms() {
|
||||||
|
req := BuildRequest("GET", "classSearch/get_partOfTerm", map[string]string{
|
||||||
|
"searchTerm": "",
|
||||||
|
"term": "202420",
|
||||||
|
"offset": "1",
|
||||||
|
"max": "10",
|
||||||
|
"uniqueSessionId": sessionID,
|
||||||
|
"_": strconv.Itoa(int(time.Now().UnixMilli())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /classSearch/get_instructor?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1701951338584
|
||||||
|
func GetInstructor() {
|
||||||
|
req := BuildRequest("GET", "classSearch/get_instructor", map[string]string{
|
||||||
|
"searchTerm": "",
|
||||||
|
"term": "202420",
|
||||||
|
"offset": "1",
|
||||||
|
"max": "10",
|
||||||
|
"uniqueSessionId": sessionID,
|
||||||
|
"_": strconv.Itoa(int(time.Now().UnixMilli())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetClassDetails() {
|
||||||
|
body, _ := json.Marshal(map[string]string{
|
||||||
|
"term": "202420",
|
||||||
|
"courseReferenceNumber": "36522",
|
||||||
|
"first": "first",
|
||||||
|
})
|
||||||
|
req := BuildRequestWithBody("GET", "searchResults/getClassDetails", nil, bytes.NewBuffer(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /searchResults/searchResults?txt_instructor=77521&txt_term=202420&startDatepicker=&endDatepicker=&uniqueSessionId=4bzai1701944879219&pageOffset=0&pageMaxSize=10&sortColumn=subjectDescription&sortDirection=asc
|
||||||
|
// GET /searchResults/searchResults?txt_subject=CS&txt_keywordlike=Application&txt_term=202420&startDatepicker=&endDatepicker=&uniqueSessionId=4bzai1701944879219&pageOffset=0&pageMaxSize=10&sortColumn=subjectDescription&sortDirection=asc
|
||||||
|
func Search() {
|
||||||
|
req := BuildRequest("GET", "classSearch/get_subject", map[string]string{
|
||||||
|
"txt_subject": "CS",
|
||||||
|
"txt_keywordlike": "Application",
|
||||||
|
"txt_term": "202420",
|
||||||
|
"startDatepicker": "",
|
||||||
|
"endDatepicker": "",
|
||||||
|
"uniqueSessionId": sessionID,
|
||||||
|
"pageOffset": "0",
|
||||||
|
"pageMaxSize": "10",
|
||||||
|
"sortColumn": "subjectDescription",
|
||||||
|
"sortDirection": "asc",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /classSearch/get_subject?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702069787420
|
||||||
|
func GetSubjects() {
|
||||||
|
req := BuildRequest("GET", "classSearch/get_subject", map[string]string{
|
||||||
|
"searchTerm": "",
|
||||||
|
"term": "202420",
|
||||||
|
"offset": "1",
|
||||||
|
"max": "10",
|
||||||
|
"uniqueSessionId": sessionID,
|
||||||
|
"_": "1702069787420",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// /classSearch/get_campus?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070341071
|
||||||
|
func GetCampuses() {
|
||||||
|
req := BuildRequest("GET", "classSearch/get_campus", map[string]string{
|
||||||
|
"searchTerm": "",
|
||||||
|
"term": "202420",
|
||||||
|
"offset": "1",
|
||||||
|
"max": "10",
|
||||||
|
"uniqueSessionId": sessionID,
|
||||||
|
"_": strconv.Itoa(int(time.Now().UnixMilli())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// / classSearch/get_instructionalMethod?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070364082
|
||||||
|
func GetInstructionalMethods() {
|
||||||
|
req := BuildRequest("GET", "classSearch/get_instructionalMethod", map[string]string{
|
||||||
|
"searchTerm": "",
|
||||||
|
"term": "202420",
|
||||||
|
"offset": "1",
|
||||||
|
"max": "10",
|
||||||
|
"uniqueSessionId": sessionID,
|
||||||
|
"_": strconv.Itoa(int(time.Now().UnixMilli())),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCourseMeetingTime retrieves the meeting time information for a course based on the given term and course reference number (CRN).
|
||||||
|
// It makes an HTTP GET request to the appropriate API endpoint and parses the response to extract the meeting time data.
|
||||||
|
// The function returns a MeetingTimeResponse struct containing the extracted information.
|
||||||
|
func GetCourseMeetingTime(term int, crn int) MeetingTimeResponse {
|
||||||
|
req := BuildRequest("GET", "searchResults/getFacultyMeetingTimes", map[string]string{
|
||||||
"term": strconv.Itoa(term),
|
"term": strconv.Itoa(term),
|
||||||
"courseReferenceNumber": strconv.Itoa(crn),
|
"courseReferenceNumber": strconv.Itoa(crn),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Build the request
|
log.Printf("GET %s", req.URL.String())
|
||||||
log.Printf("GET %s", url)
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
AddUserAgent(req)
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assert that the response is JSON
|
||||||
if !ContainsContentType(resp.Header.Get("Content-Type"), "application/json") {
|
if !ContainsContentType(resp.Header.Get("Content-Type"), "application/json") {
|
||||||
log.Fatalf("Response was not JSON: %s", resp.Header.Get("Content-Type"))
|
log.Fatalf("Response was not JSON: %s", resp.Header.Get("Content-Type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read the response body into JSON
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
var body map[string][]map[string]interface{}
|
var body map[string][]map[string]interface{}
|
||||||
err = json.NewDecoder(resp.Body).Decode(&body)
|
err = json.NewDecoder(resp.Body).Decode(&body)
|
||||||
@@ -53,6 +156,7 @@ func getCourseMeetingTime(term int, crn int) MeetingTimeResponse {
|
|||||||
dayActive := meetingTimeMap[strings.ToLower(day.String())].(bool)
|
dayActive := meetingTimeMap[strings.ToLower(day.String())].(bool)
|
||||||
weekdays[day] = dayActive
|
weekdays[day] = dayActive
|
||||||
}
|
}
|
||||||
|
|
||||||
meetingScheduleType := meetingTimeMap["meetingScheduleType"].(string)
|
meetingScheduleType := meetingTimeMap["meetingScheduleType"].(string)
|
||||||
meetingType := meetingTimeMap["meetingType"].(string)
|
meetingType := meetingTimeMap["meetingType"].(string)
|
||||||
meetingTypeDescription := meetingTimeMap["meetingTypeDescription"].(string)
|
meetingTypeDescription := meetingTimeMap["meetingTypeDescription"].(string)
|
||||||
|
|||||||
Reference in New Issue
Block a user