From 0bed518af3426cc42e90e6270eedd5ad3c3faae8 Mon Sep 17 00:00:00 2001 From: samantha Date: Fri, 27 Mar 2026 10:45:36 +0000 Subject: [PATCH] Update REST API --- REST-API.md | 197 ++++++++++++---------------------------------------- 1 file changed, 46 insertions(+), 151 deletions(-) diff --git a/REST-API.md b/REST-API.md index b07a112..9e22890 100644 --- a/REST-API.md +++ b/REST-API.md @@ -1,21 +1,12 @@ -# REST API - -The server listens on port `8080`. All request bodies are JSON (`Content-Type: application/json`). - ---- - -## Health - -### `GET /health` - -Returns server status, DB connection info, memory usage, and uptime. - -```bash -curl http://localhost:8080/health -``` - -```json -{ +

REST API

+

The server listens on port 8080. All request bodies are JSON (Content-Type: application/json).

+
+

Health

+

GET /health

+

Returns server status, DB connection info, memory usage, and uptime.

+
curl http://localhost:8080/health
+
+
{
   "status": "ok",
   "uptime": "4m32s",
   "database": {
@@ -33,64 +24,37 @@ curl http://localhost:8080/health
   "go_version": "go1.22.0",
   "goroutines": 4
 }
-```
- 
-Returns `503` with `"status": "degraded"` if the database is unreachable.
- 
----
- 
-## Companies
- 
-### `POST /company/add`
- 
-```bash
-curl -X POST http://localhost:8080/company/add \
+
+

Returns 503 with "status": "degraded" if the database is unreachable.

+
+

Companies

+

POST /company/add

+
curl -X POST http://localhost:8080/company/add \
   -H "Content-Type: application/json" \
   -d '{"name":"Novo Nordisk","shares_outstanding":4442064180,"price":251.00,"currency_id":1}'
-```
- 
-### `GET /company/list`
- 
-```bash
-curl http://localhost:8080/company/list
-```
- 
-### `GET /company/revenue/categories`
- 
-Returns all distinct revenue categories for a company.
- 
-```bash
-curl "http://localhost:8080/company/revenue/categories?company_id=1"
-```
- 
----
- 
-## Currencies
- 
-### `POST /currency/add`
- 
-```bash
-curl -X POST http://localhost:8080/currency/add \
+
+

GET /company/list

+
curl http://localhost:8080/company/list
+
+

GET /company/revenue/categories

+

Returns all distinct revenue categories for a company.

+
curl "http://localhost:8080/company/revenue/categories?company_id=1"
+
+
+

Currencies

+

POST /currency/add

+
curl -X POST http://localhost:8080/currency/add \
   -H "Content-Type: application/json" \
   -d '{"code":"DKK","name":"Danish Krone"}'
-```
- 
-### `GET /currency/list`
- 
-```bash
-curl http://localhost:8080/currency/list
-```
- 
----
- 
-## Trades
- 
-### `POST /trade/add`
- 
-Add a new trade. `product` is an integer enum and `type` is a boolean (see tables below).
- 
-```bash
-curl -X POST http://localhost:8080/trade/add \
+
+

GET /currency/list

+
curl http://localhost:8080/currency/list
+
+
+

Trades

+

POST /trade/add

+

Add a new trade. product is an integer enum and type is a boolean (see tables below).

+
curl -X POST http://localhost:8080/trade/add \
   -H "Content-Type: application/json" \
   -d '{
     "symbol":        "NOVO",
@@ -101,82 +65,13 @@ curl -X POST http://localhost:8080/trade/add \
     "price":         251.00,
     "date":          "2025-03-01T00:00:00Z"
   }'
-```
- 
-**`product` values:**
- 
-| Value | Meaning |
-|-------|---------|
-| `0` | StockTrade |
-| `1` | OptionCallTrade |
-| `2` | OptionPutTrade |
-| `3` | CurrencyTrade |
-| `4` | BondTrade |
- 
-**`type` values:**
- 
-| Value | Meaning |
-|-------|---------|
-| `true` | Buy |
-| `false` | Sell |
- 
-**Validation rules:**
-- `symbol` must not be empty
-- `shares` must be a positive integer
-- `product` must be 0–3
-- `price` must be a positive number
-- `currency_code` must not be empty
-- `date` must not be zero or in the future
- 
-### `GET /trade/list`
- 
-Returns all trades as a JSON array.
- 
-```bash
-curl http://localhost:8080/trade/list
-```
- 
----
- 
-## Positions
- 
-### `GET /positions/list`
- 
-Returns the current portfolio positions, computed by aggregating the trade history.
- 
-```bash
-curl http://localhost:8080/positions/list
-```
- 
-Each position includes `Symbol`, `CurrencyCode`, `CostBasis`, `Shares`, and `Weight`.
- 
----
- 
-## Revenue
- 
-### `POST /add/revenue/entry`
- 
-Also available at `POST /api/v1/revenue/add`. Adds a single revenue line to a report. The period is created automatically if it doesn't exist.
- 
-```bash
-curl -X POST http://localhost:8080/add/revenue/entry \
-  -H "Content-Type: application/json" \
-  -d '{
-    "company_id":  1,
-    "currency_id": 1,
-    "period_type": "Q",
-    "year":        2025,
-    "index":       1,
-    "category":    "product",
-    "label":       "iPhone",
-    "value":       69143
-  }'
-```
- 
-`period_type` values:
- 
-| Value | Meaning | `index` range |
-|-------|---------|---------------|
-| `Q` | Quarter | 1–4 |
-| `H` | Half-year | 1–2 |
-| `Y` | Full year | 1 |
\ No newline at end of file
+
+

product values:

+ +Value | Meaning +-- | -- +0 | StockTrade +1 | OptionCallTrade +2 | OptionPutTrade +3 | CurrencyTrade +4 | BondTrade