mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-16 02:36:01 -07:00
api docs, minor changes
This commit is contained in:
parent
4aa8a2f822
commit
c249a077cc
3 changed files with 203 additions and 9 deletions
194
API.md
Normal file
194
API.md
Normal file
|
|
@ -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,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
@ -17,9 +17,8 @@ import (
|
||||||
// TODO: Put user info fetching code into middleware
|
// TODO: Put user info fetching code into middleware
|
||||||
|
|
||||||
type GetBalanceResponse struct {
|
type GetBalanceResponse struct {
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
RequestID string `json:"request_id"`
|
Balance money.Money `json:"balance"`
|
||||||
Data money.Money `json:"data"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBalance(w http.ResponseWriter, r *http.Request) {
|
func GetBalance(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -39,9 +38,8 @@ func GetBalance(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := GetBalanceResponse{
|
response := GetBalanceResponse{
|
||||||
Status: 200,
|
Status: 200,
|
||||||
RequestID: "0",
|
Balance: money.Money{
|
||||||
Data: money.Money{
|
|
||||||
Currency: user.Balance.Currency,
|
Currency: user.Balance.Currency,
|
||||||
Whole: user.Balance.Whole,
|
Whole: user.Balance.Whole,
|
||||||
Decimal: user.Balance.Decimal,
|
Decimal: user.Balance.Decimal,
|
||||||
|
|
@ -96,9 +94,8 @@ func SetBalance(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := GetBalanceResponse{
|
response := GetBalanceResponse{
|
||||||
Status: 200,
|
Status: 200,
|
||||||
RequestID: "0",
|
Balance: money.Money{
|
||||||
Data: money.Money{
|
|
||||||
Currency: newBalance.Currency,
|
Currency: newBalance.Currency,
|
||||||
Whole: newBalance.Whole,
|
Whole: newBalance.Whole,
|
||||||
Decimal: newBalance.Decimal,
|
Decimal: newBalance.Decimal,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type BudgetResponse struct {
|
type BudgetResponse struct {
|
||||||
|
Status int `json:"status"`
|
||||||
// total amount allowed to spend in a month
|
// total amount allowed to spend in a month
|
||||||
Budget money.Money `json:"budget"`
|
Budget money.Money `json:"budget"`
|
||||||
// total amount allowed to spend by category
|
// 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.Expenses[e.Category] = append(response.Expenses[e.Category], e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.Status = 200
|
||||||
|
|
||||||
ret, err := json.Marshal(response)
|
ret, err := json.Marshal(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue