diff --git a/API.md b/API.md new file mode 100644 index 0000000..69bd652 --- /dev/null +++ b/API.md @@ -0,0 +1,194 @@ +# Auth (/auth) router +## POST /login +Form: email (string), password (string) + +Response: +```json +{ + "name": string, + "email": string, + "session": string, +} +``` +## POST /createaccount +Form: name (string), email (string), password (string) + +Response: +```json +{ + "name": string, + "email": string, + "session": string, +} +``` +## GET /userinfo +Headers: x-session-key + +Response: +```json +{ + "name": string, + "email": string, +} +``` + +# Widget (/w) router +**IMPORTANT!** All requests for the widget router require the x-session-key header be set +to the user's current session token. +## GET /balance +Return the current balance of the account + +Response: +```json +{ + "status": int, + "balance": { + "currency": string, + "whole": int, + "decimal": int, + } +} +``` +## POST /balance +Set the current balance to a value +Form: currency (string), whole (int), decimal (int) + +Response: +```json +{ + "status": int, + "balance": { + "currency": string, + "whole": int, + "decimal": int, + } +} +``` +## GET /transactions/recent +Get the most recent 10 transactions + +Response: +```json +{ + "status": int, + "transactions": [ + { + "timestamp": unix, + "category": string, + "amount": { + "currency": string, + "whole": int, + "decimal": int, + }, + "type": expenses/income + }, + ... + ] +} +``` +## POST /transactions +Add a new transaction, either "income" or "expense" + +Form: category (string), currency (string), whole (int), decimal (int), type (expenses/income) + +Response: +```json +{ + "status": int +} +``` +## POST /transactions/recurring +Add a recurring transaction (bill, paycheck, etc) + +Form: category (string), currency (string), whole (int), decimal (int), type (expenses/income), period (in days)(int) + +Response: +```json +{ + "status": int +} +``` +## GET /budget +Get current budget information including total and catagorized budget, as well +as total expenses in each budget category + +Response: +```json +{ + "status": int, + "budget": { + "currency": string, + "whole": int, + "decimal": int, + }, + "budget_categories": { + "category": { + "currency": string, + "whole": int, + "decimal": int, + }, + ... + }, + "categories": [ string ], + "expenses": { + "category": [ + { + "timestamp": unix, + "category": string, + "amount": { + "currency": string, + "whole": int, + "decimal": int + }, + "type": expenses/income + }, + ... + ] + } +} + +``` +## POST /budget +Set a new total budget + +Form: currency (string), whole (int), decimal (int) + +Response: +```json +{ + "status": int +} +``` +## POST /budget/categories +Set a budget for a specific category + +Form: currency (string), whole (int), decimal (int), category (string) + +Response: +```json +{ + "status": int +} +``` +## GET /expenses/month +Get the total amount of expenses in the last month + +Response: +```json +{ + "currency": string, + "whole": int, + "decimal": int, +} +``` +## GET /income/month +Get the total amount of income in the last month + +Response: +```json +{ + "currency": string, + "whole": int, + "decimal": int, +} +``` diff --git a/widgets/balance.go b/widgets/balance.go index 6bd06bf..c151065 100644 --- a/widgets/balance.go +++ b/widgets/balance.go @@ -17,9 +17,8 @@ import ( // TODO: Put user info fetching code into middleware type GetBalanceResponse struct { - Status int `json:"status"` - RequestID string `json:"request_id"` - Data money.Money `json:"data"` + Status int `json:"status"` + Balance money.Money `json:"balance"` } func GetBalance(w http.ResponseWriter, r *http.Request) { @@ -39,9 +38,8 @@ func GetBalance(w http.ResponseWriter, r *http.Request) { } response := GetBalanceResponse{ - Status: 200, - RequestID: "0", - Data: money.Money{ + Status: 200, + Balance: money.Money{ Currency: user.Balance.Currency, Whole: user.Balance.Whole, Decimal: user.Balance.Decimal, @@ -96,9 +94,8 @@ func SetBalance(w http.ResponseWriter, r *http.Request) { } response := GetBalanceResponse{ - Status: 200, - RequestID: "0", - Data: money.Money{ + Status: 200, + Balance: money.Money{ Currency: newBalance.Currency, Whole: newBalance.Whole, Decimal: newBalance.Decimal, diff --git a/widgets/budget.go b/widgets/budget.go index 20a9c59..80bee58 100644 --- a/widgets/budget.go +++ b/widgets/budget.go @@ -15,6 +15,7 @@ import ( ) type BudgetResponse struct { + Status int `json:"status"` // total amount allowed to spend in a month Budget money.Money `json:"budget"` // total amount allowed to spend by category @@ -59,6 +60,8 @@ func GetBudget(w http.ResponseWriter, r *http.Request) { response.Expenses[e.Category] = append(response.Expenses[e.Category], e) } + response.Status = 200 + ret, err := json.Marshal(response) if err != nil { w.WriteHeader(http.StatusInternalServerError)