-
Notifications
You must be signed in to change notification settings - Fork 2
/
route.go
80 lines (67 loc) · 1.99 KB
/
route.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
package fastapi
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/shoppehub/commons"
"github.com/shoppehub/fastapi/collection"
"github.com/shoppehub/fastapi/crud"
"github.com/shoppehub/fastapi/engine"
"github.com/shoppehub/fastapi/session"
)
func InitApi(resource *crud.Resource, r *gin.Engine) {
session.Init(resource, r)
apiv1 := r.Group("/api/v1")
{
apiv1.GET("/getip", func(c *gin.Context) {
ip := session.GetIP(c.Request)
c.JSON(http.StatusOK, gin.H{
"ip": ip,
})
})
// apiv1.GET("/user", func(c *gin.Context) {
// c.JSON(http.StatusOK, session.GetUserSession(c.Request))
// })
// apiv1.GET("/user/login", func(c *gin.Context) {
// s := session.NewUserSession(resource, primitive.NewObjectID().Hex(), c.Request, c.Writer)
// c.JSON(http.StatusOK, s)
// })
apiv1.POST("/collection", func(c *gin.Context) {
collection.CreateCollection(resource, c)
})
apiv1.GET("/collection/:id", func(c *gin.Context) {
collection.GetCollection(resource, c)
})
apiv1.GET("/findcollection", func(c *gin.Context) {
name := c.Query("name")
fieldMap := collection.FindOneCollection(resource, name)
c.JSON(http.StatusOK, commons.ActionResponse{
Success: true,
Data: fieldMap,
})
})
apiv1.POST("/collections", func(c *gin.Context) {
collection.QueryCollection(resource, c)
})
}
apicol := r.Group("/api/collection")
{
apicol.GET("/:group/:collection/:id", func(c *gin.Context) {
engine.GetWithId(resource, c)
})
apicol.POST("/findone/:group/:collection", func(c *gin.Context) {
engine.FindOne(resource, c)
})
apicol.POST("/save/:group/:collection", func(c *gin.Context) {
engine.Post(resource, c)
})
apicol.POST("/delete/:group/:collection/:id", func(c *gin.Context) {
engine.DeleteId(resource, c)
})
apicol.POST("/query/:group/:collection", func(c *gin.Context) {
engine.Query(resource, c)
})
apicol.POST("/func/:group/:collection/:func", func(c *gin.Context) {
engine.Func(resource, c)
})
}
}