Korrigiere Zählung paralleler Sprechstunden

This commit is contained in:
Gonne 2022-09-19 18:32:15 +02:00
parent e1c5ccab3a
commit d91de014e9
2 changed files with 16 additions and 8 deletions

View file

@ -40,7 +40,7 @@ func main() {
roomRepo := repositories.NewRoomRepo(db) roomRepo := repositories.NewRoomRepo(db)
courseRepo := repositories.NewCourseRepo(db) courseRepo := repositories.NewCourseRepo(db)
tutorRepo := repositories.NewTutorRepo(db) tutorRepo := repositories.NewTutorRepo(db)
officeHourRepo := repositories.NewOfficeHourRepo(db, roomRepo, tutorRepo, courseRepo) officeHourRepo := repositories.NewOfficeHourRepo(db, roomRepo, tutorRepo, courseRepo, conf)
requestRepo := repositories.NewRequestRepo(db, officeHourRepo, conf) requestRepo := repositories.NewRequestRepo(db, officeHourRepo, conf)
h := controllers.NewBaseHandler(roomRepo, officeHourRepo, courseRepo, tutorRepo, requestRepo, conf) h := controllers.NewBaseHandler(roomRepo, officeHourRepo, courseRepo, tutorRepo, requestRepo, conf)

View file

@ -4,6 +4,8 @@ package repositories
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"log"
"sprechstundentool/config"
"sprechstundentool/models" "sprechstundentool/models"
) )
@ -12,14 +14,16 @@ type OfficeHourRepo struct {
roomRepo *RoomRepo roomRepo *RoomRepo
tutorRepo *TutorRepo tutorRepo *TutorRepo
courseRepo *CourseRepo courseRepo *CourseRepo
config config.Config
} }
func NewOfficeHourRepo(db *sql.DB, roomRepo *RoomRepo, tutorRepo *TutorRepo, courseRepo *CourseRepo) *OfficeHourRepo { func NewOfficeHourRepo(db *sql.DB, roomRepo *RoomRepo, tutorRepo *TutorRepo, courseRepo *CourseRepo, conf config.Config) *OfficeHourRepo {
return &OfficeHourRepo{ return &OfficeHourRepo{
db: db, db: db,
roomRepo: roomRepo, roomRepo: roomRepo,
tutorRepo: tutorRepo, tutorRepo: tutorRepo,
courseRepo: courseRepo, courseRepo: courseRepo,
config: conf,
} }
} }
@ -168,14 +172,18 @@ func (r *OfficeHourRepo) NumberByTimeSpanAndRoom(date models.Date, duration int,
return 0, err return 0, err
} }
var count int var count int
for _, officeHour := range officeHours { // iterate over all points in the new officehour to get the maximum parallel officehours
if models.DateLess(models.GetEndDate(officeHour.Date, officeHour.Duration, false), date) || models.GetEndDate(officeHour.Date, officeHour.Duration, false) == date { for minute := 0; minute < duration; minute += r.config.Date.MinuteGranularity {
continue var minuteCount int = 0
for _, officeHour := range officeHours {
// increase count if officehour starts before this point in time and ends later
if models.DateLess(officeHour.Date, models.GetEndDate(date, minute, false)) && models.DateLess(models.GetEndDate(date, minute, false), models.GetEndDate(officeHour.Date, officeHour.Duration, false)) {
minuteCount += 1
}
} }
if models.DateLess(models.GetEndDate(date, duration, false), officeHour.Date) || models.GetEndDate(date, duration, false) == officeHour.Date { if minuteCount > count {
continue count = minuteCount
} }
count += 1
} }
return count, nil return count, nil
} }