Alle Methode privat gemacht, bei denen es möglich ist.

This commit is contained in:
Jason Streifling 2024-01-06 17:14:15 +01:00
parent 3cfcb721e8
commit 59e1016123
4 changed files with 22 additions and 22 deletions

View File

@ -41,7 +41,7 @@ func generateLogin() (string, error) {
return hex.EncodeToString(bs), nil return hex.EncodeToString(bs), nil
} }
func (b *Briefing) HandleNewParticipant(cp chan<- *Participant) http.HandlerFunc { func (b *Briefing) handleNewParticipant(cp chan<- *Participant) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var err error var err error
participant := Participant{ participant := Participant{
@ -67,7 +67,7 @@ func (b *Briefing) HandleNewParticipant(cp chan<- *Participant) http.HandlerFunc
} }
} }
func (b *Briefing) HandleBriefingForm(db *data.DB, s *Session) http.HandlerFunc { func (b *Briefing) handleBriefingForm(db *data.DB, s *Session) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
b.DateTime = time.Now().Format("2006-01-02 15:04:05") b.DateTime = time.Now().Format("2006-01-02 15:04:05")
b.Location = r.PostFormValue("location") b.Location = r.PostFormValue("location")

View File

@ -32,15 +32,15 @@ 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.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleParticipant(db, b)) mux.HandleFunc("/submit-participant/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleParticipant(db, b))
mux.HandleFunc("/end-video/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleEndOfVideo(b)) mux.HandleFunc("/end-video/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleEndOfVideo(b))
var i int var i int
for i = range b.Questions { for i = range b.Questions {
mux.HandleFunc("/submit-answer/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", p.HandleAnswer(db, b, int64(i+1))) mux.HandleFunc("/submit-answer/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/"+fmt.Sprint(i+1)+"/", p.handleAnswer(db, b, int64(i+1)))
} }
mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleAllowRetry()) mux.HandleFunc("/allow-retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleAllowRetry())
mux.HandleFunc("/retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleRetry(b, &i)) mux.HandleFunc("/retry/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleRetry(b, &i))
mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.HandleRefresh(b)) mux.HandleFunc("/refresh-summary/"+fmt.Sprint(b.UUID)+"/"+fmt.Sprint(p.Login)+"/", p.handleRefresh(b))
} }
} }
@ -74,8 +74,8 @@ func (mux *Mux) handleBriefings(db *data.DB, cb <-chan *Briefing, s *Session) {
for b := range cb { for b := range cb {
getQuestions(db, b) getQuestions(db, b)
mux.HandleFunc("/new-participant/"+fmt.Sprint(b.UUID)+"/", b.HandleNewParticipant(participantChan)) mux.HandleFunc("/new-participant/"+fmt.Sprint(b.UUID)+"/", b.handleNewParticipant(participantChan))
mux.HandleFunc("/submit-form/"+fmt.Sprint(b.UUID)+"/", b.HandleBriefingForm(db, s)) mux.HandleFunc("/submit-form/"+fmt.Sprint(b.UUID)+"/", b.handleBriefingForm(db, s))
go mux.handleParticipants(db, participantChan, b) go mux.handleParticipants(db, participantChan, b)
} }
@ -86,9 +86,9 @@ 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.UUID)+"/", s.HandleSearch(db)) mux.HandleFunc("/search/"+fmt.Sprint(s.UUID)+"/", s.handleSearch(db))
mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.UUID)+"/", s.HandleNewBriefing(briefingChan)) mux.HandleFunc("/new-briefing/"+fmt.Sprint(s.UUID)+"/", s.handleNewBriefing(briefingChan))
mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.UUID)+"/", s.HandleBriefingDone(db)) mux.HandleFunc("/briefing-done/"+fmt.Sprint(s.UUID)+"/", s.handleBriefingDone(db))
go mux.handleBriefings(db, briefingChan, s) go mux.handleBriefings(db, briefingChan, s)
} }

View File

