2023-10-05 18:08:44 +02:00
|
|
|
package main
|
2023-10-04 17:13:03 +02:00
|
|
|
|
2023-10-04 17:29:22 +02:00
|
|
|
import (
|
2023-10-19 20:06:08 +02:00
|
|
|
"fmt"
|
2023-10-10 20:57:53 +02:00
|
|
|
"html/template"
|
2023-10-04 17:29:22 +02:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-10-16 18:51:52 +02:00
|
|
|
|
2023-10-19 20:06:08 +02:00
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/db"
|
2023-10-05 19:56:18 +02:00
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/server"
|
2023-10-19 20:06:08 +02:00
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
2023-10-04 17:29:22 +02:00
|
|
|
)
|
|
|
|
|
2023-10-19 20:06:08 +02:00
|
|
|
func handleSessions(mux *http.ServeMux, db *db.DB, ss []*types.Session, cs <-chan *types.Session) {
|
|
|
|
for session := range cs {
|
|
|
|
ss = append(ss, session)
|
|
|
|
mux.HandleFunc("/add-participant-"+fmt.Sprint(session.ID)+"/", server.AddParticipant(session))
|
|
|
|
mux.HandleFunc("/submit-form-"+fmt.Sprint(session.ID)+"/", server.SubmitBriefingForm(session, db))
|
|
|
|
}
|
|
|
|
}
|
2023-10-05 17:42:47 +02:00
|
|
|
|
2023-10-19 20:06:08 +02:00
|
|
|
func main() {
|
|
|
|
db, err := db.Open("sicherheitsunterweisung")
|
2023-10-05 17:42:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
2023-10-05 19:52:11 +02:00
|
|
|
}
|
2023-10-04 18:55:48 +02:00
|
|
|
|
2023-10-19 20:06:08 +02:00
|
|
|
sessions := make([]*types.Session, 0)
|
|
|
|
sessionChan := make(chan *types.Session)
|
|
|
|
|
2023-10-19 15:22:45 +02:00
|
|
|
mux := http.NewServeMux()
|
2023-10-04 18:55:48 +02:00
|
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
2023-10-10 20:57:53 +02:00
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
template.Must(template.ParseFiles("templates/index.html", "templates/login.html")).Execute(w, nil)
|
|
|
|
})
|
|
|
|
mux.HandleFunc("/internal-login/", server.DisplayTable(db))
|
2023-10-19 20:06:08 +02:00
|
|
|
mux.HandleFunc("/external-login/", server.DisplayParticipantForm(sessions))
|
|
|
|
mux.HandleFunc("/search/", server.DisplaySearchResults(db))
|
2023-10-20 16:33:00 +02:00
|
|
|
mux.HandleFunc("/new-briefing/", server.DisplayInstructorForm(db, sessionChan))
|
2023-10-19 20:06:08 +02:00
|
|
|
|
|
|
|
go handleSessions(mux, db, sessions, sessionChan)
|
2023-10-04 17:29:22 +02:00
|
|
|
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
|
|
|
}
|