Sprechstunden löschen

This commit is contained in:
Gonne 2022-09-05 20:10:35 +02:00
parent 78af58a51d
commit 2ce7a1fae1
15 changed files with 100 additions and 34 deletions

View file

@ -0,0 +1,29 @@
// deleteOfficeHourHandler
package controllers
import (
"html/template"
"net/http"
"sprechstundentool/models"
"strconv"
)
func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
if req.FormValue("id") != "" {
id, err := strconv.Atoi(req.FormValue("id"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
}
officeHour, err := b.officeHourRepo.FindById(id)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
}
_, err = b.requestRepo.Add(officeHour, models.RequestDelete)
tmpl, _ := template.New("deleteSuccess.html").ParseFiles("templates/deleteSuccess.html")
tmpl.Execute(w, struct{}{})
} else {
officeHours, _ := b.officeHourRepo.GetAll(true)
timetable, slots := GetTimetable(officeHours)
b.writeTimetablePage(w, req, printTimetable(timetable, slots, true))
}
}