<commit_before>from flask import jsonify, make_response, request, url_for

import utils
from redis_inventory import LOCATION_ID, NEW, OPEN_BOX, PRODUCT_ID, QUANTITY, RESTOCK_LEVEL, TYPE, USED
from . import app

# Status Codes
HTTP_200_OK = 200
HTTP_201_CREATED = 201
HTTP_204_NO_CONTENT = 204
HTTP_400_BAD_REQUEST = 400
HTTP_404_NOT_FOUND = 404
HTTP_409_CONFLICT = 409

inventory = None


@app.route('/')
def index():
  return app.send_static_file('index.html')


@app.route('/inventory')
def inventory_index():
  """ Intro page of the inventory API
  This method will only return some welcome words.

  Returns:
    response: welcome words in json format and status 200
  """
  welcome_info = {'api': "inventory",
                  'message': "This is the index page of /inventory. "
                             "To see all products, please access /inventory/products"}
  return make_response(jsonify(welcome_info), HTTP_200_OK)


@app.route('/inventory/products', methods=['GET'])
def get_product_list():
  """ Get info about all products
    This method will get the info about all the products

    Returns:
      response: product information(product id, location id, used/new/open_box, total_quantity, restock_level)
      status 200 if succeeded
  """
  all_products = inventory.get_all()
  arg = request.args.get(TYPE)

  if arg is None or not arg:
    response = make_response(jsonify(all_products), HTTP_200_OK)

  else:
    arg = arg.lower()
    if arg != OPEN_BOX and arg != NEW and arg != USED:
      response = make_response('Invalid type, must be one of these fields: open_box, new, used', HTTP_400_BAD_REQUEST)
    else:
      l = []
      for product in inventory.get_all():
        if arg in product and int(product[arg]) > 0:
          l.append(product)
      response = make_response(jsonify(l), HTTP_200_OK)<commit_msg>Swagger docs for list all products<commit_after>from flask import jsonify, make_response, request, url_for

import utils
from redis_inventory import LOCATION_ID, NEW, OPEN_BOX, PRODUCT_ID, QUANTITY, RESTOCK_LEVEL, TYPE, USED
from . import app

# Status Codes
HTTP_200_OK = 200
HTTP_201_CREATED = 201
HTTP_204_NO_CONTENT = 204
HTTP_400_BAD_REQUEST = 400
HTTP_404_NOT_FOUND = 404
HTTP_409_CONFLICT = 409

inventory = None


@app.route('/')
def index():
  return app.send_static_file('index.html')


@app.route('/inventory')
def inventory_index():
  """ Intro page of the inventory API
  This method will only return some welcome words.

  Returns:
    response: welcome words in json format and status 200
  """
  welcome_info = {'api': "inventory",
                  'message': "This is the index page of /inventory. "
                             "To see all products, please access /inventory/products"}
  return make_response(jsonify(welcome_info), HTTP_200_OK)


@app.route('/inventory/products', methods=['GET'])
def get_product_list():
  """
    Retrieve a list of Products
    This endpoint will return all Products unless a query parameter is specificed
    ---
    tags:
      - Products
    description: The Products endpoint allows you to query Products
    parameters:
      - name: type
        in: query
        description: The type of Products you are looking for
        required: false
        type: string
    responses:
      200:
        description: An array of Products
        schema:
          type: array
          items:
            schema:
              id: Product
              properties:
                product_id:
                  type: integer
                  description: unique id assigned internally by service
                location_id:
                  type: integer
                  description: unique location id assigned internally by service
                restock_level:
                  type: integer
                  description: max space allocated for the product
                new:
                  type: integer
                  description: quantity of new products
                used:
                  type: integer
                  description: quantity of used products
                open_box:
                  type: integer
                  description: quantity of open_box products
    """
  all_products = inventory.get_all()
  arg = request.args.get(TYPE)

  if arg is None or not arg:
    response = make_response(jsonify(all_products), HTTP_200_OK)

  else:
    arg = arg.lower()
    if arg != OPEN_BOX and arg != NEW and arg != USED:
      response = make_response('Invalid type, must be one of these fields: open_box, new, used', HTTP_400_BAD_REQUEST)
    else:
      l = []
      for product in inventory.get_all():
        if arg in product and int(product[arg]) > 0:
          l.append(product)
      response = make_response(jsonify(l), HTTP_200_OK)
{'fraction_non_alphanumeric': 0.0803347280334728, 'fraction_numerical': 0.02301255230125523, 'mean_word_length': 2.5625931445603576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '598392', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1320, 'n_words': 453}