refactor template rendering logic to one base template

This commit is contained in:
Johannes 2022-09-21 22:18:39 +02:00
parent 16e8cf9cd7
commit d60b715d96
18 changed files with 199 additions and 212 deletions

View file

@ -1,7 +1,6 @@
package controllers
import (
"fmt"
"html/template"
"net/http"
"officeHours/models"
@ -28,6 +27,7 @@ func (b *BaseHandler) GetByCourseHandler(w http.ResponseWriter, req *http.Reques
courseid, err := strconv.Atoi(req.FormValue("veranstaltung"))
if err != nil {
b.RootHandler(w, req)
return
}
course, err := b.courseRepo.FindById(courseid)
if err != nil {
@ -51,9 +51,5 @@ func (b *BaseHandler) writeTimetablePage(w http.ResponseWriter, req *http.Reques
SelectedRoom int
SelectedCourse int
}{courses, rooms, timetable, selectedRoom, selectedCourse}
err := Templates.ExecuteTemplate(w, "index.html", data)
if err != nil {
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", err.Error())))
return
}
b.serveTemplate(w, "index", data)
}