fixed db query and scheduled update process

This commit is contained in:
masterelmar
2023-10-08 20:44:07 +02:00
parent e8a94bdff4
commit 60eb4e34f6
3 changed files with 11 additions and 3 deletions

View File

@@ -16,7 +16,7 @@ func AddSchedules(app *pocketbase.PocketBase) {
// Every hour update all courses (5 segments - minute, hour, day, month, weekday) "0 * * * *"
// Every three hours update all courses (5 segments - minute, hour, day, month, weekday) "0 */3 * * *"
// Every 10 minutes update all courses (5 segments - minute, hour, day, month, weekday) "*/10 * * * *"
scheduler.MustAdd("updateCourse", "*/10 * * * *", func() {
scheduler.MustAdd("updateCourse", "*/30 * * * *", func() {
courses := events.GetAllCourses(app)

View File

@@ -106,7 +106,7 @@ func GetAllModulesForCourse(app *pocketbase.PocketBase, course string, semester
var events model.Events
// get all events from event records in the events collection
err := app.Dao().DB().Select("*").From("events").Where(dbx.NewExp("course = {:course} AND semester = {:semester}", dbx.Params{"course": course, "semester": semester})).Distinct(true).All(&events)
err := app.Dao().DB().Select("*").From("events").Where(dbx.NewExp("course = {:course} AND semester = {:semester}", dbx.Params{"course": course, "semester": semester})).GroupBy("Name").Distinct(true).All(&events)
if err != nil {
print("Error while getting events from database: ", err)
return nil, err

View File

@@ -105,9 +105,17 @@ func UpdateModulesForCourse(app *pocketbase.PocketBase, course string) error {
//get all events for the course and the semester
events, err := db.GetAllModulesForCourse(app, course, "ws")
if err != nil {
return apis.NewNotFoundError("Events could not be found", err)
return apis.NewNotFoundError("Events for winter semester could not be found", err)
}
// append all events for the course and the semester to the events array for ss
summerEvents, err := db.GetAllModulesForCourse(app, course, "ss")
if err != nil {
return apis.NewNotFoundError("Events for summer semester could not be found", err)
}
events = append(events, summerEvents...)
//if there are no events in the database, save the new events
if len(events) == 0 {
_, dbError = db.SaveEvents(seminarGroups, collection, app)