GithubHelp home page GithubHelp logo

expression-backend-2's Introduction

Supported Operators:

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /

Supported Operand Range:

  • Positive integers: 0-9

Installation

Follow these steps to set up the Expression Calculator Service and Expression Agent:

Expression Calculator Service

  1. Clone the Expression Calculator Service project repository:

    git clone https://github.com/firefoxuz/expression-backend-2.git
  2. Navigate to the project directory:

    cd expression-backend-2
  3. Copy the example environment configuration file:

    cp .env.json.example .env.json
  4. Start the Docker containers using Docker Compose:

    docker-compose up -d
  5. 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

Expression Agent

  1. Clone the Expression Agent project repository:

    git clone https://github.com/firefoxuz/expression-agent-2.git
  2. Navigate to the project directory:

    cd expression-agent-2
  3. Copy the example environment configuration file:

    cp .env.json.example .env.json
  4. 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.

API Documentation

Register User

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"
      }
  • Error Response

    • Code: 400 Bad Request
    • Content:
      {
          "error": "Invalid request body"
      }

User Login

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"
      }

Add Expressions

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"
      }

Fetch All User Expressions

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"
                }
            ]
        }

Fetch Expression by ID

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"
      }

Microservice Architecture

Below is the architecture of our microservices:

Microservice Architecture

expression-backend-2's People

Contributors

firefoxuz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.