Instructor Form zum Laufen gebracht

This commit is contained in:
2023-10-20 16:33:00 +02:00
parent b78e30d109
commit d054b3644b
5 changed files with 55 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"html/template"
"log"
"net/http"
"strconv"
"time"
@ -34,13 +35,38 @@ func DisplaySearchResults(db *db.DB) http.HandlerFunc {
}
}
func DisplayInstructorForm(cs chan<- *types.Session) http.HandlerFunc {
func DisplayInstructorForm(db *db.DB, cs chan<- *types.Session) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
type option struct {
ID int64
String string
}
type htmlData struct {
SessionID uuid.UUID
Options []option
}
session := new(types.Session)
session.ID = uuid.New()
cs <- session
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", session.ID)
instructors, err := db.GetInstructors()
if err != nil {
http.Error(w, "DisplayInstructorForm: db.GetInstructors(): "+fmt.Sprint(err), http.StatusInternalServerError)
log.Panicln(err)
}
data := new(htmlData)
data.SessionID = session.ID
for _, instructor := range instructors {
option := new(option)
option.ID = instructor.ID
option.String = instructor.LastName + ", " + instructor.FirstName + ": " + fmt.Sprint(instructor.PersonnelID)
data.Options = append(data.Options, *option)
}
template.Must(template.ParseFiles("templates/briefing.html")).ExecuteTemplate(w, "content", data)
}
}