Continue work on search query, various API calls

This commit is contained in:
2024-01-07 08:44:42 -06:00
parent 1c5b3a1b6d
commit b331433d8d

109
api.go
View File

@@ -11,9 +11,7 @@ import (
log "github.com/rs/zerolog/log" log "github.com/rs/zerolog/log"
) )
var ( var sessionID string = RandomString(5) + Nonce()
sessionID string = RandomString(5) + Nonce()
)
// BannerTerm represents a term in the Banner system // BannerTerm represents a term in the Banner system
type BannerTerm struct { type BannerTerm struct {
@@ -46,7 +44,6 @@ func GetTerms(search string, offset int, max int) ([]BannerTerm, error) {
// print the response body // print the response body
defer res.Body.Close() defer res.Body.Close()
body, _ := io.ReadAll(res.Body) body, _ := io.ReadAll(res.Body)
log.Printf("Response: %s", body)
terms := make([]BannerTerm, 0, 10) terms := make([]BannerTerm, 0, 10)
json.Unmarshal(body, &terms) json.Unmarshal(body, &terms)
@@ -58,11 +55,8 @@ func GetTerms(search string, offset int, max int) ([]BannerTerm, error) {
return terms, nil return terms, nil
} }
type TermParts struct {
}
// GET /classSearch/get_partOfTerm?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070282288 // GET /classSearch/get_partOfTerm?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070282288
func GetPartOfTerms(search string, term int, offset int, max int) ([]TermParts, error) { func GetPartOfTerms(search string, term int, offset int, max int) ([]BannerTerm, error) {
req := BuildRequest("GET", "/classSearch/get_partOfTerm", map[string]string{ req := BuildRequest("GET", "/classSearch/get_partOfTerm", map[string]string{
"searchTerm": search, "searchTerm": search,
"term": strconv.Itoa(term), "term": strconv.Itoa(term),
@@ -82,11 +76,20 @@ func GetPartOfTerms(search string, term int, offset int, max int) ([]TermParts,
log.Printf("ERR Response was not JSON: %s", res.Header.Get("Content-Type")) log.Printf("ERR Response was not JSON: %s", res.Header.Get("Content-Type"))
} }
return make([]TermParts, 0), nil // print the response body
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
terms := make([]BannerTerm, 0, 10)
err = json.Unmarshal(body, &terms)
if err != nil {
return nil, err
}
return terms, nil
} }
type Instructor struct { type Instructor struct{}
}
// GET /classSearch/get_instructor?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1701951338584 // GET /classSearch/get_instructor?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1701951338584
func GetInstructor(search string, term int, offset int, max int) []Instructor { func GetInstructor(search string, term int, offset int, max int) []Instructor {
@@ -112,8 +115,7 @@ func GetInstructor(search string, term int, offset int, max int) []Instructor {
return make([]Instructor, 0) return make([]Instructor, 0)
} }
type ClassDetails struct { type ClassDetails struct{}
}
func GetClassDetails(term int, crn int) *ClassDetails { func GetClassDetails(term int, crn int) *ClassDetails {
body, _ := json.Marshal(map[string]string{ body, _ := json.Marshal(map[string]string{
@@ -136,21 +138,56 @@ func GetClassDetails(term int, crn int) *ClassDetails {
return &ClassDetails{} return &ClassDetails{}
} }
type SearchResult struct {
Success bool `json:"success"`
TotalCount int `json:"totalCount"`
PageOffset int `json:"pageOffset"`
PageMaxSize int `json:"pageMaxSize"`
PathMode string `json:"pathMode"`
SearchResultsConfig []struct {
Config string `json:"config"`
Display string `json:"display"`
} `json:"searchResultsConfig"`
Data []struct {
Id int `json:"id"`
Term string `json:"term"`
TermDesc string `json:"termDesc"`
CourseReferenceNumber string `json:"courseReferenceNumber"`
PartOfTerm string `json:"partOfTerm"`
CourseNumber string `json:"courseNumber"`
Subject string `json:"subject"`
SubjectDescription string `json:"subjectDescription"`
SequenceNumber string `json:"sequenceNumber"`
CampusDescription string `json:"campusDescription"`
ScheduleTypeDescription string `json:"scheduleTypeDescription"`
CourseTitle string `json:"courseTitle"`
CreditHours int `json:"creditHours"`
MaximumEnrollment int `json:"maximumEnrollment"`
Enrollment int `json:"enrollment"`
SeatsAvailable int `json:"seatsAvailable"`
WaitCapacity int `json:"waitCapacity"`
WaitCount int `json:"waitCount"`
CrossList *string `json:"crossList"`
CrossListCapacity *int `json:"crossListCapacity"`
} `json:"data"`
}
// 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_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 // 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(subject string, keyword string, term string, startDate time.Time, endDate time.Time, offset int, max int, sort string, sortDescending bool) []string { func Search(query Query, offset int, max int, sort string, sortDescending bool) *SearchResult {
req := BuildRequest("GET", "/classSearch/get_subject", map[string]string{ params := query.Paramify()
"txt_subject": subject,
"txt_keywordlike": keyword, params["txt_term"] = "202420" // TODO: Make this automatic but dynamically specifiable
"txt_term": term, params["uniqueSessionId"] = sessionID
"startDatepicker": "", params["pageOffset"] = strconv.Itoa(offset)
"endDatepicker": "", params["pageMaxSize"] = strconv.Itoa(max)
"uniqueSessionId": sessionID, params["sortColumn"] = sort
"pageOffset": strconv.Itoa(offset), params["sortDirection"] = "asc"
"pageMaxSize": strconv.Itoa(max), // These dates are not available for usage anywhere in the UI, but are included in every query
"sortColumn": "subjectDescription", params["startDatepicker"] = ""
"sortDirection": "asc", params["endDatepicker"] = ""
})
req := BuildRequest("GET", "/classSearch/get_subject", params)
res, err := DoRequest(req) res, err := DoRequest(req)
if err != nil { if err != nil {
@@ -162,11 +199,19 @@ func Search(subject string, keyword string, term string, startDate time.Time, en
log.Printf("ERR Response was not JSON: %s", res.Header.Get("Content-Type")) log.Printf("ERR Response was not JSON: %s", res.Header.Get("Content-Type"))
} }
return make([]string, 0) body, _ := io.ReadAll(res.Body)
var result SearchResult
err = json.Unmarshal(body, &result)
if err != nil {
return nil
}
return &result
} }
type Subject struct { type Subject struct{}
}
// GET /classSearch/get_subject?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702069787420 // GET /classSearch/get_subject?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702069787420
func GetSubjects(search string, term int, offset int, max int) []Subject { func GetSubjects(search string, term int, offset int, max int) []Subject {
@@ -192,8 +237,7 @@ func GetSubjects(search string, term int, offset int, max int) []Subject {
return make([]Subject, 0) return make([]Subject, 0)
} }
type Campus struct { type Campus struct{}
}
// /classSearch/get_campus?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070341071 // /classSearch/get_campus?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070341071
func GetCampuses(search string, term int, offset int, max int) []Campus { func GetCampuses(search string, term int, offset int, max int) []Campus {
@@ -220,8 +264,7 @@ func GetCampuses(search string, term int, offset int, max int) []Campus {
return make([]Campus, 0) return make([]Campus, 0)
} }
type InstructionalMethod struct { type InstructionalMethod struct{}
}
// / classSearch/get_instructionalMethod?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070364082 // / classSearch/get_instructionalMethod?searchTerm=&term=202420&offset=1&max=10&uniqueSessionId=4bzai1701944879219&_=1702070364082
func GetInstructionalMethods(search string, term int, offset int, max int) ([]InstructionalMethod, error) { func GetInstructionalMethods(search string, term int, offset int, max int) ([]InstructionalMethod, error) {