OnlyBiggg commited on
Commit
024703e
·
1 Parent(s): 146b8fe

feat: add list trip

Browse files
Files changed (1) hide show
  1. app/api/routes.py +11 -12
app/api/routes.py CHANGED
@@ -189,7 +189,7 @@ async def price(request: Request):
189
  return DialogFlowResponseAPI(text=text, payload=payload)
190
  except:
191
  return DialogFlowResponseAPI(text=["Hệ thống xảy ra lỗi. Quý khách vui lòng thử lại sau hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."])
192
- @router.post('/trip/booking')
193
  async def booking_trip(request: Request) -> Response:
194
  body = await request.json()
195
  raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day = get_param_from_dialogflow(body)
@@ -212,20 +212,19 @@ async def booking_trip(request: Request) -> Response:
212
  "sort_by": ["price", "departure_time"]
213
  }
214
  try:
215
- respone = await api.post("/search/trips", payload=payload)
216
- if respone.get('status') == 200:
217
- data = respone["data"]["items"]
218
- total = respone["data"]["total"]
219
  if total > 0:
220
- price = respone["data"]["items"][0]["price"]
221
  list_raw_departure_times = sorted(list(set([ trip["raw_departure_time"] for trip in data])))
222
  schedule_time_trip = "**" + "** | **".join(map(str, list_raw_departure_times)) + "**"
223
- link = f'https://stag.futabus.vn/dat-ve?from={departure_code}&fromTime={date}&isReturn=false&ticketCount={ticket_count}&to={destination_code}&toTime='
224
-
225
- text= [f"Tuyến xe **{raw_departure_city}** - **{raw_destination_city}**: **{total}** chuyến.\n"
226
- f"Thời gian các chuyến xe khởi hành: {schedule_time_trip}\n"
227
- f"Giá vé: **{price}** VND.\n"
228
- f"Quý khách vui lòng truy cập vào [**tại đây**]({link}) để tiến hành đặt vé."]
229
  return DialogFlowResponseAPI(text=text)
230
 
231
  text = [f"Hệ thống không tìm thấy tuyến xe **{raw_departure_city}** - **{raw_destination_city}**.\n Quý khách vui lòng thử lại với lộ trình khác hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."]
 
189
  return DialogFlowResponseAPI(text=text, payload=payload)
190
  except:
191
  return DialogFlowResponseAPI(text=["Hệ thống xảy ra lỗi. Quý khách vui lòng thử lại sau hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."])
192
+ @router.post('/trip/list')
193
  async def booking_trip(request: Request) -> Response:
194
  body = await request.json()
195
  raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day = get_param_from_dialogflow(body)
 
212
  "sort_by": ["price", "departure_time"]
213
  }
214
  try:
215
+ response = await api.post("/search/trips", payload=payload)
216
+ if response.get('status') == 200:
217
+ data = response["data"]["items"]
218
+ total = response["data"]["total"]
219
  if total > 0:
 
220
  list_raw_departure_times = sorted(list(set([ trip["raw_departure_time"] for trip in data])))
221
  schedule_time_trip = "**" + "** | **".join(map(str, list_raw_departure_times)) + "**"
222
+ routes_name = []
223
+ for trip in data:
224
+ if trip["route"] not in routes_name:
225
+ routes_name.append(trip["route"]["name"])
226
+ print(routes_name)
227
+ text = " | ".join(map(str, routes_name))
228
  return DialogFlowResponseAPI(text=text)
229
 
230
  text = [f"Hệ thống không tìm thấy tuyến xe **{raw_departure_city}** - **{raw_destination_city}**.\n Quý khách vui lòng thử lại với lộ trình khác hoặc liên hệ Trung tâm tổng đài 1900 6067 để được hỗ trợ."]