yats.git

ref: 1fb480ce72eacc96d9f7495d67b9b0ec0313fd41

server/rest/rest-event.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
package rest

import (
	"fmt"
	"net/http"
	"time"
	"yats-server/db"
	"yats-server/model"

	"github.com/gin-gonic/gin"
)

func WriteEventNow(c *gin.Context) {
	var event model.EventRequest

	if err := c.BindJSON(&event); err != nil {
		c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "-1"})
		return
	}

	fmt.Printf("%s / %s ", event.ID_client, event.Name)
	db.SaveEvent(event.ID_client, event.Name)

	c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "0"})
}

func WriteEventcAt(c *gin.Context) {
	var event model.EventRequest

	if err := c.BindJSON(&event); err != nil {
		c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "-1"})
		return
	}

	fmt.Printf("%s / %s ", event.ID_client, event.Name)

	unixTimeUTC := time.Unix(event.Etime, 0)
	db.SaveEventAt(event.ID_client, unixTimeUTC, event.Name)

	c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "OK"})
}