Skip to content

Database API Help

Oreko edited this page Apr 14, 2019 · 3 revisions

Help on package app:

NAME

app

PACKAGE CONTENTS

pavement (package)
tests (package)

CLASSES

json.encoder.JSONEncoder(builtins.object)
    JSONTimeIDEncoder

FUNCTIONS

bad_request(error)
    400 error handler

create_app()
    Creates a Flask app instance
    
    Creates the app and loads it with the pavement controllers as
    well as loading the app with the mongodb database instance taken 
    from the local environment. This comes from the docker settings.
    
    Args:
        none
    
    Returns:
        A flask app using the pavement controllers for a restful API
        interface.  
    
    Raises:
        none

page_not_found(error)
    404 error handler

DATA

mongo = <flask_pymongo.PyMongo object>

FILE

\pavementapp\app\__init__.py

Help on module controllers:

NAME

controllers

FUNCTIONS

create_data()
    Creates a number of documents in the mongo database
    
    Takes user's JSON from an HTTP POST request and adds the data 
    to the database.
    
    Args:
        None directly, takes JSON data from the request
    
    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and tells
        the user where their data can be accessed from.
    
        Examples:
        ({
         "message":"Inserted 2 documents",
         "id":["507f1f77bcf86cd799439011", "507f1f77bcf86cd799439012"],
         "href":["/pavement/507f1f77bcf86cd799439011", "/pavement/507f1f77bcf86cd799439012"]
        }, 201)
        ({
         "message":"Inserted 1 document",
         "id":"507f1f77bcf86cd799439013",
         "href":"/pavement/507f1f77bcf86cd799439013"
        }, 201)
    
        If the user asked to put multiple documents in the database, 
        then the function does and tells the user how many were
        added.
    
    Raises:
        none

delete_data()
    Removes documents in the mongo database matching a query
    
    Takes user's query from an HTTP DELETE request and searches the
    database for matching data. If any are found, delete them.
    
    Args:
        None directly, takes query data from the request
    
    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and 
        gives the user the number of deleted documents.
    
        Examples:
        ({"message":"Deleted 3 result(s)}, 200)
        ({"error":"Not found"}, 404)
    
    Raises:
        none

delete_document(_id)
    Queries the database for a specified document by ID and
        removes it if found.
    
    Takes an object's ID from the URL where a get request is sent
    and searches the database for matching data. If it is found,
    deletes the object.
    
    Args:
        None directly, takes the ID of the object from the URL
    
    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and 
        tells the user the ID of the deleted object.
    
        Example:
        ({
         "message":"Deleted _id: 507f1f77bcf86cd799439013"
        },200)
    
    Raises:
        none

retrieve_data()
    Queries the database for a specified kind of document
    
    Takes user's query from an HTTP GET request and searches the
    database for matching data. If any are found, return them to 
    the user.
    
    Args:
        None directly, takes query data from the request
    
    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and 
        gives the user the documents matching their query.
    
        Example:
        ({"results":[{_id:1, cars:3, time:7884848}, {_id:2, cars:4, time:9823492}]}, 200)
    
    Raises:
        none

retrieve_document(_id)
    Queries the database for a specified document by ID and
        returns it if found.
    
    Takes an object's ID from the URL where a get request is sent
    and searches the database for matching data. If it is found,
    returns it to the user.
    
    Args:
        None directly, takes the ID of the object from the URL
    
    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and 
        gives the user the document matching their query.
    
        Example:
        ({"result":{_id:1, cars:3, time:7884848}}, 200)
    
    Raises:
        none

update_document(_id)
    Queries the database for a specified document by ID and 
        updates it if found.
    
    Takes an object's ID from the URL where a get request is sent
    and searches the database for matching data. If it is found,
    update the internal data for that object based off of the 
    user's JSON sent in the request.
    
    Args:
        None directly, takes the ID of the object from the URL
                       also takes JSON from the request
    
    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and 
        if the document is updated, tells the user where their 
        data can be accessed from. 
    
        Example:
        ({
         "id":"507f1f77bcf86cd799439013",
         "href":"/pavement/507f1f77bcf86cd799439013"
        }, 200)
    
    Raises:
        none
insert_image(_id):
    Queries the database for a specified document by ID, uploads an image,
    and updates the document if found.

    Takes user's image from an HTTP POST request and adds the data 
    to the server. Also adds a image href to the database entry at the 
    specified id.

    Args:
        None directly, takes image data from the request

    Returns:
        A pair (JSON: response, Int: response code)
        which tells the user if their request was correct and tells
        the user where their data can be accessed from.

    Examples:
        ({
         "message":"Image added",
         "href":"/pavement/images/507f1f77bcf86cd799439013.png"
        }, 201)

    Raises:
        none

DATA

mongo = <flask_pymongo.PyMongo object>
pavementAPI = <flask.blueprints.Blueprint object>
request = <LocalProxy unbound>

FILE

\pavementapp\app\pavement\controllers.py

Clone this wiki locally