Erster Commit
This commit is contained in:
commit
b26544756a
11 changed files with 405 additions and 0 deletions
68
main.go
Normal file
68
main.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func root(w http.ResponseWriter, req *http.Request) {
|
||||
writeTimetablePage(w, req, template.HTML(""))
|
||||
}
|
||||
|
||||
func getByRoom(w http.ResponseWriter, req *http.Request) {
|
||||
room, err := strconv.Atoi(req.FormValue("raum"))
|
||||
if err != nil || room == 0 {
|
||||
root(w, req)
|
||||
return
|
||||
}
|
||||
writeTimetablePage(w, req, printTimetable(getTimetable(getOfficeHoursByRoom(room))))
|
||||
}
|
||||
|
||||
func getByCourse(w http.ResponseWriter, req *http.Request) {
|
||||
course, err := strconv.Atoi(req.FormValue("veranstaltung"))
|
||||
if err != nil || course == 0 {
|
||||
root(w, req)
|
||||
return
|
||||
}
|
||||
writeTimetablePage(w, req, printTimetable(getTimetable(getOfficeHoursByCourse(course))))
|
||||
}
|
||||
|
||||
func writeTimetablePage(w http.ResponseWriter, req *http.Request, timetable template.HTML) {
|
||||
room, err := strconv.Atoi(req.FormValue("raum"))
|
||||
if err != nil {
|
||||
room = 0
|
||||
}
|
||||
course, err := strconv.Atoi(req.FormValue("veranstaltung"))
|
||||
if err != nil {
|
||||
course = 0
|
||||
}
|
||||
data := struct {
|
||||
Courses []Course
|
||||
Rooms []Room
|
||||
Timetable template.HTML
|
||||
SelectedRoom int
|
||||
SelectedCourse int
|
||||
}{getCourses(), getRooms(), timetable, room, course}
|
||||
tmpl, err := template.ParseFiles("templates/index.html")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", string(err.Error()))))
|
||||
return
|
||||
}
|
||||
err = tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", string(err.Error()))))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/getByRoom", getByRoom)
|
||||
http.HandleFunc("/getByCourse", getByCourse)
|
||||
|
||||
http.HandleFunc("/", root)
|
||||
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue