forked from pclubiitk/puppy-love
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.go
84 lines (68 loc) · 1.51 KB
/
list.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package controllers
import (
"log"
"net/http"
"github.com/pclubiitk/puppy-love/models"
"github.com/gin-gonic/gin"
"gopkg.in/mgo.v2/bson"
)
// @AUTH Get user's basic information
// ---------------------------------------
type typeListAll struct {
Id string `json:"_id" bson:"_id"`
Name string `json:"name" bson:"name"`
Email string `json:"email" bson:"email"`
Image string `json:"image" bson:"image"`
}
func ListAll(c *gin.Context) {
var results []typeListAll
// Fetch user
if err := Db.GetCollection("user").
Find(bson.M{}).
All(&results); err != nil {
c.AbortWithStatus(http.StatusNotFound)
log.Print(err)
return
}
c.JSON(http.StatusAccepted, results)
}
func PubkeyList(c *gin.Context) {
var query [](struct {
Id string `json:"_id" bson:"_id"`
PK string `json:"pubKey" bson:"pubKey"`
})
if err := Db.GetCollection("user").
Find(bson.M{"dirty": false}).
All(&query); err != nil {
c.AbortWithStatus(http.StatusNotFound)
log.Print(err)
return
}
c.JSON(http.StatusAccepted, query)
}
func DeclareList(c *gin.Context) {
id, err := SessionId(c)
if err != nil {
c.AbortWithStatus(http.StatusForbidden)
return
}
var resp models.Declare
if err := Db.GetById("declare", id).One(&resp); err != nil {
c.AbortWithStatus(http.StatusNotFound)
log.Print(err)
return
}
if resp.Token0 != "" {
resp.Token0 = "1"
}
if resp.Token1 != "" {
resp.Token1 = "1"
}
if resp.Token2 != "" {
resp.Token2 = "1"
}
if resp.Token3 != "" {
resp.Token3 = "1"
}
c.JSON(http.StatusOK, resp)
}