Change manufacturer endpoint query name for search
This commit is contained in:
parent
03871b4462
commit
6751f0db16
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in New Issue