Revert "Change searching to be case insensitive"
This reverts commit 97373e0ae2
.
This commit is contained in:
parent
97373e0ae2
commit
8e44280e7d
21
webapi.py
21
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/<search>", 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}
|
||||
|
Loading…
Reference in New Issue
Block a user