mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 23:42:29 -05:00
Make SecurityType its own type
This commit is contained in:
parent
6fb66ac04e
commit
f2a45dc6b6
@ -22,7 +22,7 @@ func (i *OFXImport) GetSecurity(ofxsecurityid int64) (*Security, error) {
|
|||||||
return &i.Securities[ofxsecurityid], nil
|
return &i.Securities[ofxsecurityid], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *OFXImport) GetSecurityAlternateId(alternateid string, securityType int64) (*Security, error) {
|
func (i *OFXImport) GetSecurityAlternateId(alternateid string, securityType SecurityType) (*Security, error) {
|
||||||
for _, security := range i.Securities {
|
for _, security := range i.Securities {
|
||||||
if alternateid == security.AlternateId && securityType == security.Type {
|
if alternateid == security.AlternateId && securityType == security.Type {
|
||||||
return &security, nil
|
return &security, nil
|
||||||
|
@ -13,12 +13,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SecurityType int64
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Currency int64 = 1
|
Currency SecurityType = 1
|
||||||
Stock = 2
|
Stock = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSecurityType(typestring string) int64 {
|
func GetSecurityType(typestring string) SecurityType {
|
||||||
if strings.EqualFold(typestring, "currency") {
|
if strings.EqualFold(typestring, "currency") {
|
||||||
return Currency
|
return Currency
|
||||||
} else if strings.EqualFold(typestring, "stock") {
|
} else if strings.EqualFold(typestring, "stock") {
|
||||||
@ -37,7 +39,7 @@ type Security struct {
|
|||||||
// Number of decimal digits (to the right of the decimal point) this
|
// Number of decimal digits (to the right of the decimal point) this
|
||||||
// security is precise to
|
// security is precise to
|
||||||
Precision int
|
Precision int
|
||||||
Type int64
|
Type SecurityType
|
||||||
// AlternateId is CUSIP for Type=Stock, ISO4217 for Type=Currency
|
// AlternateId is CUSIP for Type=Stock, ISO4217 for Type=Currency
|
||||||
AlternateId string
|
AlternateId string
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ func (sl *SecurityList) Write(w http.ResponseWriter) error {
|
|||||||
return enc.Encode(sl)
|
return enc.Encode(sl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchSecurityTemplates(search string, _type int64, limit int64) []*Security {
|
func SearchSecurityTemplates(search string, _type SecurityType, limit int64) []*Security {
|
||||||
upperSearch := strings.ToUpper(search)
|
upperSearch := strings.ToUpper(search)
|
||||||
var results []*Security
|
var results []*Security
|
||||||
for i, security := range SecurityTemplates {
|
for i, security := range SecurityTemplates {
|
||||||
@ -84,7 +86,7 @@ func SearchSecurityTemplates(search string, _type int64, limit int64) []*Securit
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindSecurityTemplate(name string, _type int64) *Security {
|
func FindSecurityTemplate(name string, _type SecurityType) *Security {
|
||||||
for _, security := range SecurityTemplates {
|
for _, security := range SecurityTemplates {
|
||||||
if name == security.Name && _type == security.Type {
|
if name == security.Name && _type == security.Type {
|
||||||
return &security
|
return &security
|
||||||
@ -349,7 +351,7 @@ func SecurityTemplateHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
var limit int64 = -1
|
var limit int64 = -1
|
||||||
search := query.Get("search")
|
search := query.Get("search")
|
||||||
|
|
||||||
var _type int64 = 0
|
var _type SecurityType = 0
|
||||||
typestring := query.Get("type")
|
typestring := query.Get("type")
|
||||||
if len(typestring) > 0 {
|
if len(typestring) > 0 {
|
||||||
_type = GetSecurityType(typestring)
|
_type = GetSecurityType(typestring)
|
||||||
|
Loading…
Reference in New Issue
Block a user