65 lines
2.5 KiB
Go
65 lines
2.5 KiB
Go
/*
|
|
* Sicherheitsunterweisung
|
|
* Copyright (C) 2023 Jason Streifling
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package session
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
|
)
|
|
|
|
func NewMux() *Mux {
|
|
return &Mux{ServeMux: http.NewServeMux()}
|
|
}
|
|
|
|
func (mux *Mux) handleParticipants(db *data.DB, cp <-chan *Participant, b *Briefing) {
|
|
for p := range cp {
|
|
p.GivenAnswers = make([]int, len(b.Questions))
|
|
|
|
mux.HandleFunc("/submit-participant/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleParticipant(db, p))
|
|
mux.HandleFunc("/end-video/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleEndOfVideo(p))
|
|
var i int
|
|
for i = range b.Questions {
|
|
mux.HandleFunc("/submit-answer/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", b.HandleAnswer(db, p, int64(i+1)))
|
|
}
|
|
mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleAllowRetry())
|
|
mux.HandleFunc("/retry/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleRetry(p, &i))
|
|
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleRefresh(p))
|
|
}
|
|
}
|
|
|
|
func (mux *Mux) handleBriefings(db *data.DB, cb <-chan *Briefing) {
|
|
participantChan := make(chan *Participant)
|
|
for b := range cb {
|
|
b.getQuestions(db)
|
|
|
|
mux.HandleFunc("/new-participant/"+fmt.Sprint(b.ID)+"/", b.HandleNewParticipant(participantChan))
|
|
mux.HandleFunc("/submit-form/"+fmt.Sprint(b.ID)+"/", b.HandleBriefingForm(db))
|
|
|
|
go mux.handleParticipants(db, participantChan, b)
|
|
}
|
|
}
|
|
|
|
func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session) {
|
|
briefingChan := make(chan *Briefing)
|
|
for s := range cs {
|
|
(*ss) = append((*ss), s)
|
|
|
|
mux.HandleFunc("/search/"+fmt.Sprint(s.ID)+"/", s.HandleSearch(db))
|
|
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.ID)+"/", s.HandleNewBriefing(briefingChan))
|
|
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.ID)+"/", s.HandleBriefingDone(db))
|
|
|
|
go mux.handleBriefings(db, briefingChan)
|
|
}
|
|
}
|