|
|
|
@ -28,6 +28,7 @@ type maskData struct {
|
|
|
|
|
Config config.Config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Offer a form to add office hours and validate its input on receiving.
|
|
|
|
|
func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
var errors []string
|
|
|
|
|
courses, err := b.courseRepo.GetAll()
|
|
|
|
@ -123,6 +124,9 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|
|
|
|
} else if !allowed {
|
|
|
|
|
errors = append(errors, "In dem Raum muss noch Platz für weitere Sprechstunden sein.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there were errors in the data for the new office hour,
|
|
|
|
|
// answer with the form prefilled with the sent data.
|
|
|
|
|
if len(errors) != 0 {
|
|
|
|
|
var data maskData = maskData{
|
|
|
|
|
courses,
|
|
|
|
@ -141,6 +145,8 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|
|
|
|
}
|
|
|
|
|
b.writeAddOfficeHourMask(w, req, data)
|
|
|
|
|
} else {
|
|
|
|
|
// if the data for a new office hour was sent correctly, save it.
|
|
|
|
|
|
|
|
|
|
officeHour := models.OfficeHour{Id: 0,
|
|
|
|
|
Tutor: models.Tutor{Id: 0, Name: name, Email: email.Address},
|
|
|
|
|
Date: date,
|
|
|
|
@ -166,12 +172,11 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
|
|
|
|
|
log.Printf("Error adding request: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
templating.ServeTemplate(w, "addSuccess", nil)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *BaseHandler) writeAddOfficeHourMask(w http.ResponseWriter, req *http.Request, data maskData) {
|
|
|
|
|
if req.Method == http.MethodGet {
|
|
|
|
|
if req.Method == http.MethodGet { // if the current request is GET, we assume no office hour addition was tried so far and reset the errors.
|
|
|
|
|
data.Errors = []string{}
|
|
|
|
|
}
|
|
|
|
|
if len(data.Errors) != 0 {
|
|
|
|
|