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

Begin move away from using http.ServeMux

This commit is contained in:
2017-11-12 20:17:27 -05:00
parent 9429b748fa
commit 507868b7a5
13 changed files with 179 additions and 141 deletions

View File

@ -210,7 +210,7 @@ func ofxImportHelper(tx *Tx, r io.Reader, user *User, accountid int64) ResponseW
return SuccessWriter{}
}
func OFXImportHandler(tx *Tx, r *http.Request, user *User, accountid int64) ResponseWriterWriter {
func OFXImportHandler(context *Context, r *http.Request, user *User, accountid int64) ResponseWriterWriter {
download_json := r.PostFormValue("ofxdownload")
if download_json == "" {
return NewError(3 /*Invalid Request*/)
@ -222,7 +222,7 @@ func OFXImportHandler(tx *Tx, r *http.Request, user *User, accountid int64) Resp
return NewError(3 /*Invalid Request*/)
}
account, err := GetAccount(tx, accountid, user.UserId)
account, err := GetAccount(context.Tx, accountid, user.UserId)
if err != nil {
return NewError(3 /*Invalid Request*/)
}
@ -308,10 +308,10 @@ func OFXImportHandler(tx *Tx, r *http.Request, user *User, accountid int64) Resp
}
defer response.Body.Close()
return ofxImportHelper(tx, response.Body, user, accountid)
return ofxImportHelper(context.Tx, response.Body, user, accountid)
}
func OFXFileImportHandler(tx *Tx, r *http.Request, user *User, accountid int64) ResponseWriterWriter {
func OFXFileImportHandler(context *Context, r *http.Request, user *User, accountid int64) ResponseWriterWriter {
multipartReader, err := r.MultipartReader()
if err != nil {
return NewError(3 /*Invalid Request*/)
@ -329,20 +329,29 @@ func OFXFileImportHandler(tx *Tx, r *http.Request, user *User, accountid int64)
}
}
return ofxImportHelper(tx, part, user, accountid)
return ofxImportHelper(context.Tx, part, user, accountid)
}
/*
* Assumes the User is a valid, signed-in user, but accountid has not yet been validated
*/
func AccountImportHandler(tx *Tx, r *http.Request, user *User, accountid int64, importtype string) ResponseWriterWriter {
func AccountImportHandler(context *Context, r *http.Request, user *User, accountid int64, importtype string) ResponseWriterWriter {
switch importtype {
case "ofx":
return OFXImportHandler(tx, r, user, accountid)
return OFXImportHandler(context, r, user, accountid)
case "ofxfile":
return OFXFileImportHandler(tx, r, user, accountid)
return OFXFileImportHandler(context, r, user, accountid)
default:
return NewError(3 /*Invalid Request*/)
}
}
func ImportHandler(r *http.Request, context *Context) ResponseWriterWriter {
current, remaining := NextLevel(context.Remaining)
if current != "gnucash" {
return NewError(3 /*Invalid Request*/)
}
context.Remaining = remaining
return GnucashImportHandler(r, context)
}