Von Methoden für handlerFuncs weggegangen, solange ich da kein vernünftiges Konzept habe. Außerdem Bug behoben.

This commit is contained in:
Jason Streifling 2024-01-06 07:38:37 +01:00
parent 9331035edd
commit 0fe1d822e2
4 changed files with 19 additions and 18 deletions

View File

@ -22,7 +22,7 @@ type tableHTMLData struct {
} }
type participantHTMLData struct { type participantHTMLData struct {
BriefingID int64 BriefingID uuid.UUID
Participant Participant
} }
@ -51,6 +51,7 @@ type resultHTMLData struct {
} }
type summaryHTMLData struct { type summaryHTMLData struct {
BriefingID int64 SessionID uuid.UUID
BriefingID uuid.UUID
ParticipantsData []participantHTMLData ParticipantsData []participantHTMLData
} }

View File

@ -26,25 +26,25 @@ func (mux *Mux) handleParticipants(db *data.DB, cp <-chan *Participant, b *Brief
for p := range cp { for p := range cp {
p.GivenAnswers = make([]int, len(b.Questions)) 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("/submit-participant/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleParticipant(db, b, p))
mux.HandleFunc("/end-video/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleEndOfVideo(p)) mux.HandleFunc("/end-video/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleEndOfVideo(b, p))
var i int var i int
for i = range b.Questions { 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("/submit-answer/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", HandleAnswer(db, b, p, int64(i+1)))
} }
mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleAllowRetry()) mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleAllowRetry(p))
mux.HandleFunc("/retry/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleRetry(p, &i)) mux.HandleFunc("/retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleRetry(b, p, &i))
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.ID)+"/"+fmt.Sprint(p.Login)+"/", b.HandleRefresh(p)) mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", HandleRefresh(b, p))
} }
} }
func (mux *Mux) handleBriefings(db *data.DB, cb <-chan *Briefing) { func (mux *Mux) handleBriefings(db *data.DB, cb <-chan *Briefing, s *Session) {
participantChan := make(chan *Participant) participantChan := make(chan *Participant)
for b := range cb { for b := range cb {
b.getQuestions(db) b.getQuestions(db)
mux.HandleFunc("/new-participant/"+fmt.Sprint(b.ID)+"/", b.HandleNewParticipant(participantChan)) mux.HandleFunc("/new-participant/"+fmt.Sprint(b.UUID)+"/", HandleNewParticipant(b, participantChan))
mux.HandleFunc("/submit-form/"+fmt.Sprint(b.ID)+"/", b.HandleBriefingForm(db)) mux.HandleFunc("/submit-form/"+fmt.Sprint(b.UUID)+"/", HandleBriefingForm(db, s, b))
go mux.handleParticipants(db, participantChan, b) go mux.handleParticipants(db, participantChan, b)
} }
@ -55,10 +55,10 @@ func (mux *Mux) HandleSessions(db *data.DB, cs <-chan *Session, ss *[]*Session)
for s := range cs { for s := range cs {
(*ss) = append((*ss), s) (*ss) = append((*ss), s)
mux.HandleFunc("/search/"+fmt.Sprint(s.ID)+"/", s.HandleSearch(db)) mux.HandleFunc("/search/"+fmt.Sprint(s.UUID)+"/", HandleSearch(db, s))
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.ID)+"/", s.HandleNewBriefing(briefingChan)) mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.UUID)+"/", HandleNewBriefing(s, briefingChan))
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.ID)+"/", s.HandleBriefingDone(db)) mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.UUID)+"/", HandleBriefingDone(db, s))
go mux.handleBriefings(db, briefingChan) go mux.handleBriefings(db, briefingChan, s)
} }
} }

View File

@ -31,14 +31,14 @@ type Participant struct {
} }
type Briefing struct { type Briefing struct {
ID int64
*data.Briefing *data.Briefing
UUID uuid.UUID
Participants []*Participant Participants []*Participant
Questions []data.Question Questions []data.Question
} }
type Session struct { type Session struct {
ID uuid.UUID UUID uuid.UUID
Instructor data.Instructor Instructor data.Instructor
Briefings []*Briefing Briefings []*Briefing
} }

View File

@ -40,7 +40,7 @@
{{end}} {{end}}
{{define "content"}} {{define "content"}}
<button hx-post="/briefing-done/{{.BriefingID}}/" hx-target="#content" type="button">Beenden</button> <button hx-post="/briefing-done/{{.SessionID}}/" hx-target="#content" type="button">Beenden</button>
{{range .ParticipantsData}} {{range .ParticipantsData}}
{{template "participant" .}} {{template "participant" .}}
{{end}} {{end}}