-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_collections.go
58 lines (51 loc) · 1.24 KB
/
api_collections.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
package neocortex
import (
"net/http"
"github.com/gin-gonic/gin"
)
func (api *API) registerCollectionsAPI(r *gin.RouterGroup) {
r.GET("/collections/:type", func(c *gin.Context) {
t := c.Param("type")
if t != "all" {
switch t {
case "entity", "entities":
ents := api.repository.Entities()
c.JSON(http.StatusOK, gin.H{
"data": ents,
})
return
case "intent", "intents":
ints := api.repository.Intents()
c.JSON(http.StatusOK, gin.H{
"data": ints,
})
return
case "node", "dialog", "nodes", "dialog_nodes", "dialogs":
nodes := api.repository.DialogNodes()
c.JSON(http.StatusOK, gin.H{
"data": nodes,
})
return
case "context_vars", "vars":
vars := api.repository.ContextVars()
c.JSON(http.StatusOK, gin.H{
"data": vars,
})
return
default:
c.JSON(http.StatusInternalServerError, gin.H{"error": "invalid type of collection"})
return
}
}
ents := api.repository.Entities()
ints := api.repository.Intents()
nodes := api.repository.DialogNodes()
vars := api.repository.ContextVars()
c.JSON(http.StatusOK, gin.H{"data": gin.H{
"intents": ints,
"entities": ents,
"nodes": nodes,
"context_vars": vars,
}})
})
}