|
@@ -42,50 +42,46 @@ def add_click_time():
|
|
|
|
|
|
|
|
|
|
@dbRouter.get("/find_brand")
|
|
@dbRouter.get("/find_brand")
|
|
-def find_brand(keyword:str = None,language :str = "ch"):
|
|
|
|
|
|
+def find_brand(keyword:str = None,language :str = "ch",page_num : int = None,page_amount: int = None,search_name : str = None):
|
|
|
|
|
|
- if keyword is None :
|
|
|
|
- data, count = supabase.table('101_brand')\
|
|
|
|
- .select('*')\
|
|
|
|
- .eq("language", language)\
|
|
|
|
- .execute()
|
|
|
|
|
|
|
|
- result = []
|
|
|
|
-
|
|
|
|
- for shop in data[1] :
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- json = {
|
|
|
|
- "type" : shop["type"],
|
|
|
|
- "info" : shop
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- result.append(json)
|
|
|
|
|
|
+ if keyword is None :
|
|
|
|
+ query = supabase.table('101_brand').select('*').eq("language", language)
|
|
|
|
+ else :
|
|
|
|
+ keyword_list = keyword.split(",")
|
|
|
|
+ query= supabase.table('101_brand').select('*').eq("language", language)
|
|
|
|
+ for keyword_tmp in keyword_list :
|
|
|
|
+ query = query.like('tags', f'%{keyword_tmp}%')
|
|
|
|
|
|
|
|
+ if search_name:
|
|
|
|
+ query = query.like('name', f'%{search_name}%')
|
|
|
|
|
|
- return {"state":"success","data" : result}
|
|
|
|
|
|
+ result,_ = query.execute()
|
|
|
|
+ count = len(result[1])
|
|
|
|
|
|
- try :
|
|
|
|
- data, count = supabase.table('101_brand')\
|
|
|
|
- .select('*')\
|
|
|
|
- .eq("language", language)\
|
|
|
|
- .like('tags', f'%{keyword}%')\
|
|
|
|
- .execute()
|
|
|
|
|
|
+ if page_num and page_amount :
|
|
|
|
+ offset = (page_num - 1) * page_amount
|
|
|
|
+ query = query.range(offset, offset + page_amount-1)
|
|
|
|
|
|
|
|
+ try:
|
|
|
|
+ data,_ = query.execute()
|
|
result = []
|
|
result = []
|
|
|
|
|
|
for shop in data[1] :
|
|
for shop in data[1] :
|
|
|
|
|
|
-
|
|
|
|
json = {
|
|
json = {
|
|
"type" : shop["type"],
|
|
"type" : shop["type"],
|
|
"info" : shop
|
|
"info" : shop
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if language != "ch" :
|
|
|
|
+ if shop["floor"] == "館外" :
|
|
|
|
+ json["info"]["floor"] = "outside"
|
|
|
|
+
|
|
result.append(json)
|
|
result.append(json)
|
|
|
|
|
|
|
|
|
|
- return {"state":"success","data" : result}
|
|
|
|
|
|
+ return {"state":"success","all_num" : count,"data" : result}
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return {"state":"fail","message" :str(e)}
|
|
return {"state":"fail","message" :str(e)}
|
|
@@ -176,6 +172,10 @@ def read_root(type:str,language :str = "ch"):
|
|
# 從結果中隨機選擇一筆資料
|
|
# 從結果中隨機選擇一筆資料
|
|
random_row = choice(result)
|
|
random_row = choice(result)
|
|
|
|
|
|
|
|
+ if language != "ch" :
|
|
|
|
+ if random_row["floor"] == "館外" :
|
|
|
|
+ random_row["floor"] = "outside"
|
|
|
|
+
|
|
#print(random_row)
|
|
#print(random_row)
|
|
|
|
|
|
return {"data": random_row}
|
|
return {"data": random_row}
|