6 "github.com/gin-gonic/gin"
7 common "github.com/iotbzh/xds-common/golib"
10 // EventRegisterArgs is the parameters (json format) of /events/register command
11 type EventRegisterArgs struct {
12 Name string `json:"name"`
13 ProjectID string `json:"filterProjectID"`
16 // EventUnRegisterArgs is the parameters (json format) of /events/unregister command
17 type EventUnRegisterArgs struct {
18 Name string `json:"name"`
22 // eventsList Registering for events that will be send over a WS
23 func (s *APIService) eventsList(c *gin.Context) {
24 c.JSON(http.StatusOK, s.events.GetList())
27 // eventsRegister Registering for events that will be send over a WS
28 func (s *APIService) eventsRegister(c *gin.Context) {
29 var args EventRegisterArgs
31 if c.BindJSON(&args) != nil || args.Name == "" {
32 common.APIError(c, "Invalid arguments")
36 sess := s.webServer.sessions.Get(c)
38 common.APIError(c, "Unknown sessions")
42 // Register to all or to a specific events
43 if err := s.events.Register(args.Name, sess.ID); err != nil {
44 common.APIError(c, err.Error())
48 c.JSON(http.StatusOK, gin.H{"status": "OK"})
51 // eventsRegister Registering for events that will be send over a WS
52 func (s *APIService) eventsUnRegister(c *gin.Context) {
53 var args EventUnRegisterArgs
55 if c.BindJSON(&args) != nil || args.Name == "" {
56 common.APIError(c, "Invalid arguments")
60 sess := s.webServer.sessions.Get(c)
62 common.APIError(c, "Unknown sessions")
66 // Register to all or to a specific events
67 if err := s.events.UnRegister(args.Name, sess.ID); err != nil {
68 common.APIError(c, err.Error())
72 c.JSON(http.StatusOK, gin.H{"status": "OK"})