Skip to content

Module: db_middleware

Rishabh Jain edited this page Feb 8, 2022 · 1 revision

DB Middleware acts as a gateway to the database. This service is solely responsible for each database operation performed in the system. The service exposes its endpoint to the following services:

  1. API Gateway
  2. Queue Worker

The service will be running on port - 3001

Following are the endpoints exposed to

  1. API Gateway
NOTE: All the endpoints are POST requests

POST /getAllStatus

Request:

{
    "user_email":"rishabh.jain53@gmail.com"
}

Response:

{
    "status": "success",
    "message": "Information retrieved",
    "requests": [
        {
            "_id": "6201ae94a0aa8bcdb7ad97bf",
            "user_email": "rishabh.jain53@gmail.com",
            "request_id": "DAN1_02022022_000000_002959_Reflectivity",
            "status": "0",
            "time_stamp": "1644277396",
            "property": "Reflectivity",
            "__v": 0
        }
    ]
}

POST /postCheckRequest

Request:

{
    "request_id":"DAN1_02022022_000000_002959_Reflectivity"
}

Response:

{
    "status": "success",
    "message": "Information retrieved",
    "requests": [
        {
            "_id": "6201ae94a0aa8bcdb7ad97bf",
            "user_email": "rishabh.jain53@gmail.com",
            "request_id": "DAN1_02022022_000000_002959_Reflectivity",
            "status": "0",
            "time_stamp": "1644277396",
            "property": "Reflectivity",
            "__v": 0
        }
    ],
    "data_status": "true/false"
}

data_status - 1. true - means the data for the request already exists in the database no need to download data from S3 2. false - data doesn't exist in the database

POST /postNewRequest

Request:

{
    "user_email": "rishabh.jain53@gmail.com",
    "request_id":"KAKQ_02022022_000000_002959_Reflectivity",
    "property":"reflectivity",
    "time_stamp":"1644090027"            
}

Response:

{
   status: "success/error",
   message: "Insertion successful/Insertion failed"
}

POST /getDataOfRequestID

Request:

{
    "request_id":"KAKQ_02012022_003000_005959_Reflectivity"
}

Response:

{
    "data": [
        {
            "_id": "6201af9ba0aa8bcdb7ad97f1",
            "request_id": "KAKQ_02012022_003000_005959_Reflectivity",
            "start_time": "003000",
            "end_time": "005959",
            "__v": 0,
            "lat": {
                "_id": "6201af9ba0aa8bcdb7ad97f2",
                "parent_doc_ref": "6201af9ba0aa8bcdb7ad97f1",
                "lat": [[],[]....],
                "__v": 0
            },
            "long": {
                "_id": "6201af9ba0aa8bcdb7ad97f3",
                "parent_doc_ref": "6201af9ba0aa8bcdb7ad97f1",
                "long": [[],[]....],
                "__v": 0
            },
            "reflectivity": {
                "_id": "6201af9ba0aa8bcdb7ad97f4",
                "parent_doc_ref": "6201af9ba0aa8bcdb7ad97f1",
                "data": [[],[]....],
                "__v": 0
            }
        }
    ]
}
  1. Queue Worker

POST /data_writer

Request:

{
    "requestID": "KAKQ_02012022_003000_005959_Reflectivity",
    "start_time": "body",
    "end_time": "end_time",
    "data": {
        "stationName": "stationName",
        "stationLatitute": "stationLatitute",
        "stationLongitude": "stationLongitude",
        "stationID": "stationID",
        "property": "Reflectivity",
        "latitude": [
            ["d"],
            ["e"],
            ["f"]
        ],
        "longitude": [
            ["a"],
            ["b"],
            ["c"]
        ],
        "Reflectivity": [
            ["x"],
            ["y"],
            ["x"]
        ]
    }
}

Response:

{ 
status: "success/error", 
message: "Insertion successful/Insertion failed" 
}