Make SecurityType its own type

This commit is contained in:
Aaron Lindsay 2017-11-05 20:43:32 -05:00
parent 6fb66ac04e
commit f2a45dc6b6
2 changed files with 10 additions and 8 deletions

View File

@ -22,7 +22,7 @@ func (i *OFXImport) GetSecurity(ofxsecurityid int64) (*Security, error) {
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 {
if alternateid == security.AlternateId && securityType == security.Type {
return &security, nil

View File

@ -13,12 +13,14 @@ import (
"strings"
)
type SecurityType int64
const (
Currency int64 = 1
Stock = 2
Currency SecurityType = 1
Stock = 2
)
func GetSecurityType(typestring string) int64 {
func GetSecurityType(typestring string) SecurityType {
if strings.EqualFold(typestring, "currency") {
return Currency
} 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
// security is precise to
Precision int
Type int64
Type SecurityType
// AlternateId is CUSIP for Type=Stock, ISO4217 for Type=Currency
AlternateId string
}
@ -66,7 +68,7 @@ func (sl *SecurityList) Write(w http.ResponseWriter) error {
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)
var results []*Security
for i, security := range SecurityTemplates {
@ -84,7 +86,7 @@ func SearchSecurityTemplates(search string, _type int64, limit int64) []*Securit
return results
}
func FindSecurityTemplate(name string, _type int64) *Security {
func FindSecurityTemplate(name string, _type SecurityType) *Security {
for _, security := range SecurityTemplates {
if name == security.Name && _type == security.Type {
return &security
@ -349,7 +351,7 @@ func SecurityTemplateHandler(w http.ResponseWriter, r *http.Request) {
var limit int64 = -1
search := query.Get("search")
var _type int64 = 0
var _type SecurityType = 0
typestring := query.Get("type")
if len(typestring) > 0 {
_type = GetSecurityType(typestring)