mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-08 12:47:46 +02:00
feat:#36 added new event grpc message
This commit is contained in:
@@ -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:]
|
||||
|
Reference in New Issue
Block a user