handlers

package
v0.0.0-...-0ad7c06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePriceIfNotExist

func CreatePriceIfNotExist(tx store.Tx, price *models.Price) error

func DeleteSessionIfExists

func DeleteSessionIfExists(tx store.Tx, r *http.Request) error

func FindCurrencyTemplate

func FindCurrencyTemplate(iso4217 int64) *models.Security

func FindSecurityTemplate

func FindSecurityTemplate(name string, _type models.SecurityType) *models.Security

func GetCreateAccount

func GetCreateAccount(tx store.Tx, a models.Account) (*models.Account, error)

Get (and attempt to create if it doesn't exist). Matches on UserId, SecurityId, Type, Name, and ParentAccountId

func GetImbalanceAccount

func GetImbalanceAccount(tx store.Tx, userid int64, securityid int64) (*models.Account, error)

Get (and attempt to create if it doesn't exist) the security/currency imbalance account for the supplied security/currency

func GetSession

func GetSession(tx store.Tx, r *http.Request) (*models.Session, error)

func GetTradingAccount

func GetTradingAccount(tx store.Tx, userid int64, securityid int64) (*models.Account, error)

Get (and attempt to create if it doesn't exist) the security/currency trading account for the supplied security/currency

func GetTransactionImbalances

func GetTransactionImbalances(tx store.Tx, t *models.Transaction) (map[int64]big.Rat, error)

Return a map of security ID's to big.Rat's containing the amount that security is imbalanced by

func GetUserFromSession

func GetUserFromSession(tx store.Tx, r *http.Request) (*models.User, error)

func ImportGetCreateSecurity

func ImportGetCreateSecurity(tx store.Tx, userid int64, security *models.Security) (*models.Security, error)

func InsertUser

func InsertUser(tx store.Tx, u *models.User) error

func ReadJSON

func ReadJSON(r *http.Request, v interface{}) error

func SearchSecurityTemplates

func SearchSecurityTemplates(search string, _type models.SecurityType, limit int64) []*models.Security

func TransactionBalanced

func TransactionBalanced(tx store.Tx, t *models.Transaction) (bool, error)

Returns true if all securities contained in this transaction are balanced, false otherwise

func UpdateSecurity

func UpdateSecurity(tx store.Tx, s *models.Security) (err error)

func UpdateUser

func UpdateUser(tx store.Tx, u *models.User) error

Types

type APIHandler

type APIHandler struct {
	Store store.Store
}

func (*APIHandler) ServeHTTP

func (ah *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Context

type Context struct {
	Tx   store.Tx
	User *models.User
	// contains filtered or unexported fields
}

func (*Context) LastLevel

func (c *Context) LastLevel() bool

func (*Context) NextID

func (c *Context) NextID() (int64, error)

func (*Context) NextLevel

func (c *Context) NextLevel() string

func (*Context) SetURL

func (c *Context) SetURL(url string)

type Error

type Error struct {
	ErrorId     int
	ErrorString string
}

func NewError

func NewError(error_code int) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Read

func (e *Error) Read(json_str string) error

func (*Error) Write

func (e *Error) Write(w http.ResponseWriter) error

type GnucashAccount

type GnucashAccount struct {
	Version string `xml:"version,attr"`

	AccountId       string              `xml:"http://www.gnucash.org/XML/act id"`
	ParentAccountId string              `xml:"http://www.gnucash.org/XML/act parent"`
	Name            string              `xml:"http://www.gnucash.org/XML/act name"`
	Description     string              `xml:"http://www.gnucash.org/XML/act description"`
	Type            string              `xml:"http://www.gnucash.org/XML/act type"`
	Commodity       GnucashXMLCommodity `xml:"http://www.gnucash.org/XML/act commodity"`
	// contains filtered or unexported fields
}

type GnucashCommodity

type GnucashCommodity struct{ models.Security }

func (*GnucashCommodity) UnmarshalXML

func (gc *GnucashCommodity) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type GnucashDate

type GnucashDate struct {
	Date GnucashTime `xml:"http://www.gnucash.org/XML/ts date"`
}

type GnucashImport

type GnucashImport struct {
	Securities   []models.Security
	Accounts     []models.Account
	Transactions []models.Transaction
	Prices       []models.Price
}

func ImportGnucash

func ImportGnucash(r io.Reader) (*GnucashImport, error)

type GnucashPrice

type GnucashPrice struct {
	Id        string           `xml:"http://www.gnucash.org/XML/price id"`
	Commodity GnucashCommodity `xml:"http://www.gnucash.org/XML/price commodity"`
	Currency  GnucashCommodity `xml:"http://www.gnucash.org/XML/price currency"`
	Date      GnucashDate      `xml:"http://www.gnucash.org/XML/price time"`
	Source    string           `xml:"http://www.gnucash.org/XML/price source"`
	Type      string           `xml:"http://www.gnucash.org/XML/price type"`
	Value     string           `xml:"http://www.gnucash.org/XML/price value"`
}

type GnucashPriceDB

type GnucashPriceDB struct {
	Prices []GnucashPrice `xml:"price"`
}

type GnucashSplit

type GnucashSplit struct {
	SplitId   string `xml:"http://www.gnucash.org/XML/split id"`
	Status    string `xml:"http://www.gnucash.org/XML/split reconciled-state"`
	AccountId string `xml:"http://www.gnucash.org/XML/split account"`
	Memo      string `xml:"http://www.gnucash.org/XML/split memo"`
	Amount    string `xml:"http://www.gnucash.org/XML/split quantity"`
	Value     string `xml:"http://www.gnucash.org/XML/split value"`
}

type GnucashTime

type GnucashTime struct{ time.Time }

func (*GnucashTime) UnmarshalXML

func (g *GnucashTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type GnucashTransaction

type GnucashTransaction struct {
	TransactionId string              `xml:"http://www.gnucash.org/XML/trn id"`
	Description   string              `xml:"http://www.gnucash.org/XML/trn description"`
	Number        string              `xml:"http://www.gnucash.org/XML/trn num"`
	DatePosted    GnucashDate         `xml:"http://www.gnucash.org/XML/trn date-posted"`
	DateEntered   GnucashDate         `xml:"http://www.gnucash.org/XML/trn date-entered"`
	Commodity     GnucashXMLCommodity `xml:"http://www.gnucash.org/XML/trn currency"`
	Splits        []GnucashSplit      `xml:"http://www.gnucash.org/XML/trn splits>split"`
}

type GnucashXMLCommodity

type GnucashXMLCommodity struct {
	Name        string `xml:"http://www.gnucash.org/XML/cmdty id"`
	Description string `xml:"http://www.gnucash.org/XML/cmdty name"`
	Type        string `xml:"http://www.gnucash.org/XML/cmdty space"`
	Fraction    int    `xml:"http://www.gnucash.org/XML/cmdty fraction"`
	XCode       string `xml:"http://www.gnucash.org/XML/cmdty xcode"`
}

type GnucashXMLImport

type GnucashXMLImport struct {
	XMLName      xml.Name             `xml:"gnc-v2"`
	Commodities  []GnucashCommodity   `xml:"http://www.gnucash.org/XML/gnc book>commodity"`
	PriceDB      GnucashPriceDB       `xml:"http://www.gnucash.org/XML/gnc book>pricedb"`
	Accounts     []GnucashAccount     `xml:"http://www.gnucash.org/XML/gnc book>account"`
	Transactions []GnucashTransaction `xml:"http://www.gnucash.org/XML/gnc book>transaction"`
}

type Handler

type Handler func(*http.Request, *Context) ResponseWriterWriter

type NewSessionWriter

type NewSessionWriter struct {
	// contains filtered or unexported fields
}

func NewSession

func NewSession(tx store.Tx, r *http.Request, userid int64) (*NewSessionWriter, error)

func (*NewSessionWriter) Write

type OFXDownload

type OFXDownload struct {
	OFXPassword string
	StartDate   time.Time
	EndDate     time.Time
}

func (*OFXDownload) Read

func (od *OFXDownload) Read(json_str string) error

type OFXImport

type OFXImport struct {
	Securities   []models.Security
	Accounts     []models.Account
	Transactions []models.Transaction
}

func ImportOFX

func ImportOFX(r io.Reader) (*OFXImport, error)

func (*OFXImport) AddInvTransaction

func (i *OFXImport) AddInvTransaction(invtran *ofxgo.InvTransaction, account *models.Account, curdef *models.Security) error

func (*OFXImport) AddTransaction

func (i *OFXImport) AddTransaction(tran *ofxgo.Transaction, account *models.Account) error

func (*OFXImport) GetAddCurrency

func (i *OFXImport) GetAddCurrency(isoname string) (*models.Security, error)

func (*OFXImport) GetIncomeTran

func (i *OFXImport) GetIncomeTran(income *ofxgo.Income, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetInvBuyTran

func (i *OFXImport) GetInvBuyTran(buy *ofxgo.InvBuy, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetInvExpenseTran

func (i *OFXImport) GetInvExpenseTran(expense *ofxgo.InvExpense, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetInvSellTran

func (i *OFXImport) GetInvSellTran(sell *ofxgo.InvSell, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetInvTran

func (i *OFXImport) GetInvTran(invtran *ofxgo.InvTran) models.Transaction

func (*OFXImport) GetMarginInterestTran

func (i *OFXImport) GetMarginInterestTran(marginint *ofxgo.MarginInterest, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetReinvestTran

func (i *OFXImport) GetReinvestTran(reinvest *ofxgo.Reinvest, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetRetOfCapTran

func (i *OFXImport) GetRetOfCapTran(retofcap *ofxgo.RetOfCap, curdef *models.Security, account *models.Account) (*models.Transaction, error)

func (*OFXImport) GetSecurity

func (i *OFXImport) GetSecurity(ofxsecurityid int64) (*models.Security, error)

func (*OFXImport) GetSecurityAlternateId

func (i *OFXImport) GetSecurityAlternateId(alternateid string, securityType models.SecurityType) (*models.Security, error)

func (*OFXImport) GetTransferTran

func (i *OFXImport) GetTransferTran(transfer *ofxgo.Transfer, account *models.Account) (*models.Transaction, error)

type ResponseWrapper

type ResponseWrapper struct {
	Code   int
	Writer ResponseWriterWriter
}

func (ResponseWrapper) Write

type ResponseWriterWriter

type ResponseWriterWriter interface {
	Write(http.ResponseWriter) error
}

But who writes the ResponseWriterWriter?

func AccountHandler

func AccountHandler(r *http.Request, context *Context) ResponseWriterWriter

func AccountImportHandler

func AccountImportHandler(context *Context, r *http.Request, user *models.User, accountid int64) ResponseWriterWriter

* Assumes the User is a valid, signed-in user, but accountid has not yet been validated

func AccountTransactionsHandler

func AccountTransactionsHandler(context *Context, r *http.Request, user *models.User, accountid int64) ResponseWriterWriter

Return only those transactions which have at least one split pertaining to an account

func GnucashImportHandler

func GnucashImportHandler(r *http.Request, context *Context) ResponseWriterWriter

func ImportHandler

func ImportHandler(r *http.Request, context *Context) ResponseWriterWriter

func OFXFileImportHandler

func OFXFileImportHandler(context *Context, r *http.Request, user *models.User, accountid int64) ResponseWriterWriter

func OFXImportHandler

func OFXImportHandler(context *Context, r *http.Request, user *models.User, accountid int64) ResponseWriterWriter

func PriceHandler

func PriceHandler(r *http.Request, context *Context, user *models.User, securityid int64) ResponseWriterWriter

func ReportHandler

func ReportHandler(r *http.Request, context *Context) ResponseWriterWriter

func ReportTabulationHandler

func ReportTabulationHandler(tx store.Tx, r *http.Request, user *models.User, reportid int64) ResponseWriterWriter

func SecurityHandler

func SecurityHandler(r *http.Request, context *Context) ResponseWriterWriter

func SecurityTemplateHandler

func SecurityTemplateHandler(r *http.Request, context *Context) ResponseWriterWriter

func SessionHandler

func SessionHandler(r *http.Request, context *Context) ResponseWriterWriter

func TransactionHandler

func TransactionHandler(r *http.Request, context *Context) ResponseWriterWriter

func UserHandler

func UserHandler(r *http.Request, context *Context) ResponseWriterWriter

type SuccessWriter

type SuccessWriter struct{}

func (SuccessWriter) Write

type UserExistsError

type UserExistsError struct{}

func (UserExistsError) Error

func (ueu UserExistsError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL