diff --git a/controllers/addOfficeHourHandler.go b/controllers/addOfficeHourHandler.go
index a99a40a..76dd06c 100644
--- a/controllers/addOfficeHourHandler.go
+++ b/controllers/addOfficeHourHandler.go
@@ -101,6 +101,9 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
}
roomname := req.FormValue("raumname")
+ if roomname != "" && room.Name != "Sonstige" {
+ errors = append(errors, "Sonderraumnamen können nur für den Raum \"Sonstige\" angegeben werden.")
+ }
name := req.FormValue("name")
if name == "" {
errors = append(errors, "Der Name darf nicht leer sein.")
@@ -142,6 +145,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
Tutor: models.Tutor{Id: 0, Name: name, Email: email.Address},
Date: date,
Room: room,
+ RoomName: roomname,
Course: course,
Info: info,
Active: false,
diff --git a/models/officeHour.go b/models/officeHour.go
index 89f0b98..5be2be5 100644
--- a/models/officeHour.go
+++ b/models/officeHour.go
@@ -5,8 +5,9 @@ type OfficeHour struct {
Id int
Tutor Tutor
Date
- Room Room
- Course Course
+ Room
+ Course
+ RoomName string
Info string
Active bool
Duration int
diff --git a/officeHoursMysql.sql b/officeHoursMysql.sql
index 8c4632d..969add5 100644
--- a/officeHoursMysql.sql
+++ b/officeHoursMysql.sql
@@ -33,6 +33,7 @@ CREATE TABLE `officeHour` (
`hour` int DEFAULT NULL,
`minute` int DEFAULT NULL,
`room` int DEFAULT NULL,
+ `roomname` text DEFAULT NULL,
`course` int DEFAULT NULL,
`week` int DEFAULT NULL,
`info` text DEFAULT NULL,
diff --git a/sqlite.sql b/officeHoursSQLite.sql
similarity index 97%
rename from sqlite.sql
rename to officeHoursSQLite.sql
index e6cedef..ef71d6b 100644
--- a/sqlite.sql
+++ b/officeHoursSQLite.sql
@@ -33,6 +33,7 @@ CREATE TABLE `officeHour` (
`hour` int DEFAULT NULL,
`minute` int DEFAULT NULL,
`room` int DEFAULT NULL,
+ `roomname` text DEFAULT NULL,
`course` int DEFAULT NULL,
`week` int DEFAULT NULL,
`info` text DEFAULT NULL,
diff --git a/repositories/officeHour.go b/repositories/officeHour.go
index e92093f..21dae2b 100644
--- a/repositories/officeHour.go
+++ b/repositories/officeHour.go
@@ -119,17 +119,21 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (int, error) {
}
}
- sqlResult, err := r.db.Exec("INSERT INTO `officeHour` (tutor, day, hour, minute, room, course, week, info, active, duration) VALUES (?,?,?,?,?,?,?,?,?,?)",
+ sqlResult, err := r.db.Exec("INSERT INTO `officeHour` (tutor, day, hour, minute, room, roomname, course, week, info, active, duration) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
officeHour.Tutor.Id,
officeHour.Date.Day,
officeHour.Date.Hour,
officeHour.Date.Minute,
officeHour.Room.Id,
+ officeHour.RoomName,
officeHour.Course.Id,
officeHour.Date.Week,
officeHour.Info,
officeHour.Active,
officeHour.Duration)
+ if err != nil {
+ return 0, fmt.Errorf("SQL-error inserting new office hour: %w", err)
+ }
id, lastInsertIdErr := sqlResult.LastInsertId()
if lastInsertIdErr != nil {
log.Printf("Error getting Id for new tutor: %s", lastInsertIdErr.Error())
@@ -150,7 +154,7 @@ func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
var officeHour models.OfficeHour
var week, day, hour, minute, tutorId, courseId, roomId int
- err := row.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
+ err := row.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
if err != nil {
err = fmt.Errorf("Error getting single officeHour row from database: %w", err)
log.Println(err.Error())
@@ -184,7 +188,7 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
var officeHour models.OfficeHour
var week, day, hour, minute, tutorId, roomId, courseId int
var err error
- if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil {
+ if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &officeHour.RoomName, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil {
return officeHours, fmt.Errorf("Error getting multiple officeHour rows from database: %w", err)
}
officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute}
diff --git a/templating/templates/td.html b/templating/templates/td.html
index 8c4cb9c..d1b0ad9 100644
--- a/templating/templates/td.html
+++ b/templating/templates/td.html
@@ -6,4 +6,5 @@
{{.OfficeHour.Tutor.Name}}
{{.OfficeHour.Room.Name}}
{{if ne .OfficeHour.Info ""}}{{.OfficeHour.Info}}
{{end}}
+ {{if ne .OfficeHour.RoomName ""}}{{.OfficeHour.RoomName}}
{{end}}
\ No newline at end of file