Added arn to the main repository
This commit is contained in:
41
arn/AnalyticsAPI.go
Normal file
41
arn/AnalyticsAPI.go
Normal file
@ -0,0 +1,41 @@
|
||||
package arn
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/aerogo/api"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// Force interface implementations
|
||||
var (
|
||||
_ api.Newable = (*Analytics)(nil)
|
||||
)
|
||||
|
||||
// Authorize returns an error if the given API POST request is not authorized.
|
||||
func (analytics *Analytics) Authorize(ctx aero.Context, action string) error {
|
||||
return AuthorizeIfLoggedIn(ctx)
|
||||
}
|
||||
|
||||
// Create creates a new analytics object.
|
||||
func (analytics *Analytics) Create(ctx aero.Context) error {
|
||||
body, err := ctx.Request().Body().Bytes()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = jsoniter.Unmarshal(body, analytics)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
analytics.UserID = GetUserFromContext(ctx).ID
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Save saves the analytics in the database.
|
||||
func (analytics *Analytics) Save() {
|
||||
DB.Set("Analytics", analytics.UserID, analytics)
|
||||
}
|
Reference in New Issue
Block a user