-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentHandler.go
49 lines (42 loc) · 1.33 KB
/
studentHandler.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
package main
import (
"encoding/json"
"html/template"
"net/http"
"github.com/gorilla/mux"
)
func StudentHandler(router *mux.Router) {
router.HandleFunc("/student", func(res http.ResponseWriter, req *http.Request) {
t, err := template.ParseFiles("templates/student/index.html")
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
t.Execute(res, nil)
}).Methods("GET")
router.HandleFunc("/student/get-folder-id", func(res http.ResponseWriter, req *http.Request) {
folderID, err := GetStudentFolder(req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
response := map[string]string{"folder_id": folderID}
res.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(res).Encode(response); err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
}
}).Methods("GET")
router.HandleFunc("/student/profile", func(res http.ResponseWriter, req *http.Request) {
student, err := GetCurrentStudent(req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
t, err := template.ParseFiles("templates/student/profile.html")
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
t.Execute(res, student)
}).Methods("GET")
}