Skip to content

Commit

Permalink
Add Url field on timetable
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Nov 22, 2023
1 parent fb948b8 commit f1fd36b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bot/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func lecturesCallback(bot *tgbotapi.BotAPI, update *tgbotapi.Update, callback_te
timetableKey := callback_text[len("lectures_"):strings.Index(callback_text, "_y_")]

timetable := model.Timetables[timetableKey]
response, err := commands.GetTimeTable(timetable.Type, timetable.Name, timetable.Curriculum, year, timeForLectures)
response, err := commands.GetTimeTable(timetable.Type, timetable.Name, timetable.Curriculum, timetable.Url, year, timeForLectures)
if err != nil {
log.Printf("Error [GetTimeTable]: %s\n", err)
}
Expand Down
4 changes: 3 additions & 1 deletion commands/uni.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ func (t *LezioniTime) UnmarshalJSON(data []byte) error {

// GetTimeTable returns an HTML string containing the timetable for the given
// course on the given date. Returns an empty string if there are no lessons.
func GetTimeTable(courseType, courseName string, curriculum string, year int, day time.Time) (string, error) {
func GetTimeTable(courseType, courseName string, curriculum string, url string, year int, day time.Time) (string, error) {

interval := &timetable.Interval{Start: day, End: day}
// FIXME: after the edit on unibo-go the line below will be valid
// events, err := timetable.FetchTimetable(courseType, courseName, curriculum, url, year, interval)
events, err := timetable.FetchTimetable(courseType, courseName, curriculum, year, interval)
if err != nil {
log.Printf("Error getting timetable: %s\n", err)
Expand Down
5 changes: 3 additions & 2 deletions commands/uni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestGetTimeTable(t *testing.T) {
year int
day time.Time
curriculum string
url string
}
tests := []struct {
name string
Expand Down Expand Up @@ -146,7 +147,7 @@ func TestGetTimeTable(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetTimeTable(tt.args.courseType, tt.args.courseName, tt.args.curriculum, tt.args.year, tt.args.day)
got, err := GetTimeTable(tt.args.courseType, tt.args.courseName, tt.args.curriculum, tt.args.url, tt.args.year, tt.args.day)
if err != nil && !tt.error {
t.Errorf("GetTimeTable() error = %v", err)
return
Expand All @@ -164,7 +165,7 @@ func TestGetTimeTable(t *testing.T) {
func TestWeekend(t *testing.T) {

date := time.Date(2023, 3, 11, 0, 0, 0, 0, time.UTC)
result, err := GetTimeTable("laurea", "informatica", "", 1, date)
result, err := GetTimeTable("laurea", "informatica", "", "orario-lezioni", 1, date)
if err != nil {
t.Fatalf("Error while getting timetable: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ type Curriculum struct {
type Timetable struct {
Course string `json:"course"` // Course title
Name string `json:"name"` // Course name
Type string `json:"type"` // Type (laurea|magistrale)
Type string `json:"type"` // Type (laurea|magistrale|2cycle)
Curriculum string `json:"curricula"` // Curriculum
Url string `json:"url"`
}

// SECTION ACTION STRUCTS DATA
Expand Down

0 comments on commit f1fd36b

Please sign in to comment.