From 8e44280e7d43c0ed0f4c1add9c19c3a31ac27b56 Mon Sep 17 00:00:00 2001 From: BBaoVanC Date: Wed, 7 Oct 2020 10:15:53 -0500 Subject: [PATCH] Revert "Change searching to be case insensitive" This reverts commit 97373e0ae249b5d5dced5b56da9e7712f19f81af. --- webapi.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/webapi.py b/webapi.py index a4ea4dc..4f23caf 100644 --- a/webapi.py +++ b/webapi.py @@ -10,7 +10,6 @@ from flask import Flask, jsonify, request from flask_api import status from sqlalchemy.orm.exc import NoResultFound -from sqlalchemy import func from libdb import Session, Location, ProductQuantity, Product, Brand, Unit, Purchase, Use @@ -35,8 +34,8 @@ def api_get_location_information(search): """Route to get information about a location""" session = Session() try: - data = session.query(Location.name, Location.description).filter( - func.lower(Location.name) == func.lower(search)).one() + data = session.query(Location.name, Location.description). \ + filter(Location.name == search).one() except NoResultFound: return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND data2 = {} @@ -52,7 +51,7 @@ def api_get_current_quantities(location): data = {} try: for upc, quantity in session.query(ProductQuantity.product_upc, ProductQuantity.quantity) \ - .filter(func.lower(ProductQuantity.location) == func.lower(location)).all(): + .filter(ProductQuantity.location == location).all(): data[upc] = quantity return jsonify(data) except NoResultFound: @@ -66,13 +65,13 @@ def api_get_quantity_of_product_in_location(location, searchmethod, search): try: if searchmethod == 'upc': data = session.query(ProductQuantity.quantity).filter( - func.lower(ProductQuantity.location) == func.lower(location), + ProductQuantity.location == location, ProductQuantity.product_upc == search).one() return jsonify(data[0]) elif searchmethod == 'name': data = session.query(ProductQuantity.quantity).filter( - func.lower(ProductQuantity.location) == func.lower(location), - func.lower(ProductQuantity.name) == func.lower(search)).one() + ProductQuantity.location == location, + ProductQuantity.name == search).one() return jsonify(data[0]) else: print("invalid search method, sending 400") @@ -106,7 +105,7 @@ def api_get_product_information(searchmethod, search): if searchmethod == 'name': result = session.query(Product.upc, Product.brand, Product.name, Product.size, Product.sizeunit, Product.description).filter( - func.lower(Product.name) == func.lower(search) + Product.name == search ).one() data = {'upc': result[0], 'brand': result[1], 'name': result[2], 'size': result[3], 'sizeunit': result[4], 'description': result[5]} @@ -144,11 +143,11 @@ def api_get_brands(): @app.route("/api/v1/brand/name/", methods=["GET"]) def api_get_brand_by_name(search): - """Route to get information about a brand""" + """Route to get information about a location""" session = Session() try: data = session.query(Brand.name, Brand.description).filter( - func.lower(Brand.name) == func.lower(search)).one() + Brand.name == search).one() except NoResultFound: return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND data2 = {'name': data.name, 'description': data.description} @@ -174,7 +173,7 @@ def api_get_unit_by_name(search): session = Session() try: data = session.query(Unit.name, Unit.description).filter( - func.lower(Unit.name) == func.lower(search)).one() + Unit.name == search).one() except NoResultFound: return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND data2 = {'name': data.name, 'description': data.description}