2023-11-01 14:11:00 +01:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2023-10-28 09:17:10 +02:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
|
|
|
)
|
|
|
|
|
2023-10-30 11:38:56 +01:00
|
|
|
func (mux *Mux) handleParticipants(db *data.DB, cp <-chan *BriefingParticipant, s *Session) {
|
|
|
|
for p := range cp {
|
|
|
|
p.GivenAnswers = make([]int, len(s.Questions))
|
|
|
|
|
|
|
|
mux.HandleFunc("/submit-participant/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(p.Login)+"/", s.HandleParticipant(db, p))
|
2023-11-02 18:25:28 +01:00
|
|
|
mux.HandleFunc("/end-video/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(p.Login)+"/", s.HandleEndOfVideo(p))
|
2023-10-30 11:38:56 +01:00
|
|
|
var i int
|
|
|
|
for i = range s.Questions {
|
|
|
|
mux.HandleFunc("/submit-answer/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", s.HandleAnswer(db, p, int64(i+1)))
|
|
|
|
}
|
|
|
|
mux.HandleFunc("/allow-retry/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(p.Login)+"/", s.HandleAllowRetry(p))
|
|
|
|
mux.HandleFunc("/retry/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(p.Login)+"/", s.HandleRetry(p, &i))
|
|
|
|
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(p.Login)+"/", s.HandleRefresh(p))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-28 09:17:10 +02:00
|
|
|
func NewMux() *Mux {
|
2023-11-01 09:18:48 +01:00
|
|
|
return &Mux{ServeMux: http.NewServeMux()}
|
2023-10-28 09:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session) {
|
|
|
|
for s := range cs {
|
2023-11-01 11:16:25 +01:00
|
|
|
(*ss) = append((*ss), s)
|
2023-10-30 11:38:56 +01:00
|
|
|
participantChan := make(chan *BriefingParticipant)
|
2023-11-02 17:52:04 +01:00
|
|
|
s.getQuestions(db)
|
2023-10-28 09:17:10 +02:00
|
|
|
|
2023-10-30 11:38:56 +01:00
|
|
|
mux.HandleFunc("/search/"+fmt.Sprint(s.ID)+"/", s.HandleSearch(db))
|
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))
|
2023-10-30 11:38:56 +01:00
|
|
|
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.ID)+"/", s.HandleBriefingDone())
|
2023-10-28 09:17:10 +02:00
|
|
|
|
|
|
|
go mux.handleParticipants(db, participantChan, s)
|
|
|
|
}
|
|
|
|
}
|