forked from ccbrown/gggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity_handler.go
More file actions
43 lines (39 loc) · 894 Bytes
/
Copy pathactivity_handler.go
File metadata and controls
43 lines (39 loc) · 894 Bytes
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
package server
import (
"github.com/labstack/echo"
)
type jsonResponseActivity struct {
Type string `json:"type"`
Data Activity `json:"data"`
}
type jsonResponse struct {
Activity []*jsonResponseActivity `json:"activity"`
Next string `json:"next"`
}
func ActivityHandler(db Database) echo.HandlerFunc {
return func(c echo.Context) error {
activity, next, err := db.Activity(LocaleForRequest(c.Request()), c.QueryParam("next"), 50)
if err != nil {
return err
}
response := jsonResponse{
Next: next,
}
for _, a := range activity {
t := ""
switch a.(type) {
case *ForumPost:
t = "forum_post"
case *RedditComment:
t = "reddit_comment"
case *RedditPost:
t = "reddit_post"
}
response.Activity = append(response.Activity, &jsonResponseActivity{
Type: t,
Data: a,
})
}
return c.JSON(200, response)
}
}