1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-11-01 00:10:06 -04:00
moneygo/internal/models/reports.go

67 lines
1.3 KiB
Go
Raw Normal View History

2017-12-05 05:58:36 -05:00
package models
import (
"encoding/json"
"net/http"
"strings"
)
type Report struct {
ReportId int64
UserId int64
Name string
Lua string
}
// The maximum length (in bytes) the Lua code may be. This is used to set the
// max size of the database columns (with an added fudge factor)
const LuaMaxLength int = 65536
func (r *Report) Write(w http.ResponseWriter) error {
enc := json.NewEncoder(w)
return enc.Encode(r)
}
func (r *Report) Read(json_str string) error {
dec := json.NewDecoder(strings.NewReader(json_str))
return dec.Decode(r)
}
type ReportList struct {
2017-12-09 05:56:45 -05:00
Reports *[]*Report `json:"reports"`
2017-12-05 05:58:36 -05:00
}
func (rl *ReportList) Write(w http.ResponseWriter) error {
enc := json.NewEncoder(w)
return enc.Encode(rl)
}
func (rl *ReportList) Read(json_str string) error {
dec := json.NewDecoder(strings.NewReader(json_str))
return dec.Decode(rl)
}
type Series struct {
Values []float64
Series map[string]*Series
}
type Tabulation struct {
ReportId int64
Title string
Subtitle string
Units string
Labels []string
Series map[string]*Series
}
func (t *Tabulation) Write(w http.ResponseWriter) error {
enc := json.NewEncoder(w)
return enc.Encode(t)
}
func (t *Tabulation) Read(json_str string) error {
dec := json.NewDecoder(strings.NewReader(json_str))
return dec.Decode(t)
}