routes.md 12 KB

API Routes Documentation

This document outlines the available endpoints based on the provided controllers (LoginController and RegisterController).

Base URL Placeholder: http://localhost:8000


1. User Login

Authenticates a user and returns a JWT token.

Endpoint

POST /login

Headers

Content-Type: application/json

Request Body (JSON)

{
  "email": "john.doe@example.com",
  "password": "securepassword123"
}

cURL Example

curl --location 'http://localhost:8000/login' \
--header 'Content-Type: application/json' \
--data '{
    "email": "john.doe@example.com",
    "password": "securepassword123"
}'

Responses

200 OK (Success)

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_OK",
  "data": {
    "token": "<jwt>",
    "user_id": 1,
    "company_id": 1
  }
}

401 Unauthorized (Missing fields or Invalid credentials)

{
  "status": "fail",
  "message": "Invalid credentials",
  "code": "E_VALIDATE"
}

2. User Register

Creates a new user account in the database.

Endpoint

POST /register

Headers

Content-Type: application/json

Request Body (JSON)

{
  "username": "John Doe",
  "email": "john.doe@example.com",
  "password": "securepassword123",
  "phone": "+15550199",
  "address": "123 Tech Street",
  "city": "Silicon Valley",
  "state": "CA",
  "zip": "94000",
  "country": "USA",
  "kyc": 1,
  "birthdate": 631152000,
  "cpf": "12345678900",
  "company_id": 1,
  "role_id": 2
}

cURL Example

curl --location 'http://localhost:8000/register' \
--header 'Content-Type: application/json' \
--data '{
  "username": "John Doe",
  "email": "john.doe@example.com",
  "password": "securepassword123",
  "phone": "+15550199",
  "address": "123 Tech Street",
  "city": "Silicon Valley",
  "state": "CA",
  "zip": "94000",
  "country": "USA",
  "kyc": 1,
  "birthdate": 631152000,
  "cpf": "12345678900",
  "company_id": 1,
  "role_id": 1
}'

Responses

200 OK (Success)

{
  "status": "success",
  "code": "S_CREATED",
  "data": {
    "user_id": 45,
    "user_name": "John Doe",
    "user_email": "john.doe@example.com",
    "company_id": 1,
    "role_id": 2
  }
}

400 Bad Request (Validation Errors)

  • Missing required fields
  • Invalid email format
  • Password too short (< 8 characters)
  • Email already exists

    {
    "status": "fail",
    "message": "Missing field: phone",
    "code": "E_VALIDATE"
    }
    

3. Create Company with User and Wallet

Creates a company, a user linked to it, and a wallet (address/publicKey/privateKey) in a single transaction. Public endpoint (no auth).

Endpoint

POST /company/user/create

Headers

Content-Type: application/json

Request Body (JSON)

{
  "company_name": "Acme Corp",
  "username": "John Doe",
  "email": "john.doe@example.com",
  "password": "secret123",
  "phone": "+55 11 99999-9999",
  "address": "Rua A, 123",
  "city": "Sao Paulo",
  "state": "SP",
  "zip": "01234-567",
  "country": "BR",
  "kyc": 1,
  "birthdate": 631152000,
  "cpf": "123.456.789-00",
  "cnpj": "00000000000001"
}

cURL Example

curl --location 'http://localhost:8000/company/user/create' \
  -H 'Content-Type: application/json' \
  --data '{
    "company_name": "MixTech",
    "username": "LuvasLuvas",
    "email": "Luvas@email.com",
    "password": "secret123",
    "phone": "+55 16 93939-2222",
    "address": "Rua A, 123",
    "city": "Sao Paulo",
    "state": "SP",
    "zip": "01234-567",
    "country": "BR",
    "kyc": 1,
    "birthdate": 631152000,
    "cpf": "12345678900",
    "cnpj": "00000000000030"
  }'

Responses

200 OK (Success)

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_CREATED",
  "data": {
    "company_id": 1,
    "role_id": 1,
    "user": {
      "user_id": 1,
      "user_name": "John Doe",
      "user_email": "john.doe@example.com",
      "company_id": 1,
      "role_id": 1
    },
    "wallet_id": 1,
    "wallet_address": "0x8AC9615b1a555BeA2938778aAef1ead35205c167"
  }
}

400 Bad Request (Validation Errors)

{
  "status": "failed",
  "msg": "Password must be at least 8 characters",
  "code": "E_VALIDATE",
  "data": []
}

500 Internal Server Error (Wallet/DB issues)

{
  "status": "failed",
  "msg": "Wallet generation failed",
  "code": "E_INTERNAL",
  "data": []
}

4. Change User Email

Updates the authenticated user's email. Requires JWT.

Endpoint

POST /user/change-email

Headers

Content-Type: application/json

Authorization: Bearer <JWT>

Request Body (JSON)

{
  "email": "new.email@example.com"
}

cURL Example

curl --location 'http://localhost:8000/user/change-email' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <JWT>' \
  --data '{"email":"new.email@example.com"}'

Responses

200 OK (Updated)

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_UPDATED",
  "data": {
    "user_id": 1,
    "user_email": "new.email@example.com"
  }
}

400 Bad Request (Validation Errors)

{
  "status": "failed",
  "msg": "Email already in use or update failed",
  "code": "E_VALIDATE",
  "data": []
}

401 Unauthorized

{
  "status": "failed",
  "msg": "Unauthorized",
  "code": "E_VALIDATE",
  "data": []
}

5. Change User Password

Changes the authenticated user's password. Requires JWT.

Endpoint

POST /user/change-password

Headers

Content-Type: application/json

Authorization: Bearer <JWT>

Request Body (JSON)

{
  "current_password": "minhaSenhaAtual",
  "new_password": "novaSenhaForte123"
}

cURL Example

curl --location 'http://localhost:8000/user/change-password' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <JWT>' \
  --data '{"current_password":"minhaSenhaAtual","new_password":"novaSenhaForte123"}'

Responses

200 OK (Updated)

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_UPDATED",
  "data": {
    "user_id": 1
  }
}

400 Bad Request (Validation Errors)

{
  "status": "failed",
  "msg": "Invalid current password or update failed",
  "code": "E_VALIDATE",
  "data": []
}

401 Unauthorized

{
  "status": "failed",
  "msg": "Unauthorized",
  "code": "E_VALIDATE",
  "data": []
}

6. Commodities — List

Returns all commodities. No request body required. Requires JWT.

Endpoint

POST /commodities/get

Headers

Authorization: Bearer <JWT>

cURL Example

curl --location -X POST 'http://localhost:8000/commodities/get' \
  -H 'Authorization: Bearer <JWT>'

Responses

200 OK

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_OK",
  "data": [
    {
      "commodities_id": 1,
      "name": "Gold",
      "flag": "a"
    }
  ]
}

204 No Content

{
  "status": "fail",
  "msg": "Commodities Not Found",
  "code": "E_DATABASE",
  "data": []
}

7. Commodity Create

Creates a new commodity.

Endpoint

POST /commodity/create

Headers

Content-Type: application/json

Request Body (JSON)

{
  "name": "Gold",
  "flag": "a"
}

cURL Example

curl --location 'http://localhost:8000/commodity/create' \
  -H 'Content-Type: application/json' \
  --data '{
    "name": "Gold",
    "flag": "a"
  }'

Responses

200 OK (Created)

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_CREATED",
  "data": {
    "commodities_id": 10,
    "name": "Gold",
    "flag": "a"
  }
}

400 Bad Request (Missing name)

{
  "status": "fail",
  "msg": "Validation failed: name is required",
  "code": "E_VALIDATE",
  "data": []
}

8. Commodity Update

Updates an existing commodity.

Endpoint

POST /commodity/update

Headers

Content-Type: application/json

Request Body (JSON)

{
  "commodities_id": 10,
  "name": "Silver",
  "flag": "b"
}

You may send only name, only flag, or both.

cURL Example

curl --location 'http://localhost:8000/commodity/update' \
  -H 'Content-Type: application/json' \
  --data '{
    "commodities_id": 10,
    "name": "Silver",
    "flag": "b"
  }'

Responses

200 OK

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_UPDATED",
  "data": {
    "commodities_id": 10,
    "name": "Silver",
    "flag": "b"
  }
}

400 Bad Request

  • Missing commodities_id
  • Empty name
  • No fields to update

    {
    "status": "fail",
    "msg": "Validation failed: nothing to update",
    "code": "E_VALIDATE",
    "data": []
    }
    

204 No Content

{
  "status": "fail",
  "msg": "Commodity Not Found or Not Updated",
  "code": "E_DATABASE",
  "data": []
}

9. Commodity Delete

Deletes a commodity by ID.

Endpoint

POST /commodity/delete

Headers

Content-Type: application/json

Request Body (JSON)

{
  "commodities_id": 10
}

cURL Example

curl --location 'http://localhost:8000/commodity/delete' \
  -H 'Content-Type: application/json' \
  --data '{"commodities_id":10}'

Responses

200 OK (Deleted)

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_DELETED",
  "data": {
    "deleted": true
  }
}

400 Bad Request

{
  "status": "fail",
  "msg": "Validation failed: invalid commodities_id",
  "code": "E_VALIDATE",
  "data": []
}

204 No Content

{
  "status": "fail",
  "msg": "Commodity Not Found",
  "code": "E_DATABASE",
  "data": []
}

10. Token Get

Returns all tokens filtered by token_uf and commodities_name. Requires JWT.

Endpoint

POST /token/get

Headers

Content-Type: application/json

Authorization: Bearer <JWT>

Request Body (JSON)

{
  "token_uf": "SP",
  "commodities_name": "soja"
}

cURL Example

curl --location 'http://localhost:8000/token/get' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <JWT>' \
  --data '{
  "token_uf": "SP",
  "commodities_name": "soja"
}'

Responses

200 OK

{
  "status": "ok",
  "msg": "[100] Request ok.",
  "code": "S_OK",
  "data": [
    {
      "token_id": 1,
      "token_external_id": "abc123",
      "token_commodities_amount": 1000,
      "token_commodities_value": 5000,
      "token_uf": "SP",
      "token_city": "Sao Paulo",
      "token_content": "financial instrument",
      "token_flag": "a",
      "wallet_id": 1,
      "chain_id": 1,
      "commodities_id": 1,
      "cpr_id": 1,
      "user_id": 1
    }
  ]
}

204 No Content

{
  "status": "fail",
  "msg": "Token Not Found",
  "code": "E_DATABASE",
  "data": []
}