1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-03 12:48:38 -04:00

Split Lua reports into own package

This commit is contained in:
2017-12-10 20:50:37 -05:00
parent ac8afec6c1
commit d5bea1102d
11 changed files with 138 additions and 130 deletions

View File

@ -5,7 +5,6 @@ import (
"github.com/aclindsa/moneygo/internal/store"
"log"
"net/http"
"time"
)
func CreatePriceIfNotExist(tx store.Tx, price *models.Price) error {
@ -33,27 +32,6 @@ func CreatePriceIfNotExist(tx store.Tx, price *models.Price) error {
return nil
}
// Return the price for security in currency closest to date
func GetClosestPrice(tx store.Tx, security, currency *models.Security, date *time.Time) (*models.Price, error) {
earliest, _ := tx.GetEarliestPrice(security, currency, date)
latest, err := tx.GetLatestPrice(security, currency, date)
// Return early if either earliest or latest are invalid
if earliest == nil {
return latest, err
} else if err != nil {
return earliest, nil
}
howlate := earliest.Date.Sub(*date)
howearly := date.Sub(latest.Date)
if howearly < howlate {
return latest, nil
} else {
return earliest, nil
}
}
func PriceHandler(r *http.Request, context *Context, user *models.User, securityid int64) ResponseWriterWriter {
security, err := context.Tx.GetSecurity(securityid, user.UserId)
if err != nil {