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") 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") name := req.FormValue("name")
if name == "" { if name == "" {
errors = append(errors, "Der Name darf nicht leer sein.") 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}, Tutor: models.Tutor{Id: 0, Name: name, Email: email.Address},
Date: date, Date: date,
Room: room, Room: room,
RoomName: roomname,
Course: course, Course: course,
Info: info, Info: info,
Active: false, Active: false,

View File

@ -5,8 +5,9 @@ type OfficeHour struct {
Id int Id int
Tutor Tutor Tutor Tutor
Date Date
Room Room Room
Course Course Course
RoomName string
Info string Info string
Active bool Active bool
Duration int Duration int

View File

@ -33,6 +33,7 @@ CREATE TABLE `officeHour` (
`hour` int DEFAULT NULL, `hour` int DEFAULT NULL,
`minute` int DEFAULT NULL, `minute` int DEFAULT NULL,
`room` int DEFAULT NULL, `room` int DEFAULT NULL,
`roomname` text DEFAULT NULL,
`course` int DEFAULT NULL, `course` int DEFAULT NULL,
`week` int DEFAULT NULL, `week` int DEFAULT NULL,
`info` text DEFAULT NULL, `info` text DEFAULT NULL,

View File

@ -33,6 +33,7 @@ CREATE TABLE `officeHour` (
`hour` int DEFAULT NULL, `hour` int DEFAULT NULL,
`minute` int DEFAULT NULL, `minute` int DEFAULT NULL,
`room` int DEFAULT NULL, `room` int DEFAULT NULL,
`roomname` text DEFAULT NULL,
`course` int DEFAULT NULL, `course` int DEFAULT NULL,
`week` int DEFAULT NULL, `week` int DEFAULT NULL,
`info` text 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.Tutor.Id,
officeHour.Date.Day, officeHour.Date.Day,
officeHour.Date.Hour, officeHour.Date.Hour,
officeHour.Date.Minute, officeHour.Date.Minute,
officeHour.Room.Id, officeHour.Room.Id,
officeHour.RoomName,
officeHour.Course.Id, officeHour.Course.Id,
officeHour.Date.Week, officeHour.Date.Week,
officeHour.Info, officeHour.Info,
officeHour.Active, officeHour.Active,
officeHour.Duration) officeHour.Duration)
if err != nil {
return 0, fmt.Errorf("SQL-error inserting new office hour: %w", err)
}
id, lastInsertIdErr := sqlResult.LastInsertId() id, lastInsertIdErr := sqlResult.LastInsertId()
if lastInsertIdErr != nil { if lastInsertIdErr != nil {
log.Printf("Error getting Id for new tutor: %s", lastInsertIdErr.Error()) 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) { func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
var officeHour models.OfficeHour var officeHour models.OfficeHour
var week, day, hour, minute, tutorId, courseId, roomId int 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 { if err != nil {
err = fmt.Errorf("Error getting single officeHour row from database: %w", err) err = fmt.Errorf("Error getting single officeHour row from database: %w", err)
log.Println(err.Error()) log.Println(err.Error())
@ -184,7 +188,7 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
var officeHour models.OfficeHour var officeHour models.OfficeHour
var week, day, hour, minute, tutorId, roomId, courseId int var week, day, hour, minute, tutorId, roomId, courseId int
var err error 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) 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} officeHour.Date = models.Date{Week: week, Day: day, Hour: hour, Minute: minute}

View File

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