This commit is contained in:
Gonne 2022-09-19 18:51:51 +02:00
parent d91de014e9
commit 02cac422f4
4 changed files with 17 additions and 18 deletions

View file

@ -90,7 +90,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
errors = append(errors, fmt.Sprintf("Sprechstunden dürfen nur alle %d Minuten starten.", b.config.Date.MinuteGranularity))
}
}
date := models.Date{week, day, hour, minute}
date := models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
duration, err := strconv.Atoi(req.FormValue("dauer"))
if err != nil {
errors = append(errors, "Die Dauer muss eine ganze Zahl sein.")
@ -106,7 +106,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
}
email, err := mail.ParseAddress(req.FormValue("email"))
if err != nil {
email = &mail.Address{"", req.FormValue("email")}
email = &mail.Address{Name: "", Address: req.FormValue("email")}
errors = append(errors, "Mailaddresse konnte nicht geparst werden.")
} else if !strings.HasSuffix(email.Address, b.config.Tutor.MailSuffix) {
errors = append(errors, fmt.Sprintf("Mailaddresse muss auf „%s“ enden.", b.config.Tutor.MailSuffix))
@ -137,14 +137,14 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
}
b.writeAddOfficeHourMask(w, req, data)
} else {
officeHour := models.OfficeHour{0,
models.Tutor{0, name, email.Address},
date,
room,
course,
info,
false,
duration,
officeHour := models.OfficeHour{Id: 0,
Tutor: models.Tutor{Id: 0, Name: name, Email: email.Address},
Date: date,
Room: room,
Course: course,
Info: info,
Active: false,
Duration: duration,
}
id, err := b.officeHourRepo.Add(officeHour)
if err != nil {

View file

@ -59,16 +59,16 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
}
for day := 0; day < 5; day += 1 {
for slot := 0; slot < slots[day]; slot += 1 {
current, currentExists := timetable[models.Date{0, day, hour, minute}][slot]
current, currentExists := timetable[models.Date{Week: 0, Day: day, Hour: hour, Minute: minute}][slot]
if currentExists { // This slot is taken by some office hour
var continued bool = false // is this slot occupied by the same office hour the previous minute?
var predecessorExists bool
var predecessor models.OfficeHour
if hour > 0 && minute < b.config.Date.MinuteGranularity {
predecessor, predecessorExists = timetable[models.Date{0, day, hour - 1, 60 - b.config.Date.MinuteGranularity}][slot]
predecessor, predecessorExists = timetable[models.Date{Week: 0, Day: day, Hour: hour - 1, Minute: 60 - b.config.Date.MinuteGranularity}][slot]
} else {
predecessor, predecessorExists = timetable[models.Date{0, day, hour, minute - b.config.Date.MinuteGranularity}][slot]
predecessor, predecessorExists = timetable[models.Date{Week: 0, Day: day, Hour: hour, Minute: minute - b.config.Date.MinuteGranularity}][slot]
}
if predecessorExists {
continued = (predecessor == current)
@ -83,7 +83,7 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
OfficeHour models.OfficeHour
MinuteGranularity int
DeleteIcons bool
}{current, b.config.Date.MinuteGranularity, deleteIcons}
}{OfficeHour: current, MinuteGranularity: b.config.Date.MinuteGranularity, DeleteIcons: deleteIcons}
Templates.ExecuteTemplate(&celldata, "td.html", data)
tableBody += celldata.String()
}

View file

@ -4,7 +4,6 @@ package repositories
import (
"database/sql"
"fmt"
"log"
"sprechstundentool/config"
"sprechstundentool/models"
)
@ -131,7 +130,7 @@ func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
if err != nil {
return models.OfficeHour{}, fmt.Errorf("Error getting single officeHours row from database: %s", err.Error())
}
officeHour.Date = models.Date{week, day, hour, minute}
officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
officeHour.Room, _ = r.roomRepo.FindById(roomId)
officeHour.Tutor, _ = r.tutorRepo.FindById(tutorId)
officeHour.Course, _ = r.courseRepo.FindById(courseId)
@ -146,7 +145,7 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil {
return officeHours, fmt.Errorf("Error getting multiple officeHour rows from database: %s", err.Error())
}
officeHour.Date = models.Date{week, day, hour, minute}
officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
officeHour.Room, _ = r.roomRepo.FindById(roomId)
officeHour.Tutor, _ = r.tutorRepo.FindById(tutorId)
officeHour.Course, _ = r.courseRepo.FindById(courseId)

View file

@ -81,7 +81,7 @@ func (r *RequestRepo) Add(officeHour models.OfficeHour, action int) (int, error)
if err != nil {
return 0, err
}
request := models.Request{0, officeHour, action, secret}
request := models.Request{Id: 0, OfficeHour: officeHour, Action: action, Secret: secret}
_, err = r.db.Exec("INSERT INTO `request` (officeHour, action, secret) VALUES (?,?,?)", officeHour.Id, action, secret)
if err != nil {
return 0, err