Get closer to unified MeetingTimeResponse parsing

This commit is contained in:
2024-01-18 02:20:37 -06:00
parent 26bdad9c94
commit 3464208d9c
3 changed files with 38 additions and 40 deletions

72
api.go
View File

@@ -192,32 +192,39 @@ func GetClassDetails(term int, crn int) *ClassDetails {
return &ClassDetails{} return &ClassDetails{}
} }
type MeetingTimeInnerResponse struct { type MeetingTimeResponse struct {
Category string `json:"category"` Category *string `json:"category"`
Class string `json:"class"` Class string `json:"class"`
StartDate string `json:"startDate"` CourseReferenceNumber string `json:"courseReferenceNumber"`
EndDate string `json:"endDate"` Faculty []struct{}
BeginTime string `json:"beginTime"` MeetingTime struct {
EndTime string `json:"endTime"` Category string `json:"category"`
Room string `json:"room"` Class string `json:"class"`
Term string `json:"term"` StartDate string `json:"startDate"`
Building string `json:"building"` EndDate string `json:"endDate"`
BuildingDescription string `json:"buildingDescription"` BeginTime string `json:"beginTime"`
Campus string `json:"campus"` EndTime string `json:"endTime"`
CampusDescription string `json:"campusDescription"` Room string `json:"room"`
CourseReferenceNumber string `json:"courseReferenceNumber"` Term string `json:"term"`
CreditHourSession float64 `json:"creditHourSession"` Building string `json:"building"`
HoursWeek float64 `json:"hoursWeek"` BuildingDescription string `json:"buildingDescription"`
MeetingScheduleType string `json:"meetingScheduleType"` Campus string `json:"campus"`
MeetingType string `json:"meetingType"` CampusDescription string `json:"campusDescription"`
MeetingTypeDescription string `json:"meetingTypeDescription"` CourseReferenceNumber string `json:"courseReferenceNumber"`
Monday bool `json:"monday"` CreditHourSession float64 `json:"creditHourSession"`
Tuesday bool `json:"tuesday"` HoursWeek float64 `json:"hoursWeek"`
Wednesday bool `json:"wednesday"` MeetingScheduleType string `json:"meetingScheduleType"`
Thursday bool `json:"thursday"` MeetingType string `json:"meetingType"`
Friday bool `json:"friday"` MeetingTypeDescription string `json:"meetingTypeDescription"`
Saturday bool `json:"saturday"` Monday bool `json:"monday"`
Sunday bool `json:"sunday"` Tuesday bool `json:"tuesday"`
Wednesday bool `json:"wednesday"`
Thursday bool `json:"thursday"`
Friday bool `json:"friday"`
Saturday bool `json:"saturday"`
Sunday bool `json:"sunday"`
} `json:"meetingTime"`
Term string `json:"term"`
} }
type SearchResult struct { type SearchResult struct {
@@ -272,14 +279,7 @@ type SearchResult struct {
Primary bool `json:"primaryIndicator"` Primary bool `json:"primaryIndicator"`
Term string `json:"term"` Term string `json:"term"`
} `json:"faculty"` } `json:"faculty"`
MeetingsFaculty []struct { MeetingsFaculty []MeetingTimeResponse `json:"meetingsFaculty"`
Category *string `json:"category"`
Class string `json:"class"`
CourseReferenceNumber string `json:"courseReferenceNumber"`
Faculty []struct{}
MeetingTime MeetingTimeInnerResponse `json:"meetingTime"`
Term string `json:"term"`
}
} `json:"data"` } `json:"data"`
} }
@@ -404,7 +404,7 @@ func GetInstructionalMethods(search string, term int, offset int, max int) ([]In
// GetCourseMeetingTime retrieves the meeting time information for a course based on the given term and course reference number (CRN). // 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. // 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. // The function returns a MeetingTimeResponse struct containing the extracted information.
func GetCourseMeetingTime(term int, crn int) (*MeetingTimeResponse, error) { func GetCourseMeetingTime(term int, crn int) (*PrettyMeetingTimeResponse, error) {
req := BuildRequest("GET", "/searchResults/getFacultyMeetingTimes", map[string]string{ req := BuildRequest("GET", "/searchResults/getFacultyMeetingTimes", map[string]string{
"term": strconv.Itoa(term), "term": strconv.Itoa(term),
"courseReferenceNumber": strconv.Itoa(crn), "courseReferenceNumber": strconv.Itoa(crn),
@@ -483,7 +483,7 @@ func GetCourseMeetingTime(term int, crn int) (*MeetingTimeResponse, error) {
}) })
} }
return &MeetingTimeResponse{ return &PrettyMeetingTimeResponse{
faculty: faculty, faculty: faculty,
weekdays: weekdays, weekdays: weekdays,
campus: campus, campus: campus,

View File

@@ -189,7 +189,6 @@ func main() {
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Cannot get existing commands") log.Fatal().Err(err).Msg("Cannot get existing commands")
} }
newCommands, err := session.ApplicationCommandBulkOverwrite(session.State.User.ID, guildTarget, commandDefinitions) newCommands, err := session.ApplicationCommandBulkOverwrite(session.State.User.ID, guildTarget, commandDefinitions)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Cannot register commands") log.Fatal().Err(err).Msg("Cannot register commands")
@@ -217,11 +216,10 @@ func main() {
log.Info().Msg("Command registration complete") log.Info().Msg("Command registration complete")
// Fetch terms on startup // Fetch terms on startup
terms, err := GetTerms("", 1, 10) _, err = GetTerms("", 1, 10)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Cannot get terms") log.Fatal().Err(err).Msg("Cannot get terms")
} }
log.Debug().Interface("terms", terms).Msg("Terms")
// Term Select Pre-Search POST // Term Select Pre-Search POST
var termSelect string var termSelect string

View File

@@ -12,7 +12,7 @@ type MeetingTimeFaculty struct {
primary bool primary bool
} }
type MeetingTimeResponse struct { type PrettyMeetingTimeResponse struct {
faculty []MeetingTimeFaculty faculty []MeetingTimeFaculty
weekdays map[time.Weekday]bool weekdays map[time.Weekday]bool
campus string campus string