- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Division:
/
- Positive integers: 0-9
Follow these steps to set up the Expression Calculator Service and Expression Agent:
-
Clone the Expression Calculator Service project repository:
git clone https://github.com/firefoxuz/expression-backend-2.git
-
Navigate to the project directory:
cd expression-backend-2
-
Copy the example environment configuration file:
cp .env.json.example .env.json
-
Start the Docker containers using Docker Compose:
docker-compose up -d
-
Apply database migrations:
docker run -v ./db/migrations:/migrations --network host migrate/migrate -path=/migrations/ -database postgres://expression_user:expression_password@localhost:5444/expression_db?sslmode=disable up
-
Clone the Expression Agent project repository:
git clone https://github.com/firefoxuz/expression-agent-2.git
-
Navigate to the project directory:
cd expression-agent-2
-
Copy the example environment configuration file:
cp .env.json.example .env.json
-
Start the Docker containers using Docker Compose:
docker-compose up -d
Now, both the Expression Calculator Service and Expression Agent should be up and running. You can access the Expression Calculator Service at http://127.0.0.1:8085/ and the Expression Agent at their respective API endpoints.
Registers a new user with the provided login credentials.
-
URL
/api/v1/register
-
Method
POST
-
Request Body
Field Type Description login string User's username password string User's password Example:
{ "login": "username", "password": "123456" }
-
Success Response
- Code: 200 OK
{ "message": "User registered successfully" }
- Code: 200 OK
-
Error Response
- Code: 400 Bad Request
- Content:
{ "error": "Invalid request body" }
Logs in a user with the provided login credentials.
-
URL
/api/v1/login
-
Method
POST
-
Request Body
Field Type Description login string User's username password string User's password Example:
{ "login": "username", "password": "123456" }
-
Success Response
- Code: 200 OK
- Content:
{ "token_type": "jwt", "token": "some_generated_token" }
-
Error Response
- Code: 401 Unauthorized
- Content:
{ "error": "Invalid login credentials" }
Adds expressions with a time limit.
-
URL
/api/v1/expressions
-
Method
POST
-
Request Headers
Header Value Content-Type application/json Authorization Bearer <access_token> -
Request Body
Field Type Description expression string Mathematical expression time_limit integer Time limit for expression (ms) Example:
{ "expression": "3+3+3", "time_limit": 1000 }
-
Success Response
- Code: 200 OK
- Content:
{ "message": "expression is stored and will be calculated" }
-
Error Response
- Code: 400 Bad Request
- Content:
{ "error": "Invalid request body" }
OR
- Code: 401 Unauthorized
- Content:
{ "error": "Unauthorized" }
Retrieves all expressions stored for the authenticated user.
-
URL
/api/v1/expressions
-
Method
GET
-
Request Headers
Header Value Content-Type application/json Authorization Bearer <access_token> -
Success Response
- Code: 200 OK
- Content:
{ "expressions": [ { "id": 2, "user_id": 1, "expression": "3+3+3", "result": 9, "is_processing": false, "is_time_limit": null, "is_valid": true, "is_finished": true, "time_limit": 1000, "created_at": "2024-04-21T22:11:55Z", "finished_at": "2024-04-21T17:11:57.92291Z" }, { "id": 1, "user_id": 1, "expression": "3+3+3", "result": 9, "is_processing": false, "is_time_limit": null, "is_valid": true, "is_finished": true, "time_limit": 1000, "created_at": "2024-04-21T16:57:30Z", "finished_at": "2024-04-21T17:10:44.748884Z" } ] }
- Content:
- Code: 200 OK
Retrieves a single expression by its ID.
-
URL
/api/v1/expressions/{expression_id}
-
Method
GET
-
URL Parameters
Parameter Type Description expression_id string ID of the expression -
Request Headers
Header Value Authorization Bearer <access_token> -
Success Response
- Code: 200 OK
- Content:
{ "expressions": { "id": 2, "user_id": 1, "expression": "3+3+3", "result": 9, "is_processing": false, "is_time_limit": null, "is_valid": true, "is_finished": true, "time_limit": 1000, "created_at": "2024-04-21T22:11:55Z", "finished_at": "2024-04-21T17:11:57.92291Z" } }
-
-
Error Responses
- Code: 401 Unauthorized
Content:
{ "error": "Unauthorized" }
- Code: 404 Not Found
Content:
{ "error": "Expression not found" }
- Code: 401 Unauthorized
Content:
Below is the architecture of our microservices: