Zeige Raumnamen an

This commit is contained in:
Gonne 2022-09-27 16:40:47 +02:00
parent 6241c8f391
commit b2a975dcbe
6 changed files with 17 additions and 5 deletions

View file

@ -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,

View file

@ -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

View file

@ -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,

View file

@ -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,

View file

@ -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}

View file

@ -6,4 +6,5 @@
{{.OfficeHour.Tutor.Name}}<br />
{{.OfficeHour.Room.Name}}<br />
{{if ne .OfficeHour.Info ""}}{{.OfficeHour.Info}}<br />{{end}}
{{if ne .OfficeHour.RoomName ""}}{{.OfficeHour.RoomName}}<br />{{end}}
</td>