| 1 |
package server |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
|
| 6 |
"github.com/gin-gonic/gin" |
| 7 |
"github.com/henrybear327/go-proton-api" |
| 8 |
) |
| 9 |
|
| 10 |
func (s *Server) handleGetEvents() gin.HandlerFunc { |
| 11 |
return func(c *gin.Context) { |
| 12 |
event, more, err := s.b.GetEvent(c.GetString("UserID"), c.Param("eventID")) |
| 13 |
if err != nil { |
| 14 |
_ = c.AbortWithError(http.StatusBadRequest, err) |
| 15 |
return |
| 16 |
} |
| 17 |
|
| 18 |
c.JSON( |
| 19 |
http.StatusOK, |
| 20 |
struct { |
| 21 |
proton.Event |
| 22 |
More proton.Bool |
| 23 |
}{ |
| 24 |
event, |
| 25 |
proton.Bool(more), |
| 26 |
}, |
| 27 |
) |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
func (s *Server) handleGetEventsLatest() gin.HandlerFunc { |
| 32 |
return func(c *gin.Context) { |
| 33 |
eventID, err := s.b.GetLatestEventID(c.GetString("UserID")) |
| 34 |
if err != nil { |
| 35 |
_ = c.AbortWithError(http.StatusBadRequest, err) |
| 36 |
return |
| 37 |
} |
| 38 |
|
| 39 |
c.JSON(http.StatusOK, gin.H{ |
| 40 |
"EventID": eventID, |
| 41 |
}) |
| 42 |
} |
| 43 |
} |