1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-06-13 21:48:39 -04:00

Split reports into models

This commit is contained in:
2017-12-05 05:58:36 -05:00
parent 5f296e8669
commit 3e3038295d
7 changed files with 122 additions and 117 deletions

View File

@ -0,0 +1,66 @@
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 {
Reports *[]Report `json:"reports"`
}
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)
}