go-mcm/model/alert.go

46 lines
918 B
Go

package model
import (
"encoding/json"
"git.canopymc.net/Etzelia/go-mcm/internal"
"git.canopymc.net/Etzelia/go-mcm/model/django"
)
type Alert struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
Message string `json:"message"`
Seen bool `json:"seen"`
Date string `json:"date"`
Link string `json:"link"`
model *Model `json:"-"`
}
func (q *Model) Alert(builder *django.Builder) ([]*Alert, error) {
endpoint := q.queryEndpoint("alert", builder.QueryString())
alerts := make([]*Alert, 0)
resp, err := internal.ResponseGet(endpoint)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &alerts)
if err != nil {
return nil, err
}
for _, alert := range alerts {
alert.model = q
}
return alerts, nil
}
func (a *Alert) Save() (*internal.Status, error) {
endpoint := a.model.endpoint("alert")
return internal.ResponseStatus(endpoint, a.model.Values(a))
}