mirror of
https://github.com/Xevion/banner.git
synced 2025-12-08 14:06:27 -06:00
Include offset/max in Query data, improve range build fn's
This commit is contained in:
4
api.go
4
api.go
@@ -174,13 +174,11 @@ type SearchResult struct {
|
||||
|
||||
// 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(query Query, offset int, max int, sort string, sortDescending bool) (*SearchResult, error) {
|
||||
func Search(query *Query, sort string, sortDescending bool) (*SearchResult, error) {
|
||||
params := query.Paramify()
|
||||
|
||||
params["txt_term"] = "202420" // TODO: Make this automatic but dynamically specifiable
|
||||
params["uniqueSessionId"] = sessionID
|
||||
params["pageOffset"] = strconv.Itoa(offset)
|
||||
params["pageMaxSize"] = strconv.Itoa(max)
|
||||
params["sortColumn"] = sort
|
||||
params["sortDirection"] = "asc"
|
||||
// These dates are not available for usage anywhere in the UI, but are included in every query
|
||||
|
||||
48
search.go
48
search.go
@@ -20,7 +20,10 @@ type Query struct {
|
||||
instructor *[]uint64 // e.g. [27957, 27961]
|
||||
startTime *time.Duration
|
||||
endTime *time.Duration
|
||||
creditHours *Range
|
||||
minCredits *int
|
||||
maxCredits *int
|
||||
offset int
|
||||
maxResults int
|
||||
courseNumberRange *Range
|
||||
}
|
||||
|
||||
@@ -98,13 +101,36 @@ func (q *Query) EndTime(endTime time.Duration) *Query {
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *Query) CreditHours(creditHours Range) *Query {
|
||||
q.creditHours = &creditHours
|
||||
func (q *Query) Credits(low int, high int) *Query {
|
||||
q.minCredits = &low
|
||||
q.maxCredits = &high
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *Query) CourseNumberRange(courseNumberRange Range) *Query {
|
||||
q.courseNumberRange = &courseNumberRange
|
||||
func (q *Query) MinCredits(value int) *Query {
|
||||
q.minCredits = &value
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *Query) MaxCredits(value int) *Query {
|
||||
q.maxCredits = &value
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *Query) CourseNumbers(low int, high int) *Query {
|
||||
q.courseNumberRange = &Range{low, high}
|
||||
return q
|
||||
}
|
||||
|
||||
// Offset sets the offset for the query, allowing for pagination
|
||||
func (q *Query) Offset(offset int) *Query {
|
||||
q.offset = offset
|
||||
return q
|
||||
}
|
||||
|
||||
// MaxResults sets the maximum number of results for the query
|
||||
func (q *Query) MaxResults(maxResults int) *Query {
|
||||
q.maxResults = maxResults
|
||||
return q
|
||||
}
|
||||
|
||||
@@ -194,9 +220,12 @@ func (q *Query) Paramify() map[string]string {
|
||||
params["select_end_ampm"] = meridiem
|
||||
}
|
||||
|
||||
if q.creditHours != nil {
|
||||
params["txt_credithourlow"] = strconv.Itoa(q.creditHours.Low)
|
||||
params["txt_credithourhigh"] = strconv.Itoa(q.creditHours.High)
|
||||
if q.minCredits != nil {
|
||||
params["txt_credithourlow"] = strconv.Itoa(*q.minCredits)
|
||||
}
|
||||
|
||||
if q.maxCredits != nil {
|
||||
params["txt_credithourhigh"] = strconv.Itoa(*q.maxCredits)
|
||||
}
|
||||
|
||||
if q.courseNumberRange != nil {
|
||||
@@ -204,5 +233,8 @@ func (q *Query) Paramify() map[string]string {
|
||||
params["txt_course_number_range_to"] = strconv.Itoa(q.courseNumberRange.High)
|
||||
}
|
||||
|
||||
params["pageOffset"] = strconv.Itoa(q.offset)
|
||||
params["pageMaxSize"] = strconv.Itoa(q.maxResults)
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user