@ -67,7 +67,7 @@ func makeResultQuestions(sq []data.Question, givenAnswers []int) []resultQuestio
return questions return questions
} }
func (p *Participant) HandleParticipant(db *data.DB, b *Briefing) http.HandlerFunc { func (p *Participant) handleParticipant(db *data.DB, b *Briefing) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
p.FirstName = r.PostFormValue("first-" + fmt.Sprint(p.Login)) p.FirstName = r.PostFormValue("first-" + fmt.Sprint(p.Login))
p.LastName = r.PostFormValue("last-" + fmt.Sprint(p.Login)) p.LastName = r.PostFormValue("last-" + fmt.Sprint(p.Login))
@ -88,7 +88,7 @@ func (p *Participant) HandleParticipant(db *data.DB, b *Briefing) http.HandlerFu
} }
} }
func (p *Participant) HandleAnswer(db *data.DB, b *Briefing, i int64) http.HandlerFunc { func (p *Participant) handleAnswer(db *data.DB, b *Briefing, i int64) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
if i < int64(len(b.Questions)) { if i < int64(len(b.Questions)) {
if err := handleGivenAnswer(p, i-1, r); err != nil { if err := handleGivenAnswer(p, i-1, r); err != nil {
@ -139,14 +139,14 @@ func (p *Participant) HandleAnswer(db *data.DB, b *Briefing, i int64) http.Handl
} }
} }
func (p *Participant) HandleAllowRetry() http.HandlerFunc { func (p *Participant) handleAllowRetry() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
p.NoIncorrect = -1 p.NoIncorrect = -1
p.AllowRetry = true p.AllowRetry = true
} }
} }
func (p *Participant) HandleRetry(b *Briefing, i *int) http.HandlerFunc { func (p *Participant) handleRetry(b *Briefing, i *int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
if p.AllowRetry { if p.AllowRetry {
p.AllowRetry = false p.AllowRetry = false
@ -176,7 +176,7 @@ func (p *Participant) HandleRetry(b *Briefing, i *int) http.HandlerFunc {
} }
} }
func (p *Participant) HandleRefresh(b *Briefing) http.HandlerFunc { func (p *Participant) handleRefresh(b *Briefing) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
data := participantHTMLData{ data := participantHTMLData{
BriefingID: b.UUID, BriefingID: b.UUID,
@ -187,7 +187,7 @@ func (p *Participant) HandleRefresh(b *Briefing) http.HandlerFunc {
} }
} }
func (p *Participant) HandleEndOfVideo(b *Briefing) http.HandlerFunc { func (p *Participant) handleEndOfVideo(b *Briefing) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
data := questionHTMLData{ data := questionHTMLData{
participantHTMLData: participantHTMLData{ participantHTMLData: participantHTMLData{

View File

@ -26,7 +26,7 @@ type Session struct {
Briefings []*Briefing Briefings []*Briefing
} }
func (s *Session) HandleSearch(db *data.DB) http.HandlerFunc { func (s *Session) handleSearch(db *data.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var err error var err error
data := tableHTMLData{} data := tableHTMLData{}
@ -41,7 +41,7 @@ func (s *Session) HandleSearch(db *data.DB) http.HandlerFunc {
} }
} }
func (s *Session) HandleNewBriefing(cb chan<- *Briefing) http.HandlerFunc { func (s *Session) handleNewBriefing(cb chan<- *Briefing) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
briefing := Briefing{Briefing: &data.Briefing{InstructorID: s.Instructor.ID}, UUID: uuid.New()} briefing := Briefing{Briefing: &data.Briefing{InstructorID: s.Instructor.ID}, UUID: uuid.New()}
s.Briefings = append(s.Briefings, &briefing) s.Briefings = append(s.Briefings, &briefing)
@ -51,7 +51,7 @@ func (s *Session) HandleNewBriefing(cb chan<- *Briefing) http.HandlerFunc {
} }
} }
func (s *Session) HandleBriefingDone(db *data.DB) http.HandlerFunc { func (s *Session) handleBriefingDone(db *data.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
data := tableHTMLData{SessionID: s.UUID} data := tableHTMLData{SessionID: s.UUID}
var err error var err error