feat:#36 added new event grpc message

This commit is contained in:
Elmar Kresse
2024-06-18 12:50:21 +02:00
parent 56e77630b5
commit 08140b5802
14 changed files with 510 additions and 50 deletions

View File

@@ -131,25 +131,37 @@ func findEventByDayWeekStartEndNameCourse(event model.Event, course string, dao
}
}
func buildIcalQueryForModules(modules []model.FeedCollection) dbx.Expression {
func buildIcalQueryForModules(modulesUuid []string) dbx.Expression {
// check uuids against sql injection
// uuids are generated by the system and are not user input
// following the pattern of only containing alphanumeric characters and dashes
for _, moduleUuid := range modulesUuid {
if !IsSafeIdentifier(moduleUuid) {
slog.Warn("Module UUID is not safe: ", "moduleUuid", moduleUuid)
return dbx.HashExp{}
}
}
// build where conditions for each module
//first check if modules is empty
if len(modules) == 0 {
if len(modulesUuid) == 0 {
return dbx.HashExp{}
}
//second check if modules has only one element
if len(modules) == 1 {
return dbx.HashExp{"uuid": modules[0].UUID}
if len(modulesUuid) == 1 {
return dbx.HashExp{"uuid": modulesUuid[0]}
}
//third check if modules has more than one element
var wheres []dbx.Expression
for _, module := range modules {
where := dbx.HashExp{"uuid": module.UUID}
for _, moduleUuid := range modulesUuid {
where := dbx.HashExp{"uuid": moduleUuid}
wheres = append(wheres, where)
}
@@ -162,18 +174,18 @@ func buildIcalQueryForModules(modules []model.FeedCollection) dbx.Expression {
// GetPlanForModules returns all events for the given modules with the given course
// used for the ical feed
func GetPlanForModules(app *pocketbase.PocketBase, modules map[string]model.FeedCollection) (model.Events, error) {
func GetPlanForModules(app *pocketbase.PocketBase, modules []string) (model.Events, error) {
var events model.Events
modulesArray := make([]model.FeedCollection, 0, len(modules))
modulesArray := make([]string, 0, len(modules))
for _, value := range modules {
modulesArray = append(modulesArray, value)
}
// iterate over modules in 100 batch sizes
for i := 0; i < len(modules); i += 100 {
var moduleBatch []model.FeedCollection
var moduleBatch []string
if i+100 > len(modules) {
moduleBatch = modulesArray[i:]