ServiceConnect

Proiect EAIP

Steps for initializing services

Database: cwd = Database
    $ docker-compose up
Performance Measuring App: cwd = BusinessLogicService
    $ python3 -m venv venv
    $ source venv/bin/activate
    $ pip3 install -r requirements.txt
    $ pip3 install -U pip google-api-python-client
    $ python3 src/app.py
Login Service: cwd = BackendLogicServices/LoginService
    $ npm install
    $ npm run start
Web App: cwd = BackendLogicServices/AppService
    $ npm install
    $ npm run start
Frontend: cwd = Frontend/my-app
    $ npm install
    $ npm run start

REST API Endpoints, Documentation and Usage:

Login Service: PORT 3003
Backend Service: PORT 3002
Business Service: PORT 3004
Frontend Service: PORT 3000

REGISTER CLIENT

Path: localhost:3003/api/v1/users/register/client
Type: POST
Body pt CLIENT:
        {
           "username": "IonPopescu",
           "password": "1234",
        }
Returns for SUCCESS:
    {
        "response": {
            "username": "IonPopescu",
            "id": 3
        }
    }
Returns for FAILURE:
        400

REGISTER SERVICE

Path: localhost:3003/api/v1/users/register/service
Type: POST
Body pt SERVICE:
    {
       "username": "CarFix",
       "password": "1234",
       "user_type": "service",
       "location": "Strada Poporului, nr. 17, Bucuresti, Sector 1",
       "descriere": "Vulcanizare & revizii"
    }
Returns for SUCCESS:
    {
        "response": {
            "username": "CarFix",
            "id": 2
        }
    }
Returns for FAILURE:
        400

LOGIN

Path: localhost:3003/api/v1/users/login
Type: POST
Authorized roles: ADMIN, SERVICE, CLIENT
Body:
    {
        "username": "Guest2",
        "password": "1234"
    }
Returns for SUCCESS:
    {
        "response": {
            "role": "CLIENT",
            "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjYsInVzZXJSb2xlIjoiTUFOQUdFUiIsImlhdCI6MTYyMTc1Mzk2MSwiYXVkIjoicHcgY2xpZW50IiwiaXNzIjoicHcgYmFja2VuZCIsInN1YiI6InB3In0.Ii-D51xvdn-0fuuHOhj6quNDxjGYLG8FytuWHmW9jgw"
        }
    }
Returns for FAILURE:
        400

PROFILE EDIT CLIENT

Path: localhost:3003/api/v1/profile/client
Type: PUT
Body pt CLIENT:
        {
           "username": "IonPopescu",
           "password": "1234",
           "new_username": "IonPopescu2",
           "new_password": "12345",
        }
Returns for SUCCESS:
    Returns pt CLIENT:
        {
           "username": "IonPopescu2",
           "password": "12345",
        }
Returns for FAILURE:
    400

PROFILE EDIT SERVICE

Path: localhost:3003/api/v1/profile/service
Type: PUT
Body pt SERVICE:
    {
       "username": "CarFix",
       "password": "1234",
       "new_username": "CarFix2",
       "new_password": "12345",
       "new_location": "Strada Poporului, nr. 18, Bucuresti, Sector 1",
       "new_description": "Vulcanizare & revizii",
    }
Returns for SUCCESS:
    Returns pt SERVICE:
        {
           "username": "CarFix2",
           "password": "12345",
           "location": "Strada Poporului, nr. 18, Bucuresti, Sector 1",
           "description": "Vulcanizare & revizii",
        }
Returns for FAILURE:
    400

PROFILE VIEW CLIENT

Path: localhost:3003/api/v1/profile/client
    Type: GET
    Returns for SUCCESS pt CLIENT:
        {
           "username": "IonPopescu",
           "password": "1234",
        }

PROFILE VIEW SERVICE

Path: localhost:3003/api/v1/profile/service
    Type: GET
    Returns for SUCCESS pt SERVICE:
        {
           "username": "CarFix",
           "password": "12345",
           "location": "Strada Poporului, nr. 17, Bucuresti, Sector 1",
           "descriere": "Vulcanizare & revizii",
        } 

