DB konstant als ersten Funktionsparameter gesetzt

This commit is contained in:
Jason Streifling 2023-10-28 09:03:19 +02:00
parent 387f662355
commit e3fb756bb1
2 changed files with 4 additions and 4 deletions

View File

@ -12,7 +12,7 @@ import (
func handleParticipants(mux *http.ServeMux, db *data.DB, cp <-chan *data.Participant, s *session.Session) {
for participant := range cp {
mux.HandleFunc("/submit-participant/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(participant.Login)+"/", s.HandleParticipant(participant, &s.Questions, db))
mux.HandleFunc("/submit-participant/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(participant.Login)+"/", s.HandleParticipant(db, participant, &s.Questions))
for i := range s.Questions {
mux.HandleFunc("/submit-answer/"+fmt.Sprint(s.ID)+"/"+fmt.Sprint(participant.Login)+"/"+fmt.Sprint(i+1)+"/", s.HandleAnswer(db, participant, &s.Questions, int64(i+1)))
}
@ -58,7 +58,7 @@ func main() {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
template.Must(template.ParseFiles("templates/index.html", "templates/login.html")).Execute(w, nil)
})
mux.HandleFunc("/internal-login/", session.HandleInternalLogin(&sessions, sessionChan, db))
mux.HandleFunc("/internal-login/", session.HandleInternalLogin(db, &sessions, sessionChan))
mux.HandleFunc("/external-login/", session.HandleExternalLogin(&sessions))
mux.HandleFunc("/search/", session.HandleSearch(db))

View File

@ -11,7 +11,7 @@ import (
"streifling.com/jason/sicherheitsunterweisung/packages/data"
)
func HandleInternalLogin(ss *[]*Session, cs chan<- *Session, db *data.DB) http.HandlerFunc {
func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
instructors, err := db.GetInstructors()
if err != nil {
@ -112,7 +112,7 @@ func HandleExternalLogin(ss *[]*Session) http.HandlerFunc {
}
}
func (s *Session) HandleParticipant(p *data.Participant, sq *[]data.Question, db *data.DB) http.HandlerFunc {
func (s *Session) HandleParticipant(db *data.DB, p *data.Participant, sq *[]data.Question) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
p.FirstName = r.PostFormValue("first-" + fmt.Sprint(p.Login))
p.LastName = r.PostFormValue("last-" + fmt.Sprint(p.Login))