1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-06-30 19:48:38 -04:00

Move to a consistent way of handling IDs in URLs

This commit is contained in:
2017-11-12 21:12:49 -05:00
parent e99abfe866
commit 9624f0c5bc
9 changed files with 66 additions and 94 deletions

View File

@ -452,9 +452,7 @@ func TransactionHandler(r *http.Request, context *Context) ResponseWriterWriter
return &transaction
} else if r.Method == "GET" {
transactionid, err := GetURLID(r.URL.Path)
if err != nil {
if context.LastLevel() {
//Return all Transactions
var al TransactionList
transactions, err := GetTransactions(context.Tx, user.UserId)
@ -466,6 +464,10 @@ func TransactionHandler(r *http.Request, context *Context) ResponseWriterWriter
return &al
} else {
//Return Transaction with this Id
transactionid, err := context.NextID()
if err != nil {
return NewError(3 /*Invalid Request*/)
}
transaction, err := GetTransaction(context.Tx, transactionid, user.UserId)
if err != nil {
return NewError(3 /*Invalid Request*/)
@ -473,7 +475,7 @@ func TransactionHandler(r *http.Request, context *Context) ResponseWriterWriter
return transaction
}
} else {
transactionid, err := GetURLID(r.URL.Path)
transactionid, err := context.NextID()
if err != nil {
return NewError(3 /*Invalid Request*/)
}
@ -518,11 +520,6 @@ func TransactionHandler(r *http.Request, context *Context) ResponseWriterWriter
return &transaction
} else if r.Method == "DELETE" {
transactionid, err := GetURLID(r.URL.Path)
if err != nil {
return NewError(3 /*Invalid Request*/)
}
transaction, err := GetTransaction(context.Tx, transactionid, user.UserId)
if err != nil {
return NewError(3 /*Invalid Request*/)