mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-06-13 21:48:39 -04:00
Split prices into models
This commit is contained in:
41
internal/models/prices.go
Normal file
41
internal/models/prices.go
Normal file
@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Price struct {
|
||||
PriceId int64
|
||||
SecurityId int64
|
||||
CurrencyId int64
|
||||
Date time.Time
|
||||
Value string // String representation of decimal price of Security in Currency units, suitable for passing to big.Rat.SetString()
|
||||
RemoteId string // unique ID from source, for detecting duplicates
|
||||
}
|
||||
|
||||
type PriceList struct {
|
||||
Prices *[]*Price `json:"prices"`
|
||||
}
|
||||
|
||||
func (p *Price) Read(json_str string) error {
|
||||
dec := json.NewDecoder(strings.NewReader(json_str))
|
||||
return dec.Decode(p)
|
||||
}
|
||||
|
||||
func (p *Price) Write(w http.ResponseWriter) error {
|
||||
enc := json.NewEncoder(w)
|
||||
return enc.Encode(p)
|
||||
}
|
||||
|
||||
func (pl *PriceList) Read(json_str string) error {
|
||||
dec := json.NewDecoder(strings.NewReader(json_str))
|
||||
return dec.Decode(pl)
|
||||
}
|
||||
|
||||
func (pl *PriceList) Write(w http.ResponseWriter) error {
|
||||
enc := json.NewEncoder(w)
|
||||
return enc.Encode(pl)
|
||||
}
|
Reference in New Issue
Block a user