/
boardlog.go
53 lines (41 loc) · 1.14 KB
/
boardlog.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
package controllers
import (
"encoding/json"
"github.com/gin-gonic/gin"
e "github.com/eirka/eirka-libs/errors"
"github.com/eirka/eirka-admin/models"
)
// BoardLogController will get the the board audit log
func BoardLogController(c *gin.Context) {
// Get parameters from validate middleware
params := c.MustGet("params").([]uint)
if !c.MustGet("protected").(bool) {
c.JSON(e.ErrorMessage(e.ErrInternalError))
c.Error(e.ErrInternalError).SetMeta("BoardLogController.protected")
return
}
// Initialize model struct
m := &models.BoardLogModel{
Ib: params[0],
Page: params[1],
}
// Get the model which outputs JSON
err := m.Get()
if err == e.ErrNotFound {
c.JSON(e.ErrorMessage(e.ErrNotFound))
c.Error(err).SetMeta("BoardLogController.Get")
return
} else if err != nil {
c.JSON(e.ErrorMessage(e.ErrInternalError))
c.Error(err).SetMeta("BoardLogController.Get")
return
}
// Marshal the structs into JSON
output, err := json.Marshal(m.Result)
if err != nil {
c.JSON(e.ErrorMessage(e.ErrInternalError))
c.Error(err).SetMeta("BoardLogController.json.Marshal")
return
}
c.Data(200, "application/json", output)
}