CHAT - VIEW CHAT

Path: localhost:3003/api/v1/chat
Type: GET
Body:
    {
       "username": "service_i_talked_to",
    }
Returns for SUCCESS:
    {
        "response": {
            "chat" : [
                {
                    "timestamp": 1500000000,
                    "message": "Salut!",
                    "message_type": "received",
                },
            ]
        }
    }
Returns for FAILURE:
        400

CHAT - SEND CHAT

Path: localhost:3003/api/v1/chat
Type: POST
Body:
    {
       "username": "service_i_talked_to",
       "message": "Salutare!"
    }
Returns for SUCCESS:
    {
        "response": {
            "chat" : [
                {
                    "timestamp": 1500000000,
                    "message": "Salut!",
                    "message_type": "received",
                },
                {
                    "timestamp": 1500100000,
                    "message": "Salutare!",
                    "message_type": "sent",
                }
            ]
        }
    }
Returns for FAILURE:
        400

GET_USERS

Path: localhost:3003/api/v1/users/
Type: GET
Authorized roles: ADMIN
Returns:
    {
        "response": [
            {
                "username": "admin",
                "id": 1,
                "roleId": 1
            },
            {
                "username": "Taner",
                "id": 2,
                "roleId": 2
            },
            {
                "username": "Corina",
                "id": 3,
                "roleId": 2
            },
            {
                "username": "Teodor",
                "id": 4,
                "roleId": 2
            },
            {
                "username": "Guest",
                "id": 5,
                "roleId": 3
            },
            {
                "username": "Guest2",
                "id": 6,
                "roleId": 2
            }
        ]
    }

DELETE USER

Path: localhost:3003/api/v1/users/:USER_ID/
Type: DELETE
Parameters: USER_ID
Returns for SUCCESS:
    200
Returns for FAILURE:
    400

DELETE REVIEW

Path: localhost:3003/api/v1/reviews/:review_id/
Type: DELETE
Parameters: REVIEW_ID
Returns for SUCCESS:
    200
Returns for FAILURE:
    400

SET_ROLE

Path: localhost:3003/api/v1/users/:USER_ID/role/:ROLE_ID
Type: PUT
Parameters: USER_ID & ROLE_ID

GET_ROLES

Path: localhost:3003/api/v1/roles
Type: GET
Authorized roles: ADMIN
Returns:
    {
        "response": [
            {
                "value": "ADMIN",
                "id": 1
            },
            {
                "value": "SERVICE",
                "id": 2
            },
            {
                "value": "CLIENT",
                "id": 3
            }
        ]
    }

ADD_ROLE

Path: localhost:3003/api/v1/roles
Type: POST
Authorized roles: ADMIN
Body:
    {
        "value": "GUEST"
    }
Returns:
    {
        "response": {
            "value": "GUEST",
            "id": 4
        }
    }

GET_USER_ANALYTICS

Path: localhost:3002/api/v1/users/analytics
Type: GET
Authorized roles: ADMIN
Body:
    {
        "limit": 2
    }
Returns:
    {
        "response": {
            "registers_data": [
                {
                    "today_date": "2021-06-03T00:00:00.000Z",
                    "avg": "5.0000000000000000"
                },
                {
                    "today_date": "2021-06-02T00:00:00.000Z",
                    "avg": "22.0000000000000000"
                }
            ],
            "logins_data": [
                {
                    "today_date": "2021-06-03T00:00:00.000Z",
                    "avg": "9.0000000000000000"
                },
                {
                    "today_date": "2021-06-02T00:00:00.000Z",
                    "avg": "8.0000000000000000"
                }
            ],
            "jobs_data": [
                {
                    "today_date": "2021-06-03T00:00:00.000Z",
                    "avg": "10.0000000000000000"
                },
                {
                    "today_date": "2021-06-02T00:00:00.000Z",
                    "avg": "8.0000000000000000"
                }
            ]
        }
    }