私が取り組んでいる小さな API があります。すべて正常に動作し、すべてのリクエストは想定どおりに動作しますが、何らかの理由で URL クエリを介して結果をフィルタリングしようとすると、id では機能しますが、デバイス フィールドでは機能しません。
def on_get(self, req, resp):
"""Handles GET requests"""
if req.get_param("id"):
result = {'location': r.db(PROJECT_DB).table(PROJECT_TABLE).get(req.get_param("id")).run(db_connection)}
elif req.get_param("device"):
result = {'location': r.db(PROJECT_DB).table(PROJECT_TABLE).get(req.get_param("device")).run(db_connection)}
else:
location = r.db(PROJECT_DB).table(PROJECT_TABLE).run(db_connection)
result = {'locations': [i for i in location]}
resp.body = json.dumps(result)
例http://localhost:8000/location?id=(some random id)
これはうまくいきます
しかし、http://localhost:8000/location?device=(some device)
これを行うとうまくいかず、null を返します
それで、誰かが私が間違っていることを教えてもらえますか? または、URL を使用してフィルタリングするより良い方法を誰かが知っている場合は、さらに良いですか?
注:rethinkdbを使用しています
編集:
これは私が通常持っているものです:
{
"locations": [
{
"id": "4bf4b94f-747a-42db-9d54-a8399d995025",
"location": "gps coords",
"device": "Device 2"
},
{
"id": "b5cce561-37d2-42e7-86e4-a31c008b0af2",
"location": "gps coords",
"device": "Device 1"
},
{
"id": "bebba7cf-710c-4ee8-ad69-2d58174d4e02",
"location": "gps coords",
"device": "Device 1"
},
{
"id": "e928f84b-60ff-40f3-b839-920bc99e5480",
"location": "gps coords",
"device": "Device1"
}
]
}
ID によるフィルタリングは正常に機能しますが、奇妙であるデバイスによるフィルタリングは機能しません