rework template rendering, cache parsed templates

adapt error wrapping principle
This commit is contained in:
Johannes 2022-09-24 15:01:33 +02:00
parent 7a1448d6f9
commit f04396809d
21 changed files with 175 additions and 82 deletions

View file

@ -4,10 +4,13 @@ package controllers
import (
"net/http"
"officeHours/models"
"officeHours/templating"
"strconv"
)
func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
// TODO: error handling here is by no means sufficient, furthermore
// 400 BadRequest is for technically wrong stuff (most promimently GET instead of POST)
if req.FormValue("id") != "" {
id, err := strconv.Atoi(req.FormValue("id"))
if err != nil {
@ -18,7 +21,7 @@ func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.R
w.WriteHeader(http.StatusBadRequest)
}
_, err = b.requestRepo.Add(officeHour, models.RequestDelete)
b.serveTemplate(w, "deleteSuccess", nil)
templating.ServeTemplate(w, "deleteSuccess", nil)
} else {
officeHours, _ := b.officeHourRepo.GetAll(true)
timetable, slots := b.GetTimetable(officeHours)