Revert "Change searching to be case insensitive"
This reverts commit 97373e0ae2.
			
			
This commit is contained in:
		
							
								
								
									
										21
									
								
								webapi.py
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								webapi.py
									
									
									
									
									
								
							| @@ -10,7 +10,6 @@ from flask import Flask, jsonify, request | |||||||
| from flask_api import status | from flask_api import status | ||||||
|  |  | ||||||
| from sqlalchemy.orm.exc import NoResultFound | from sqlalchemy.orm.exc import NoResultFound | ||||||
| from sqlalchemy import func |  | ||||||
| from libdb import Session, Location, ProductQuantity, Product, Brand, Unit, Purchase, Use | 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""" |     """Route to get information about a location""" | ||||||
|     session = Session() |     session = Session() | ||||||
|     try: |     try: | ||||||
|         data = session.query(Location.name, Location.description).filter( |         data = session.query(Location.name, Location.description). \ | ||||||
|             func.lower(Location.name) == func.lower(search)).one() |             filter(Location.name == search).one() | ||||||
|     except NoResultFound: |     except NoResultFound: | ||||||
|         return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND |         return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND | ||||||
|     data2 = {} |     data2 = {} | ||||||
| @@ -52,7 +51,7 @@ def api_get_current_quantities(location): | |||||||
|     data = {} |     data = {} | ||||||
|     try: |     try: | ||||||
|         for upc, quantity in session.query(ProductQuantity.product_upc, ProductQuantity.quantity) \ |         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 |             data[upc] = quantity | ||||||
|         return jsonify(data) |         return jsonify(data) | ||||||
|     except NoResultFound: |     except NoResultFound: | ||||||
| @@ -66,13 +65,13 @@ def api_get_quantity_of_product_in_location(location, searchmethod, search): | |||||||
|     try: |     try: | ||||||
|         if searchmethod == 'upc': |         if searchmethod == 'upc': | ||||||
|             data = session.query(ProductQuantity.quantity).filter( |             data = session.query(ProductQuantity.quantity).filter( | ||||||
|                 func.lower(ProductQuantity.location) == func.lower(location), |                 ProductQuantity.location == location, | ||||||
|                 ProductQuantity.product_upc == search).one() |                 ProductQuantity.product_upc == search).one() | ||||||
|             return jsonify(data[0]) |             return jsonify(data[0]) | ||||||
|         elif searchmethod == 'name': |         elif searchmethod == 'name': | ||||||
|             data = session.query(ProductQuantity.quantity).filter( |             data = session.query(ProductQuantity.quantity).filter( | ||||||
|                 func.lower(ProductQuantity.location) == func.lower(location), |                 ProductQuantity.location == location, | ||||||
|                 func.lower(ProductQuantity.name) == func.lower(search)).one() |                 ProductQuantity.name == search).one() | ||||||
|             return jsonify(data[0]) |             return jsonify(data[0]) | ||||||
|         else: |         else: | ||||||
|             print("invalid search method, sending 400") |             print("invalid search method, sending 400") | ||||||
| @@ -106,7 +105,7 @@ def api_get_product_information(searchmethod, search): | |||||||
|         if searchmethod == 'name': |         if searchmethod == 'name': | ||||||
|             result = session.query(Product.upc, Product.brand, Product.name, |             result = session.query(Product.upc, Product.brand, Product.name, | ||||||
|                                    Product.size, Product.sizeunit, Product.description).filter( |                                    Product.size, Product.sizeunit, Product.description).filter( | ||||||
|                 func.lower(Product.name) == func.lower(search) |                 Product.name == search | ||||||
|             ).one() |             ).one() | ||||||
|             data = {'upc': result[0], 'brand': result[1], 'name': result[2], 'size': result[3], |             data = {'upc': result[0], 'brand': result[1], 'name': result[2], 'size': result[3], | ||||||
|                     'sizeunit': result[4], 'description': result[5]} |                     'sizeunit': result[4], 'description': result[5]} | ||||||
| @@ -144,11 +143,11 @@ def api_get_brands(): | |||||||
|  |  | ||||||
| @app.route("/api/v1/brand/name/<search>", methods=["GET"]) | @app.route("/api/v1/brand/name/<search>", methods=["GET"]) | ||||||
| def api_get_brand_by_name(search): | def api_get_brand_by_name(search): | ||||||
|     """Route to get information about a brand""" |     """Route to get information about a location""" | ||||||
|     session = Session() |     session = Session() | ||||||
|     try: |     try: | ||||||
|         data = session.query(Brand.name, Brand.description).filter( |         data = session.query(Brand.name, Brand.description).filter( | ||||||
|             func.lower(Brand.name) == func.lower(search)).one() |             Brand.name == search).one() | ||||||
|     except NoResultFound: |     except NoResultFound: | ||||||
|         return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND |         return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND | ||||||
|     data2 = {'name': data.name, 'description': data.description} |     data2 = {'name': data.name, 'description': data.description} | ||||||
| @@ -174,7 +173,7 @@ def api_get_unit_by_name(search): | |||||||
|     session = Session() |     session = Session() | ||||||
|     try: |     try: | ||||||
|         data = session.query(Unit.name, Unit.description).filter( |         data = session.query(Unit.name, Unit.description).filter( | ||||||
|             func.lower(Unit.name) == func.lower(search)).one() |             Unit.name == search).one() | ||||||
|     except NoResultFound: |     except NoResultFound: | ||||||
|         return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND |         return jsonify({'error': 'NO_RESULT_FOUND'}), status.HTTP_404_NOT_FOUND | ||||||
|     data2 = {'name': data.name, 'description': data.description} |     data2 = {'name': data.name, 'description': data.description} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user