-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
api.go
42 lines (33 loc) · 781 Bytes
/
api.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
package main
import (
"encoding/json"
"log"
"net/http"
"gopkg.in/mgo.v2/bson"
)
func Me(w http.ResponseWriter, r *http.Request) {
tokenData := GetToken(w, r)
db := GetDB(w, r)
user, errM := FindUserById(db, bson.ObjectIdHex(tokenData.ID))
if errM != nil {
HandleModelError(w, r, errM)
return
}
b, _ := json.Marshal(user)
parse := &Response{}
json.Unmarshal(b, parse)
ServeJSON(w, r, parse, http.StatusOK)
}
func UpdateAccount(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var userData User
err := decoder.Decode(&userData)
if err != nil {
log.Println(err)
return
}
tokenData := GetToken(w, r)
db := GetDB(w, r)
UpdateUserById(db, bson.ObjectIdHex(tokenData.ID), userData.Email, userData.DisplayName)
Me(w, r)
}