Change manufacturer endpoint query name for search

This commit is contained in:
Xavier Bustamante Talavera 2018-10-18 13:08:42 +02:00
parent 03871b4462
commit 6751f0db16
2 changed files with 6 additions and 6 deletions

View File

@ -139,15 +139,15 @@ class DeviceView(View):
class ManufacturerView(View):
class FindArgs(marshmallow.Schema):
name = marshmallow.fields.Str(required=True,
# Disallow like operators
validate=lambda x: '%' not in x and '_' not in x)
search = marshmallow.fields.Str(required=True,
# Disallow like operators
validate=lambda x: '%' not in x and '_' not in x)
@cache(datetime.timedelta(days=1))
def find(self, args: dict):
name = args['name']
search = args['search']
manufacturers = Manufacturer.query \
.filter(Manufacturer.name.ilike(name + '%')) \
.filter(Manufacturer.name.ilike(search + '%')) \
.paginate(page=1, per_page=6) # type: Pagination
return jsonify(
items=app.resources[Manufacturer.t].schema.dump(

View File

@ -474,7 +474,7 @@ def test_computer_with_display():
def test_manufacturer(user: UserClient):
m, r = user.get(res='Manufacturer', query=[('name', 'asus')])
m, r = user.get(res='Manufacturer', query=[('search', 'asus')])
assert m == {'items': [{'name': 'Asus', 'url': 'https://en.wikipedia.org/wiki/Asus'}]}
assert r.cache_control.public
assert r.expires > datetime.datetime.now()