kltn20133118 commited on
Commit
9cf7565
·
verified ·
1 Parent(s): fb5927c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +63 -57
main.py CHANGED
@@ -106,7 +106,7 @@ def get_current_user_email(credentials: str = Depends(JWTBearer())):
106
  raise HTTPException(status_code=403, detail="Invalid token or expired token.")
107
 
108
 
109
- @app.get("/api/mysql/render_chat_history", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
110
  async def override_render_chat(user_id: Optional[str] = Query(None),
111
  current_user_email: str = Depends(get_current_user_email)):
112
  check = support_function.check_value_user_id(user_id, current_user_email)
@@ -116,7 +116,7 @@ async def override_render_chat(user_id: Optional[str] = Query(None),
116
  return MySQLService.render_chat_history(request)
117
 
118
 
119
- @app.put("/api/mysql/edit_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
120
  async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
121
  current_user_email: str = Depends(get_current_user_email)):
122
  user_id = request.user_id
@@ -132,7 +132,7 @@ async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
132
  return MySQLService.edit_chat(request)
133
 
134
 
135
- @app.delete("/api/mysql/delete_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
136
  async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
137
  current_user_email: str = Depends(get_current_user_email)):
138
  user_id = request.user_id
@@ -145,7 +145,7 @@ async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
145
  return MySQLService.delete_chat(request)
146
 
147
 
148
- @app.get("/api/mysql/load_chat_history", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
149
  async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Optional[str] = Query(None),
150
  current_user_email: str = Depends(get_current_user_email)):
151
  check = support_function.check_value_user_id(user_id, current_user_email)
@@ -167,7 +167,7 @@ async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Opti
167
  return MySQLService.load_chat_history(request)
168
 
169
 
170
- @app.get("/api/default/info_user", dependencies=[Depends(JWTBearer())], tags=["Default"])
171
  async def override_get_user(user_id: str = Query(None), current_user_email: str = Depends(get_current_user_email)):
172
  check = support_function.check_value_user_id(user_id, current_user_email)
173
  if check is not True:
@@ -176,7 +176,7 @@ async def override_get_user(user_id: str = Query(None), current_user_email: str
176
  return DefaultService.info_user(request)
177
 
178
 
179
- @app.post("/api/users/update_user_info", dependencies=[Depends(JWTBearer())], tags=["Login"])
180
  async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo,
181
  current_user_email: str = Depends(get_current_user_email)):
182
  user_id = request.user_id
@@ -201,7 +201,7 @@ async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo,
201
  return LoginService.update_user_info(request)
202
 
203
 
204
- @app.put('/api/users/change_password', dependencies=[Depends(JWTBearer())], tags=["Login"])
205
  async def override_reset_password_firebase(request: RequestLogin.RequestChangePassword,
206
  current_user_email: str = Depends(get_current_user_email)):
207
  user_id = request.user_id
@@ -210,16 +210,22 @@ async def override_reset_password_firebase(request: RequestLogin.RequestChangePa
210
  return check
211
  new_password = request.new_password
212
  current_password = request.current_password
 
 
213
  if new_password is None or new_password.strip() == "":
214
  return res.ReponseError(status=400,
215
  data=res.Message(message="new_password field is required."))
216
  if current_password is None or current_password.strip() == "":
217
  return res.ReponseError(status=400,
218
  data=res.Message(message="current_password field is required."))
 
 
 
 
219
  return LoginService.change_password(request)
220
 
221
 
222
- @app.delete("/api/file/delete_all_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
223
  async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
224
  current_user_email: str = Depends(get_current_user_email)):
225
  check = support_function.check_value_user_id(request.user_id, current_user_email)
@@ -228,7 +234,7 @@ async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
228
  return FileService.deleteAllFile(request)
229
 
230
 
231
- @app.delete("/api/file/delete_one_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
232
  async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
233
  current_user_email: str = Depends(get_current_user_email)):
234
  user_id = request.user_id
@@ -242,7 +248,7 @@ async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
242
  return FileService.deleteFile(request)
243
 
244
 
245
- @app.post("/api/file/chatbot/download_folder/", dependencies=[Depends(JWTBearer())], tags=["File"])
246
  async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder,
247
  current_user_email: str = Depends(get_current_user_email)):
248
  user_id = request.user_id
@@ -252,7 +258,7 @@ async def override_download_folder_from_dropbox(request: RequestFile.RequestDown
252
  return FileService.download_folder(request)
253
 
254
 
255
- @app.post("/api/file/chatbot/download_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
256
  async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
257
  current_user_email: str = Depends(get_current_user_email)):
258
  user_id = request.user_id
@@ -262,7 +268,7 @@ async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
262
  return FileService.download_file(request)
263
 
264
 
265
- @app.post("/api/file/upload_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
266
  async def override_upload_files_dropbox(
267
  user_id: str = Form(None),
268
  files: List[UploadFile] = File(None),
@@ -275,7 +281,7 @@ async def override_upload_files_dropbox(
275
  return FileService.upload_files(request)
276
 
277
 
278
- @app.post("/api/chat/chatbot/query/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
279
  async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...),
280
  question: str = Form(None), chat_name: str = Form(None),
281
  current_user_email: str = Depends(get_current_user_email)):
@@ -287,7 +293,7 @@ async def override_handle_query2_upgrade_old(request: Request, user_id: str = Fo
287
  return ChatService.query2_upgrade_old(request)
288
 
289
 
290
- @app.get("/api/chat/chatbot/extract_file/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
291
  async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
292
  check = support_function.check_value_user_id(user_id, current_user_email)
293
  if check is not True:
@@ -296,7 +302,7 @@ async def override_extract_file(user_id: str, current_user_email: str = Depends(
296
  return ChatService.extract_file(request)
297
 
298
 
299
- @app.get("/api/chat/chatbot/generate_question/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
300
  async def override_generate_question(user_id: str, current_user_email: str = Depends(get_current_user_email)):
301
  check = support_function.check_value_user_id(user_id, current_user_email)
302
  if check is not True:
@@ -305,7 +311,7 @@ async def override_generate_question(user_id: str, current_user_email: str = Dep
305
  return ChatService.generate_question(request)
306
 
307
 
308
- @app.post("/api/default/upload_image/", dependencies=[Depends(JWTBearer())], tags=["Default"])
309
  async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),
310
  current_user_email: str = Depends(get_current_user_email)):
311
  check = support_function.check_value_user_id(user_id, current_user_email)
@@ -315,30 +321,30 @@ async def override_upload_image(user_id: str = Form(None), file: UploadFile = Fi
315
  return DefaultService.upload_image_service(request)
316
 
317
 
318
- app.include_router(MySQLController.router, prefix="/api/mysql")
319
- app.include_router(LoginController.router, prefix="/api/users")
320
- app.include_router(FileController.router, prefix="/api/file")
321
- app.include_router(ChatController.router, prefix="/api/chat")
322
- app.include_router(DefaultController.router, prefix="/api/default")
323
 
324
  routes_to_override = {
325
- "/api/mysql/render_chat_history": {"GET"},
326
- "/api/mysql/load_chat_history": {"GET"},
327
- "/api/mysql/edit_chat/": {"PUT"},
328
- "/api/mysql/delete_chat/": {"DELETE"},
329
- "/api/users/update_user_info": {"POST"},
330
- "/api/users/change_password": {"PUT"},
331
- "/api/file/delete_all_file/": {"DELETE"},
332
- "/api/file/delete_one_file/": {"DELETE"},
333
- "/api/file/chatbot/download_folder/": {"POST"},
334
- "/api/file/chatbot/download_files/": {"POST"},
335
- "/api/file/upload_files/": {"POST"},
336
- "/api/chat/query2_upgrade/": {"POST"},
337
- "/api/chat/chatbot/query/": {"POST"},
338
- "/api/chat/chatbot/extract_file/": {"GET"},
339
- "/api/chat/chatbot/generate_question/": {"GET"},
340
- "/api/default/upload_image/": {"POST"},
341
- "/api/default/info_user": {"GET"}
342
 
343
  }
344
 
@@ -350,36 +356,36 @@ app.router.routes = [
350
  )
351
  ]
352
 
353
- app.add_api_route("/api/mysql/render_chat_history", override_render_chat, methods=["GET"],
354
  dependencies=[Depends(JWTBearer())], tags=["MySQL"])
355
- app.add_api_route("/api/mysql/load_chat_history", override_load_chat, methods=["GET"],
356
  dependencies=[Depends(JWTBearer())], tags=["MySQL"])
357
- app.add_api_route("/api/mysql/edit_chat/", override_edit_chat, methods=["PUT"], dependencies=[Depends(JWTBearer())],
358
  tags=["MySQL"])
359
- app.add_api_route("/api/mysql/delete_chat/", override_delete_chat, methods=["DELETE"],
360
  dependencies=[Depends(JWTBearer())], tags=["MySQL"])
361
- app.add_api_route("/api/users/update_user_info", override_update_user_info, methods=["POST"],
362
- dependencies=[Depends(JWTBearer())], tags=["Login"])
363
- app.add_api_route("/api/users/change_password", override_reset_password_firebase, methods=["PUT"],
364
- dependencies=[Depends(JWTBearer())], tags=["Login"])
365
- app.add_api_route("/api/file/delete_all_file/", override_delete_folder, methods=["DELETE"],
366
  dependencies=[Depends(JWTBearer())], tags=["File"])
367
- app.add_api_route("/api/file/delete_one_file/", override_delete_one_file, methods=["DELETE"],
368
  dependencies=[Depends(JWTBearer())], tags=["File"])
369
- app.add_api_route("/api/file/chatbot/download_folder/", override_download_folder_from_dropbox, methods=["POST"],
370
  dependencies=[Depends(JWTBearer())], tags=["File"])
371
- app.add_api_route("/api/file/chatbot/download_files/", override_download_file_by_id, methods=["POST"],
372
  dependencies=[Depends(JWTBearer())], tags=["File"])
373
- app.add_api_route("/api/file/upload_files/", override_upload_files_dropbox, methods=["POST"],
374
  dependencies=[Depends(JWTBearer())], tags=["File"])
375
- app.add_api_route("/api/chat/chatbot/query/", override_handle_query2_upgrade_old, methods=["POST"],
376
  dependencies=[Depends(JWTBearer())], tags=["Chat"])
377
- app.add_api_route("/api/chat/chatbot/extract_file/", override_extract_file, methods=["GET"],
378
  dependencies=[Depends(JWTBearer())], tags=["Chat"])
379
- app.add_api_route("/api/chat/chatbot/generate_question/", override_generate_question, methods=["GET"],
380
  dependencies=[Depends(JWTBearer())], tags=["Chat"])
381
- app.add_api_route("/api/default/upload_image/", override_upload_image, methods=["POST"],
382
  dependencies=[Depends(JWTBearer())], tags=["Default"])
383
- app.add_api_route("/api/default/info_user", override_get_user, methods=["GET"], dependencies=[Depends(JWTBearer())],
384
  tags=["Default"])
385
- app.include_router(OTPController.router, tags=["OTP"], prefix="/api/otp")
 
106
  raise HTTPException(status_code=403, detail="Invalid token or expired token.")
107
 
108
 
109
+ @app.get("/api/v1/mysql/render_chat_history", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
110
  async def override_render_chat(user_id: Optional[str] = Query(None),
111
  current_user_email: str = Depends(get_current_user_email)):
112
  check = support_function.check_value_user_id(user_id, current_user_email)
 
116
  return MySQLService.render_chat_history(request)
117
 
118
 
119
+ @app.put("/api/v1/mysql/edit_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
120
  async def override_edit_chat(request: RequestMySQL.RequestEditNameChat,
121
  current_user_email: str = Depends(get_current_user_email)):
122
  user_id = request.user_id
 
132
  return MySQLService.edit_chat(request)
133
 
134
 
135
+ @app.delete("/api/v1/mysql/delete_chat/", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
136
  async def override_delete_chat(request: RequestMySQL.RequestDeleteChat,
137
  current_user_email: str = Depends(get_current_user_email)):
138
  user_id = request.user_id
 
145
  return MySQLService.delete_chat(request)
146
 
147
 
148
+ @app.get("/api/v1/mysql/load_chat_history", dependencies=[Depends(JWTBearer())], tags=["MySQL"])
149
  async def override_load_chat(chat_id: Optional[str] = Query(None), user_id: Optional[str] = Query(None),
150
  current_user_email: str = Depends(get_current_user_email)):
151
  check = support_function.check_value_user_id(user_id, current_user_email)
 
167
  return MySQLService.load_chat_history(request)
168
 
169
 
170
+ @app.get("/api/v1/default/info_user", dependencies=[Depends(JWTBearer())], tags=["Default"])
171
  async def override_get_user(user_id: str = Query(None), current_user_email: str = Depends(get_current_user_email)):
172
  check = support_function.check_value_user_id(user_id, current_user_email)
173
  if check is not True:
 
176
  return DefaultService.info_user(request)
177
 
178
 
179
+ @app.post("/api/v1/users/update_user_info", dependencies=[Depends(JWTBearer())], tags=["User"])
180
  async def override_update_user_info(request: RequestLogin.RequestUpdateUserInfo,
181
  current_user_email: str = Depends(get_current_user_email)):
182
  user_id = request.user_id
 
201
  return LoginService.update_user_info(request)
202
 
203
 
204
+ @app.put('/api/v1/users/change_password', dependencies=[Depends(JWTBearer())], tags=["User"])
205
  async def override_reset_password_firebase(request: RequestLogin.RequestChangePassword,
206
  current_user_email: str = Depends(get_current_user_email)):
207
  user_id = request.user_id
 
210
  return check
211
  new_password = request.new_password
212
  current_password = request.current_password
213
+ confirm_new_password = request.confirm_new_password
214
+
215
  if new_password is None or new_password.strip() == "":
216
  return res.ReponseError(status=400,
217
  data=res.Message(message="new_password field is required."))
218
  if current_password is None or current_password.strip() == "":
219
  return res.ReponseError(status=400,
220
  data=res.Message(message="current_password field is required."))
221
+ if confirm_new_password is None or confirm_new_password.strip() == "":
222
+ return res.ReponseError(status=400,
223
+ data=res.Message(message="confirm_new_password field is required."))
224
+
225
  return LoginService.change_password(request)
226
 
227
 
228
+ @app.delete("/api/v1/file/delete_all_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
229
  async def override_delete_folder(request: RequestFile.RequestDeleteAllFile,
230
  current_user_email: str = Depends(get_current_user_email)):
231
  check = support_function.check_value_user_id(request.user_id, current_user_email)
 
234
  return FileService.deleteAllFile(request)
235
 
236
 
237
+ @app.delete("/api/v1/file/delete_one_file/", dependencies=[Depends(JWTBearer())], tags=["File"])
238
  async def override_delete_one_file(request: RequestFile.RequestDeleteFile,
239
  current_user_email: str = Depends(get_current_user_email)):
240
  user_id = request.user_id
 
248
  return FileService.deleteFile(request)
249
 
250
 
251
+ @app.post("/api/v1/file/chatbot/download_folder/", dependencies=[Depends(JWTBearer())], tags=["File"])
252
  async def override_download_folder_from_dropbox(request: RequestFile.RequestDownLoadFolder,
253
  current_user_email: str = Depends(get_current_user_email)):
254
  user_id = request.user_id
 
258
  return FileService.download_folder(request)
259
 
260
 
261
+ @app.post("/api/v1/file/chatbot/download_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
262
  async def override_download_file_by_id(request: RequestFile.RequestDownLoadFile,
263
  current_user_email: str = Depends(get_current_user_email)):
264
  user_id = request.user_id
 
268
  return FileService.download_file(request)
269
 
270
 
271
+ @app.post("/api/v1/file/upload_files/", dependencies=[Depends(JWTBearer())], tags=["File"])
272
  async def override_upload_files_dropbox(
273
  user_id: str = Form(None),
274
  files: List[UploadFile] = File(None),
 
281
  return FileService.upload_files(request)
282
 
283
 
284
+ @app.post("/api/v1/chat/chatbot/query/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
285
  async def override_handle_query2_upgrade_old(request: Request, user_id: str = Form(None), text_all: str = Form(...),
286
  question: str = Form(None), chat_name: str = Form(None),
287
  current_user_email: str = Depends(get_current_user_email)):
 
293
  return ChatService.query2_upgrade_old(request)
294
 
295
 
296
+ @app.get("/api/v1/chat/chatbot/extract_file/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
297
  async def override_extract_file(user_id: str, current_user_email: str = Depends(get_current_user_email)):
298
  check = support_function.check_value_user_id(user_id, current_user_email)
299
  if check is not True:
 
302
  return ChatService.extract_file(request)
303
 
304
 
305
+ @app.get("/api/v1/chat/chatbot/generate_question/", dependencies=[Depends(JWTBearer())], tags=["Chatbot"])
306
  async def override_generate_question(user_id: str, current_user_email: str = Depends(get_current_user_email)):
307
  check = support_function.check_value_user_id(user_id, current_user_email)
308
  if check is not True:
 
311
  return ChatService.generate_question(request)
312
 
313
 
314
+ @app.post("/api/v1/default/upload_image/", dependencies=[Depends(JWTBearer())], tags=["Default"])
315
  async def override_upload_image(user_id: str = Form(None), file: UploadFile = File(...),
316
  current_user_email: str = Depends(get_current_user_email)):
317
  check = support_function.check_value_user_id(user_id, current_user_email)
 
321
  return DefaultService.upload_image_service(request)
322
 
323
 
324
+ app.include_router(MySQLController.router, prefix="/api/v1/mysql")
325
+ app.include_router(LoginController.router, prefix="/api/v1/users")
326
+ app.include_router(FileController.router, prefix="/api/v1/file")
327
+ app.include_router(ChatController.router, prefix="/api/v1/chat")
328
+ app.include_router(DefaultController.router, prefix="/api/v1/default")
329
 
330
  routes_to_override = {
331
+ "/api/v1/mysql/render_chat_history": {"GET"},
332
+ "/api/v1/mysql/load_chat_history": {"GET"},
333
+ "/api/v1/mysql/edit_chat/": {"PUT"},
334
+ "/api/v1/mysql/delete_chat/": {"DELETE"},
335
+ "/api/v1/users/update_user_info": {"POST"},
336
+ "/api/v1/users/change_password": {"PUT"},
337
+ "/api/v1/file/delete_all_file/": {"DELETE"},
338
+ "/api/v1/file/delete_one_file/": {"DELETE"},
339
+ "/api/v1/file/chatbot/download_folder/": {"POST"},
340
+ "/api/v1/file/chatbot/download_files/": {"POST"},
341
+ "/api/v1/file/upload_files/": {"POST"},
342
+ "/api/v1/chat/query2_upgrade/": {"POST"},
343
+ "/api/v1/chat/chatbot/query/": {"POST"},
344
+ "/api/v1/chat/chatbot/extract_file/": {"GET"},
345
+ "/api/v1/chat/chatbot/generate_question/": {"GET"},
346
+ "/api/v1/default/upload_image/": {"POST"},
347
+ "/api/v1/default/info_user": {"GET"}
348
 
349
  }
350
 
 
356
  )
357
  ]
358
 
359
+ app.add_api_route("/api/v1/mysql/render_chat_history", override_render_chat, methods=["GET"],
360
  dependencies=[Depends(JWTBearer())], tags=["MySQL"])
361
+ app.add_api_route("/api/v1/mysql/load_chat_history", override_load_chat, methods=["GET"],
362
  dependencies=[Depends(JWTBearer())], tags=["MySQL"])
363
+ app.add_api_route("/api/v1/mysql/edit_chat/", override_edit_chat, methods=["PUT"], dependencies=[Depends(JWTBearer())],
364
  tags=["MySQL"])
365
+ app.add_api_route("/api/v1/mysql/delete_chat/", override_delete_chat, methods=["DELETE"],
366
  dependencies=[Depends(JWTBearer())], tags=["MySQL"])
367
+ app.add_api_route("/api/v1/users/update_user_info", override_update_user_info, methods=["POST"],
368
+ dependencies=[Depends(JWTBearer())], tags=["User"])
369
+ app.add_api_route("/api/v1/users/change_password", override_reset_password_firebase, methods=["PUT"],
370
+ dependencies=[Depends(JWTBearer())], tags=["User"])
371
+ app.add_api_route("/api/v1/file/delete_all_file/", override_delete_folder, methods=["DELETE"],
372
  dependencies=[Depends(JWTBearer())], tags=["File"])
373
+ app.add_api_route("/api/v1/file/delete_one_file/", override_delete_one_file, methods=["DELETE"],
374
  dependencies=[Depends(JWTBearer())], tags=["File"])
375
+ app.add_api_route("/api/v1/file/chatbot/download_folder/", override_download_folder_from_dropbox, methods=["POST"],
376
  dependencies=[Depends(JWTBearer())], tags=["File"])
377
+ app.add_api_route("/api/v1/file/chatbot/download_files/", override_download_file_by_id, methods=["POST"],
378
  dependencies=[Depends(JWTBearer())], tags=["File"])
379
+ app.add_api_route("/api/v1/file/upload_files/", override_upload_files_dropbox, methods=["POST"],
380
  dependencies=[Depends(JWTBearer())], tags=["File"])
381
+ app.add_api_route("/api/v1/chat/chatbot/query/", override_handle_query2_upgrade_old, methods=["POST"],
382
  dependencies=[Depends(JWTBearer())], tags=["Chat"])
383
+ app.add_api_route("/api/v1/chat/chatbot/extract_file/", override_extract_file, methods=["GET"],
384
  dependencies=[Depends(JWTBearer())], tags=["Chat"])
385
+ app.add_api_route("/api/v1/chat/chatbot/generate_question/", override_generate_question, methods=["GET"],
386
  dependencies=[Depends(JWTBearer())], tags=["Chat"])
387
+ app.add_api_route("/api/v1/default/upload_image/", override_upload_image, methods=["POST"],
388
  dependencies=[Depends(JWTBearer())], tags=["Default"])
389
+ app.add_api_route("/api/v1/default/info_user", override_get_user, methods=["GET"], dependencies=[Depends(JWTBearer())],
390
  tags=["Default"])
391
+ app.include_router(OTPController.router, tags=["OTP"], prefix="/api/v1/otp")