# Too Easy Genesis API Routes

## INICIATE THE SERVER

cd /home/uriri/Projetos/tooeasy/backend/too-easy-genesis

```bash
./mvnw -DskipTests spring-boot:run
```

```bash
java -jar target/too-easy-trader-genesis-0.0.1-SNAPSHOT.jar --server.port=8080
```
## STOP THE SERVER

```bash
pkill -f too-easy-trader-genesis-0.0.1-SNAPSHOT.jar
```

Base URL: http://localhost:8080

Set Postman collection variables:
- baseUrl = http://localhost:8080

Default headers for protected routes:
- Authorization: Bearer {{token}}
- Content-Type: application/json

# IMPORTANTE: JWT ATUALMENTE ESTÁ SEM LIMITE DE TEMPO POR QUESTÃO DE TESTES!

## Register

#### Create a Default user with:

```bash
POST {{baseUrl}}/auth/register/default
```
- email = "tester@tooeasy.local" 
- password = "ChangeMe123!"
- Response 201 Created:
```json
{
  "token": "<JWT>",
  "companyId": 1,
  "userId": 1
}
```

#### POST {{baseUrl}}/auth/register
- Body (application/json) — fields from `RegisterDTO` (`src/main/java/com/platform2easy/genesis/web/dto/RegisterDTO.java`):
```json
{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "Str0ng!Pass",
  "phone": "+55 11 99999-9999",
  "address": "Av. Paulista, 1000",
  "city": "São Paulo",
  "state": "SP",
  "zip": "01310-100",
  "country": "BR",
  "kyc": 1,
  "birthdate": 19900101,
  "cpf": "123.456.789-00",
  "companyId": 1,
  "roleId": 1,
  "flag": "ACTIVE"
}
```
- Response 201 Created:
```json
{
  "token": "<JWT>",
  "companyId": 1,
  "userId": 1
}
```

#### POST {{baseUrl}}/auth/login
- Body — `AuthenticationDTO` (`src/main/java/com/platform2easy/genesis/web/dto/AuthenticationDTO.java`):
```json
{ "email": "john@example.com", "password": "Str0ng!Pass" }
```
- Response 200 OK:
```json
{
  "token": "<JWT>",
  "companyId": 1,
  "userId": 1
}
```

#### POST {{baseUrl}}/auth/validate-token
- Headers:
  - Authorization: Bearer <JWT>
- Response 200 OK (if token is valid):
```json
{
  "token": "<JWT>",
  "companyId": 1,
  "userId": 1
}
```
- Response 401 Unauthorized (if token is invalid or expired)

## User Management

#### GET {{baseUrl}}/auth/company/{companyId}
- Headers:
  - Authorization: Bearer <JWT>
- Path params: companyId (Integer)
- Response 200 OK: List of users from the specified company

#### PUT {{baseUrl}}/auth/email/{id}
- Headers:
  - Authorization: Bearer <JWT>
  - Content-Type: application/json
- Path params: id (Long) - User ID
- Request body:
```json
{
  "userEmail": "new.email@example.com"
}
```
- Response 200 OK: Updated user object

#### PUT {{baseUrl}}/auth/password/{id}
- Headers:
  - Authorization: Bearer <JWT>
  - Content-Type: application/json
- Path params: id (Long) - User ID
- Request body:
```json
{
  "userPassword": "newSecurePassword123"
}
```
- Response 200 OK: Updated user object with hashed password

#### DELETE {{baseUrl}}/auth/{id}
- Headers:
  - Authorization: Bearer <JWT>
- Path params: id (Long) - User ID to delete
- Response 204 No Content (on successful deletion)

## Commodity API (`com.platform2easy.genesis.web.controller.CommodityController`)
#### Base path: {{baseUrl}}/api/commodity

- GET {{baseUrl}}/api/commodity
  - List all commodities.

- GET {{baseUrl}}/api/commodity/{id}
  - Path params: id (Long)

- POST {{baseUrl}}/api/commodity
  - Body — entity `Commoditiy` (`domain/model/Commoditiy.java`):
```json
{
  "name": "Soja",
  "flag": "ACTIVE"
}
```

#### - PUT {{baseUrl}}/api/commodity/{id}
  - Body: same as POST

#### - DELETE {{baseUrl}}/api/commodity/{id}

Notes:
- Fields: `name` (String), `flag` (String).

## Orderbook API (`com.platform2easy.genesis.web.controller.OrderbookController`)
#### Base path: {{baseUrl}}/api/orderbook

- GET {{baseUrl}}/api/orderbook
  - List all orderbook entries.

- GET {{baseUrl}}/api/orderbook?isToken=0|1
  - Query params: `isToken` (0 or 1). Filters by `orderbook_is_token` (1 = true = sell, 0 = false = buy).

- GET {{baseUrl}}/api/orderbook/{id}
  - Path params: id (Long)

- POST {{baseUrl}}/api/orderbook
  - Body — entity `Orderbook` (`domain/model/Orderbook.java`):
```json
{
  "flag": "ACTIVE",
  "ts": 1696200000,
  "isToken": true,
  "amount": "1000",
  "statusId": 1,
  "userId": 1,
  "walletId": 1,
  "tokenId": 1,
  "currencyId": 1,
  "chainId": 1
}
```

- PUT {{baseUrl}}/api/orderbook/{id}
  - Body: same as POST

- DELETE {{baseUrl}}/api/orderbook/{id}

