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"
|
|
|
|
)
|
|
|
|
|
2024-01-02 10:56:17 +01:00
|
|
|
func NewMux() *Mux {
|
|
|
|
return &Mux{ServeMux: http.NewServeMux()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mux *Mux) handleParticipants(db *data.DB, cp <-chan *Participant, b *Briefing) {
|
2023-10-30 11:38:56 +01:00
|
|
|
for p := range cp {
|
2024-01-02 10:56:17 +01:00
|
|
|
p.GivenAnswers = make([]int, len(b.Questions))
|
2023-10-30 11:38:56 +01:00
|
|
|
|
2024-01-06 07:38:37 +01:00
|
|
|
mux.HandleFunc("/submit-participant/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleParticipant(db, b, p))
|
|
|
|
mux.HandleFunc("/end-video/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleEndOfVideo(b, p))
|
2023-10-30 11:38:56 +01:00
|
|
|
var i int
|
2024-01-02 10:56:17 +01:00
|
|
|
for i = range b.Questions {
|
2024-01-06 07:38:37 +01:00
|
|
|
mux.HandleFunc("/submit-answer/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", HandleAnswer(db, b, p, int64(i+1)))
|
2023-10-30 11:38:56 +01:00
|
|
|
}
|
2024-01-06 07:38:37 +01:00
|
|
|
mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleAllowRetry(p))
|
|
|
|
mux.HandleFunc("/retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleRetry(b, p, &i))
|
|
|
|
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleRefresh(b, p))
|
2023-10-30 11:38:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 07:38:37 +01:00
|
|
|
func (mux *Mux) handleBriefings(db *data.DB, cb <-chan *Briefing, s *Session) {
|
2024-01-02 10:56:17 +01:00
|
|
|
participantChan := make(chan *Participant)
|
|
|
|
for b := range cb {
|
|
|
|
b.getQuestions(db)
|
|
|
|
|
2024-01-06 07:38:37 +01:00
|
|
|
mux.HandleFunc("/new-participant/"+fmt.Sprint(b.UUID)+"/", HandleNewParticipant(b, participantChan))
|
|
|
|
mux.HandleFunc("/submit-form/"+fmt.Sprint(b.UUID)+"/", HandleBriefingForm(db, s, b))
|
2024-01-02 10:56:17 +01:00
|
|
|
|
|
|
|
go mux.handleParticipants(db, participantChan, b)
|
|
|
|
}
|
2023-10-28 09:17:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session) {
|
2024-01-02 10:56:17 +01:00
|
|
|
briefingChan := make(chan *Briefing)
|
2023-10-28 09:17:10 +02:00
|
|
|
for s := range cs {
|
2023-11-01 11:16:25 +01:00
|
|
|
(*ss) = append((*ss), s)
|
2023-10-28 09:17:10 +02:00
|
|
|
|
2024-01-06 07:38:37 +01:00
|
|
|
mux.HandleFunc("/search/"+fmt.Sprint(s.UUID)+"/", HandleSearch(db, s))
|
|
|
|
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.UUID)+"/", HandleNewBriefing(s, briefingChan))
|
|
|
|
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.UUID)+"/", HandleBriefingDone(db, s))
|
2023-10-28 09:17:10 +02:00
|
|
|
|
2024-01-06 07:38:37 +01:00
|
|
|
go mux.handleBriefings(db, briefingChan, s)
|
2023-10-28 09:17:10 +02:00
|
|
|
}
|
|
|
|
}
|