generated from jphacks/JP_sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.go
38 lines (30 loc) · 969 Bytes
/
dashboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"database/sql"
"html/template"
"net/http"
"time"
_ "github.com/mattn/go-sqlite3"
)
type StudyData struct {
Date string
DetectionTime float64
StudyTime float64
FocusScore float64
}
var dashboardTemplate = template.Must(template.ParseFiles("templates/dashboard.html"))
func dashboardPage(w http.ResponseWriter, r *http.Request) {
db, _ := sql.Open("sqlite3", "./user_registration.db")
defer db.Close()
rows, _ := db.Query("SELECT date, detection_time, study_time, focus_score FROM study_data ORDER BY date DESC")
var data []StudyData
for rows.Next() {
var record StudyData
rows.Scan(&record.Date, &record.DetectionTime, &record.StudyTime, &record.FocusScore)
data = append(data, record)
}
dashboardTemplate.Execute(w, data)
}
func logout(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/login", http.StatusSeeOther)
}