Notes:
- Protected by JWT (Authorization: Bearer {{token}}).

## Company API (`com.platform2easy.genesis.web.controller.CompanyController`)
#### Base path: {{baseUrl}}/api/company

- GET {{baseUrl}}/api/company
  - List all companies.

- GET {{baseUrl}}/api/company/{id}
  - Path params: id (Long)

- POST {{baseUrl}}/api/company
  - Body — entity `Company` (`domain/model/Company.java`):
```json
{
  "name": "Minha Empresa",
  "flag": "ACTIVE"
}

```
- Response 201 Created:
```json
{
  "id": 1,
  "name": "Minha Empresa",
  "flag": "ACTIVE"
}
```

- PUT {{baseUrl}}/api/company/{id}
  - Body: same as POST

- DELETE {{baseUrl}}/api/company/{id}

Notes:
- Protected by JWT (Authorization: Bearer {{token}}).
- Fields: `name` (String), `flag` (String).

## Wallet API (`com.platform2easy.genesis.web.controller.WalletController`)
#### Base path: {{baseUrl}}/api/wallet

- GET {{baseUrl}}/api/wallet
  - List all wallets.

- GET {{baseUrl}}/api/wallet/{id}
  - Path params: id (Long)

- POST {{baseUrl}}/api/wallet
  - Body — entity `Wallet` (`domain/model/Wallet.java`):
```json
{
  "companyId": 1,
  "publicKey": "WALLET_PUBLIC_KEY",
  "privateKey": "WALLET_PRIVATE_KEY",
  "flag": "ACTIVE",
  "chainId": 1
}
```

- PUT {{baseUrl}}/api/wallet/{id}
  - Body: same as POST

- DELETE {{baseUrl}}/api/wallet/{id}

Notes:
- Protected by JWT (Authorization: Bearer {{token}}).
- Fields: `companyId` (Long), `publicKey` (String), `privateKey` (String), `flag` (String), `chainId` (Long).

## Token API (`com.platform2easy.genesis.web.controller.TokenController`)
#### Base path: {{baseUrl}}/api/token

- GET {{baseUrl}}/api/token
  - List all tokens.

- GET {{baseUrl}}/api/token/{id}
  - Path params: id (Long)

- POST {{baseUrl}}/api/token
  - Body — entity `Token` (`domain/model/Token.java`):
```json
{
  "externalId": "1",
  "commoditiesAmount": 100,
  "flag": "ACTIVE",
  "commoditiesValue": 5000,
  "walletId": 1,
  "chainId": 1,
  "commoditiesId": 1,
  "cprId": 1
}
```

- PUT {{baseUrl}}/api/token/{id}
  - Body: same as POST

- DELETE {{baseUrl}}/api/token/{id}

Notes:
- Protected by JWT (Authorization: Bearer {{token}}).
- Fields: `externalId` (String), `commoditiesAmount` (Integer), `flag` (String), `commoditiesValue` (Integer), `walletId` (Long), `chainId` (Long), `commoditiesId` (Long), `cprId` (Long).

## TxCoin API (`com.platform2easy.genesis.web.controller.TxCoinController`)
#### Base path: {{baseUrl}}/api/tx_coin

- GET {{baseUrl}}/api/tx_coin
  - List all tx_coin entries.

- GET {{baseUrl}}/api/tx_coin/{id}
  - Path params: id (String)

- POST {{baseUrl}}/api/tx_coin
  - Body — entity `TxCoin` (`domain/model/TxCoin.java`):
```json
{
  "id": "1",
  "value": "1000.00",
  "flag": "ACTIVE",
  "ts": 1696200000,
  "fromAddress": "",
  "toAddress": "",
  "currencyId": 1,
  "chainId": 1
}
```

- PUT {{baseUrl}}/api/tx_coin/{id}
  - Body: same as POST

- DELETE {{baseUrl}}/api/tx_coin/{id}

Notes:
- Protected by JWT (Authorization: Bearer {{token}}).
- Fields: `id` (String), `value` (String), `flag` (String), `ts` (Integer), `fromAddress` (String), `toAddress` (String), `currencyId` (Long), `chainId` (Long).

## TxToken API (`com.platform2easy.genesis.web.controller.TxTokenController`)
#### Base path: {{baseUrl}}/api/tx_token

- GET {{baseUrl}}/api/tx_token
  - List all tx_token entries.

- GET {{baseUrl}}/api/tx_token/{id}
  - Path params: id (String)

- POST {{baseUrl}}/api/tx_token
  - Body — entity `TxToken` (`domain/model/TxToken.java`):
```json
{
  "id": "1",
  "flag": "ACTIVE",
  "ts": 1696200000,
  "fromAddress": "",
  "toAddress": "",
  "tokenId": 1,
  "chainId": 1
}
```

- PUT {{baseUrl}}/api/tx_token/{id}
  - Body: same as POST

- DELETE {{baseUrl}}/api/tx_token/{id}

Notes:
- Protected by JWT (Authorization: Bearer {{token}}).
- Fields: `id` (String), `flag` (String), `ts` (Integer), `fromAddress` (String), `toAddress` (String), `tokenId` (Long), `chainId` (Long).

## Quick Postman steps
1. Choose a login:
   #### - POST `/auth/login` with email/password, OR
   #### - POST `/authentication/login` with login/password.
2. Copy `token` from response and set Postman variable `token`.
3. Use protected endpoints under `/api/**` with header `Authorization: Bearer {{token}}`.