-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyNotificationsList.go
56 lines (52 loc) · 1.37 KB
/
myNotificationsList.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
package main
import (
"encoding/json"
"net/http"
"github.com/globalsign/mgo/bson"
)
func myNotificationsListPage(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
if r.FormValue("userId") == "" {
writeResponse(w, requiredInputError("userId"))
} else {
var control, str = myNotificationsList(r.FormValue("userId"))
if control != nil {
writeResponse(w, string(control))
} else {
if str == "NotFound" {
writeResponse(w, notFindRecordError())
} else if str == "ID" {
writeResponse(w, incorrectInput("ID"))
} else {
writeResponse(w, someThingWentWrong())
}
}
}
} else {
writeResponse(w, notValidRequestError(r.Method))
}
}
func myNotificationsList(userID string) ([]byte, string) {
var data []byte
var l []*MyNotifications
var notification *MyNotifications
person := &NotificationForUser{}
id, errID := checkObjID(userID)
if errID == true {
notifications := connection.Collection("notifications").Find(bson.M{"user_id": bson.ObjectIdHex(id)})
for notifications.Next(person) {
notification = &MyNotifications{person.Title, person.Description, person.Created}
l = append(l, notification)
}
data, _ = json.Marshal(l)
if l == nil {
return nil, "NotFound"
}
if l != nil {
response := &MyNotificationsArr{l}
data, _ = json.Marshal(response)
return addError(data), ""
}
}
return data, "ID"
}