Added viewing logs via api
This commit is contained in:
parent
91e10eb78b
commit
3de6ecf579
|
@ -29,3 +29,12 @@ func logAction(actionType ActionType, user *User, itemID int64) (err error) {
|
|||
_, err = x.Insert(UserLog{Log: actionType, UserID: user.ID, ItemID: itemID})
|
||||
return
|
||||
}
|
||||
|
||||
func GetAllLogs() (logs []UserLog, err error) {
|
||||
err = x.OrderBy("id DESC").Find(&logs)
|
||||
if err != nil {
|
||||
return logs, err
|
||||
}
|
||||
|
||||
return logs, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"git.kolaente.de/konrad/Library/models"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ShowLogs(c echo.Context) error {
|
||||
|
||||
// Check if the user is admin
|
||||
if !models.IsAdmin(c) {
|
||||
return echo.ErrUnauthorized
|
||||
}
|
||||
|
||||
// Get the logs
|
||||
logs, err := models.GetAllLogs()
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting logs."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, logs)
|
||||
}
|
|
@ -119,6 +119,9 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
a.DELETE("/users/:id", apiv1.UserDelete)
|
||||
a.POST("/users/:id/password", apiv1.UserChangePassword)
|
||||
|
||||
// View logs
|
||||
a.GET("/logs", apiv1.ShowLogs)
|
||||
|
||||
/*
|
||||
Alles nur mit Api machen, davor dann einen onepager mit vue.js.
|
||||
|
||||
|
|
Loading…
Reference in New Issue