diff --git a/klice.go b/klice.go index 41c33a4..5676437 100644 --- a/klice.go +++ b/klice.go @@ -117,13 +117,35 @@ func isLoggedIn(w http.ResponseWriter, r *http.Request) (bool, int) { func teamInfoHandler(w http.ResponseWriter, r *http.Request) { if loggedIn, teamID := isLoggedIn(w, r); loggedIn { - var teamName, city, last_cipher, penalty string - err := db.QueryRow("SELECT name, city, last_cipher, penalty FROM teams WHERE id = ?", teamID).Scan(&teamName, &city, &last_cipher, &penalty) + var teamName string + var difficultyLevelID int + var difficultyLevel string + var lastCipher int + var penalty int + + err := db.QueryRow("SELECT name, difficulty_level, last_cipher, penalty FROM teams WHERE id = ?", teamID).Scan(&teamName, &difficultyLevelID, &lastCipher, &penalty) if err != nil { - http.Error(w, "Could not retrieve team information", http.StatusInternalServerError) + http.Error(w, "Could not retrieve team info", http.StatusInternalServerError) + return + } + err = db.QueryRow("SELECT level_name FROM difficulty_levels WHERE id = ?", difficultyLevelID).Scan(&difficultyLevel) + if err != nil { + http.Error(w, "Could not retrieve difficulty level", http.StatusInternalServerError) + return + } + + TeamTemplateData := TeamTemplateS{ + TeamName: teamName, + Difficulty: difficultyLevel, + LastCipher: lastCipher, + Penalties: penalty, + } + + err = TeamTemplate.Execute(w, TeamTemplateData) + if err != nil { + http.Error(w, "Could not render template", http.StatusInternalServerError) return } - fmt.Fprintf(w, "Team Name: %s, City: %s, Last Cipher: %s, Penalty: %s", teamName, city, last_cipher, penalty) } } diff --git a/templates.go b/templates.go index c3a1b7b..74da33f 100644 --- a/templates.go +++ b/templates.go @@ -15,4 +15,12 @@ type CipherTemplateS struct { Wrong bool } +type TeamTemplateS struct { + TeamName string + Difficulty string + LastCipher int + Penalties int +} + var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html")) +var TeamTemplate = template.Must(template.ParseFiles("templates/team.html")) diff --git a/templates/assignment.html b/templates/assignment.html index c79d6df..df9ec4c 100644 --- a/templates/assignment.html +++ b/templates/assignment.html @@ -2,6 +2,7 @@ + Zadání šifry {{.Order}} diff --git a/templates/team.html b/templates/team.html new file mode 100644 index 0000000..ae3d62f --- /dev/null +++ b/templates/team.html @@ -0,0 +1,20 @@ + + + + + + Tým: {{.TeamName}} + + + +

Tým: {{.TeamName}}

+ Obtížnost: {{.Difficulty}}
+ Poslední šifra : {{.LastCipher}}
+ Penalizace: {{.Penalties}}
+
+
+ +
+ + + \ No newline at end of file