2023-10-28 09:17:10 +02:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewMux() *Mux {
|
|
|
|
mux := new(Mux)
|
|
|
|
mux.ServeMux = http.NewServeMux()
|
|
|
|
return mux
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session) {
|
|
|
|
for s := range cs {
|
|
|
|
(*ss) = append(*ss, s)
|
|
|
|
participantChan := make(chan *data.Participant)
|
|
|
|
questionIDs := make([]string, 4)
|
|
|
|
|
|
|
|
for i := 0; i < len(questionIDs); i++ {
|
|
|
|
questionIDs[i] = fmt.Sprint(i + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
s.Questions, err = db.GetQuestions(questionIDs)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2023-10-28 10:52:06 +02:00
|
|
|
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.ID)+"/", s.HandleNewBriefing())
|
2023-10-28 09:17:10 +02:00
|
|
|
mux.HandleFunc("/new-participant/"+fmt.Sprint(s.ID)+"/", s.HandleNewParticipant(participantChan))
|
|
|
|
mux.HandleFunc("/submit-form/"+fmt.Sprint(s.ID)+"/", s.HandleBriefingForm(db))
|
|
|
|
|
|
|
|
go mux.handleParticipants(db, participantChan, s)
|
|
|
|
}
|
|
|
|
}
|