-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes_pages.go
58 lines (42 loc) · 964 Bytes
/
routes_pages.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
// "fmt"
"fmt"
"log"
"net/http"
"todo-app/data"
"github.com/julienschmidt/httprouter"
)
// GET -> Index Page
func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
generateHTML(w, nil, "layout", "index")
}
// PLANNER -> authenticated index page
func planner(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
ctx := r.Context()
// get tasks
tasks, err := data.GetTasksByUserId(ctx.Value(userIdKey).(int))
if err != nil {
log.Fatal(err)
}
goals, err := data.GetGoalsByUserId(ctx.Value(userIdKey).(int))
if err != nil {
log.Fatal(err)
}
user, err := data.UserByEmail(ctx.Value(userEmailKey).(string))
if err != nil {
log.Fatal(err)
}
fmt.Println(user, "user..")
d := struct {
Tasks []data.TaskWithSubTasks
Goals []data.Goal
User data.User
}{
Tasks: tasks,
Goals: goals,
User: user,
}
generateHTML(w, d, "layout", "planner")
}
// TODO: GET -> Error page