update 8-8-2022
This commit is contained in:
@@ -8,6 +8,8 @@ from ..models.post import (
|
|||||||
ShowPostModel
|
ShowPostModel
|
||||||
)
|
)
|
||||||
from datetime import datetime, time, timedelta
|
from datetime import datetime, time, timedelta
|
||||||
|
import pytz
|
||||||
|
tz = pytz.timezone('Asia/Ho_Chi_Minh')
|
||||||
|
|
||||||
|
|
||||||
class PyObjectId(ObjectId):
|
class PyObjectId(ObjectId):
|
||||||
@@ -29,9 +31,11 @@ class PyObjectId(ObjectId):
|
|||||||
class HistoryModel(BaseModel):
|
class HistoryModel(BaseModel):
|
||||||
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
|
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
|
||||||
token: str = None
|
token: str = None
|
||||||
created_at: Optional[datetime] = None
|
created_at: Optional[datetime] = datetime.now(tz=tz)
|
||||||
status: str = None
|
status: str = None
|
||||||
note: str = None
|
post_id: str = None
|
||||||
|
key_find: str = None
|
||||||
|
# count: int = 0
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
@@ -43,18 +47,19 @@ class HistoryModel(BaseModel):
|
|||||||
"example": {
|
"example": {
|
||||||
"token": "",
|
"token": "",
|
||||||
"status": "",
|
"status": "",
|
||||||
"note": ""
|
"post_id": "",
|
||||||
|
"key_find": ""
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class HistoryByUserModel(BaseModel):
|
class HistoryByUserModel(BaseModel):
|
||||||
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
|
|
||||||
user_name: Union[str, None] = None
|
user_name: Union[str, None] = None
|
||||||
created_at: Optional[datetime] = None
|
created_at: Optional[datetime] = datetime.now(tz=tz)
|
||||||
status: str = None
|
status: str = None
|
||||||
note: str = None
|
note: str = None
|
||||||
|
data: str = None
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class PyObjectId(ObjectId):
|
|||||||
|
|
||||||
class SavePostModel(BaseModel):
|
class SavePostModel(BaseModel):
|
||||||
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
|
id: PyObjectId = Field(default_factory=PyObjectId, alias="_id")
|
||||||
user_name: str = None
|
username: str = None
|
||||||
# is_active: str = None
|
# is_active: str = None
|
||||||
created_at: Optional[datetime] = None
|
created_at: Optional[datetime] = None
|
||||||
post_id: str = None
|
post_id: str = None
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ async def create_history(username: str, status: str, note: str, history: History
|
|||||||
history_new = await db["history"].insert_one(history)
|
history_new = await db["history"].insert_one(history)
|
||||||
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
||||||
create_history = jsonable_encoder(create_history)
|
create_history = jsonable_encoder(create_history)
|
||||||
print(type(create_history))
|
|
||||||
# return JSONResponse(status_code=status.HTTP_201_CREATED, content=create_history)
|
# return JSONResponse(status_code=status.HTTP_201_CREATED, content=create_history)
|
||||||
return create_history
|
return create_history
|
||||||
|
|
||||||
@@ -60,11 +59,32 @@ async def list_post():
|
|||||||
return history_find
|
return history_find
|
||||||
|
|
||||||
|
|
||||||
@ history.get("/user_history", response_description="Get list Posts viewed")
|
@history.get("/user_history", response_description="Get list history", response_model=List[HistoryByUserModel])
|
||||||
async def get_list_post_view_by_username(token: str):
|
async def get_list_post_view_by_username(token: str):
|
||||||
data_token = await get_current_user(token)
|
data_token = await get_current_user(token)
|
||||||
user_name = data_token.get("user_name", None)
|
user_name = data_token.get("user_name", None)
|
||||||
if user_name == None:
|
if user_name == None:
|
||||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
history_find = await db["history"].find({"user_name": user_name}).to_list(100)
|
history_find = await db["history"].find({"user_name": user_name}).to_list(100)
|
||||||
|
print(history_find)
|
||||||
|
output = []
|
||||||
|
for dt in history_find:
|
||||||
|
if dt.get("note", None) != '':
|
||||||
|
post = await db["posts"].find_one({"_id": dt.get("note", None)})
|
||||||
|
input = []
|
||||||
|
print(dt)
|
||||||
|
dt["data"] = post["translation_post"]
|
||||||
|
output.append(dt)
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
@history.get("/user_history_key_find", response_description="Get list history key find")
|
||||||
|
async def get_key_find_view_by_username(token: str):
|
||||||
|
data_token = await get_current_user(token)
|
||||||
|
user_name = data_token.get("user_name", None)
|
||||||
|
if user_name == None:
|
||||||
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
|
print(0)
|
||||||
|
history_find = await db["history"].find({"user_name": user_name, "status": "Tìm kiếm bài viết theo từ khóa"}).to_list(10)
|
||||||
|
print(history)
|
||||||
return history_find
|
return history_find
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ async def post_html(content: str, request: Request):
|
|||||||
async def create_post(post: PostModel,
|
async def create_post(post: PostModel,
|
||||||
# current_user: UserModel = Depends(get_current_user)
|
# current_user: UserModel = Depends(get_current_user)
|
||||||
# token: TokenModel
|
# token: TokenModel
|
||||||
|
token: str
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
# print(post)
|
# print(post)
|
||||||
@@ -87,6 +88,29 @@ async def create_post(post: PostModel,
|
|||||||
created_post = await db["posts"].find_one({"_id": new_post.inserted_id})
|
created_post = await db["posts"].find_one({"_id": new_post.inserted_id})
|
||||||
# aaa = create_history(username=data, status="tạo bài viết",
|
# aaa = create_history(username=data, status="tạo bài viết",
|
||||||
# note=new_post.inserted_id, history=None)
|
# note=new_post.inserted_id, history=None)
|
||||||
|
# post.created_at = datetime.datetime.now(tz=tz)
|
||||||
|
data_token = await get_current_user(token)
|
||||||
|
data = data_token.get("user_name", None)
|
||||||
|
user_type = data_token.get("user_type", None)
|
||||||
|
if data == None:
|
||||||
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
|
history_user = post
|
||||||
|
print(history_user)
|
||||||
|
history_user["user_name"] = data
|
||||||
|
history_user["status"] = "Thêm mới bài viết"
|
||||||
|
history_user["note"] = new_post.inserted_id
|
||||||
|
history_user["data"] = ''
|
||||||
|
del history_user["original_post"]
|
||||||
|
del history_user["translation_post"]
|
||||||
|
del history_user["link"]
|
||||||
|
del history_user["is_active"]
|
||||||
|
# del history_user["created_at"]
|
||||||
|
del history_user["point"]
|
||||||
|
del history_user["specialist"]
|
||||||
|
del history_user["data"]
|
||||||
|
del history_user["summary"]
|
||||||
|
history_new = await db["history"].insert_one(history_user)
|
||||||
|
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
||||||
return JSONResponse(status_code=status.HTTP_201_CREATED, content=created_post)
|
return JSONResponse(status_code=status.HTTP_201_CREATED, content=created_post)
|
||||||
except NameError:
|
except NameError:
|
||||||
return NameError
|
return NameError
|
||||||
@@ -135,8 +159,7 @@ async def list_post(
|
|||||||
@post.post(
|
@post.post(
|
||||||
"/find_list_post", response_description="search list posts"
|
"/find_list_post", response_description="search list posts"
|
||||||
)
|
)
|
||||||
async def list_post(key_find: str, token: TokenModel = None):
|
async def list_post(key_find: str, token: str = None, history: HistoryFindModel = None):
|
||||||
|
|
||||||
# point_data = ["point.less10",
|
# point_data = ["point.less10",
|
||||||
# "point.form10to20",
|
# "point.form10to20",
|
||||||
# "point.form20to30",
|
# "point.form20to30",
|
||||||
@@ -166,12 +189,30 @@ async def list_post(key_find: str, token: TokenModel = None):
|
|||||||
]
|
]
|
||||||
}).sort(age_sort, -1).to_list(100)
|
}).sort(age_sort, -1).to_list(100)
|
||||||
output = []
|
output = []
|
||||||
if token.token != None:
|
if token != None:
|
||||||
posts = jsonable_encoder(posts)
|
data_token = await get_current_user(token)
|
||||||
for post in posts:
|
|
||||||
data_token = await get_current_user(token.token)
|
|
||||||
data = data_token.get("user_name", None)
|
data = data_token.get("user_name", None)
|
||||||
user_type = data_token.get("user_type", None)
|
user_type = data_token.get("user_type", None)
|
||||||
|
history.created_at = datetime.datetime.now(tz=tz)
|
||||||
|
history = jsonable_encoder(history)
|
||||||
|
history_user = history
|
||||||
|
history_user["user_name"] = data
|
||||||
|
history_user["status"] = "Tìm kiếm bài viết theo từ khóa"
|
||||||
|
history_user["note"] = ""
|
||||||
|
history_user["data"] = key_find
|
||||||
|
# check_data = await db["history"].find_one({"data": key_find, "status": "Tìm kiếm bài viết theo từ khóa"})
|
||||||
|
# print(check_data)
|
||||||
|
# count = check_data.get("count", None)
|
||||||
|
# if count != None:
|
||||||
|
# history_user["count"] = count + 1
|
||||||
|
# else:
|
||||||
|
# history_user["count"] = 1
|
||||||
|
del history_user["_id"]
|
||||||
|
del history_user["token"]
|
||||||
|
del history_user["sick"]
|
||||||
|
del history_user["authorities"]
|
||||||
|
history_new = await db["history"].insert_one(history_user)
|
||||||
|
for post in posts:
|
||||||
if data == None:
|
if data == None:
|
||||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
post = jsonable_encoder(post)
|
post = jsonable_encoder(post)
|
||||||
@@ -183,6 +224,8 @@ async def list_post(key_find: str, token: TokenModel = None):
|
|||||||
post["post_save"] = False
|
post["post_save"] = False
|
||||||
output.append(post)
|
output.append(post)
|
||||||
return output
|
return output
|
||||||
|
else:
|
||||||
|
return posts
|
||||||
|
|
||||||
|
|
||||||
@post.post(
|
@post.post(
|
||||||
@@ -222,10 +265,26 @@ async def get_post_by_name(history: HistoryFindModel):
|
|||||||
if not ROLE_PUBLIC in dt["level"]:
|
if not ROLE_PUBLIC in dt["level"]:
|
||||||
if not user_type in dt["level"]:
|
if not user_type in dt["level"]:
|
||||||
post["data"].remove(dt)
|
post["data"].remove(dt)
|
||||||
history = jsonable_encoder(history)
|
history_find = jsonable_encoder(history)
|
||||||
new_his = await db["history_find"].insert_one(history)
|
print(history_find)
|
||||||
|
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": data})
|
||||||
|
if count != 0:
|
||||||
|
post["post_save"] = True
|
||||||
|
else:
|
||||||
|
post["post_save"] = False
|
||||||
|
new_his = await db["history_find"].insert_one(history_find)
|
||||||
created = await db["history_find"].find_one({"_id": new_his.inserted_id})
|
created = await db["history_find"].find_one({"_id": new_his.inserted_id})
|
||||||
print(post)
|
history_user = history_find
|
||||||
|
history_user["user_name"] = data
|
||||||
|
history_user["status"] = "xem bài viết"
|
||||||
|
history_user["note"] = history_user["post_id"]
|
||||||
|
history_user["data"] = ''
|
||||||
|
del history_user["_id"]
|
||||||
|
del history_user["token"]
|
||||||
|
del history_user["sick"]
|
||||||
|
del history_user["authorities"]
|
||||||
|
history_new = await db["history"].insert_one(history_user)
|
||||||
|
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
||||||
if post is not None:
|
if post is not None:
|
||||||
return post
|
return post
|
||||||
else:
|
else:
|
||||||
@@ -267,10 +326,29 @@ async def get_post_edit(history: HistoryFindModel):
|
|||||||
@post.delete("/delete_post/{id}", response_description="Delete a post")
|
@post.delete("/delete_post/{id}", response_description="Delete a post")
|
||||||
async def delete_user(id: str,
|
async def delete_user(id: str,
|
||||||
# current_user: UserModel = Depends(get_current_user)
|
# current_user: UserModel = Depends(get_current_user)
|
||||||
|
token: str,
|
||||||
|
post: UpdatePostModel = None
|
||||||
):
|
):
|
||||||
|
|
||||||
delete_result = await db["posts"].delete_one({"_id": id})
|
delete_result = await db["posts"].delete_one({"_id": id})
|
||||||
if delete_result.deleted_count == 1:
|
if delete_result.deleted_count == 1:
|
||||||
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT)
|
post = jsonable_encoder(post)
|
||||||
|
data_token = await get_current_user(token)
|
||||||
|
data = data_token.get("user_name", None)
|
||||||
|
user_type = data_token.get("user_type", None)
|
||||||
|
if data == None:
|
||||||
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
|
print(data)
|
||||||
|
history_user = {}
|
||||||
|
history_user["user_name"] = data
|
||||||
|
history_user["status"] = "xóa bài viết"
|
||||||
|
history_user["note"] = id
|
||||||
|
history_user["data"] = ''
|
||||||
|
history_new = await db["history"].insert_one(history_user)
|
||||||
|
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
||||||
|
print(history_new)
|
||||||
|
print(history_user)
|
||||||
|
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content={"message": "Delete successfull"})
|
||||||
raise HTTPException(status_code=404, detail=f"Post {id} not found")
|
raise HTTPException(status_code=404, detail=f"Post {id} not found")
|
||||||
|
|
||||||
|
|
||||||
@@ -432,8 +510,8 @@ async def video_endpoint(video_name
|
|||||||
return StreamingResponse(iterfile(), media_type="video/mp4")
|
return StreamingResponse(iterfile(), media_type="video/mp4")
|
||||||
|
|
||||||
|
|
||||||
@post.post("/edit_post/{id}", response_description="score all post", response_model=UpdatePostModel)
|
@post.post("/edit_post/{id}", response_description="score all post")
|
||||||
async def edit_post(id: str, post: UpdatePostModel):
|
async def edit_post(id: str, post: UpdatePostModel, token: str):
|
||||||
try:
|
try:
|
||||||
post.updated_at = datetime.datetime.now(tz=tz)
|
post.updated_at = datetime.datetime.now(tz=tz)
|
||||||
post = jsonable_encoder(post)
|
post = jsonable_encoder(post)
|
||||||
@@ -443,7 +521,33 @@ async def edit_post(id: str, post: UpdatePostModel):
|
|||||||
post
|
post
|
||||||
})
|
})
|
||||||
|
|
||||||
return JSONResponse(status_code=status.HTTP_200_OK, content=post)
|
data_token = await get_current_user(token)
|
||||||
|
data = data_token.get("user_name", None)
|
||||||
|
user_type = data_token.get("user_type", None)
|
||||||
|
if data == None:
|
||||||
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
|
history_user = post
|
||||||
|
print(post)
|
||||||
|
history_user["user_name"] = data
|
||||||
|
history_user["status"] = "sửa bài viết"
|
||||||
|
history_user["note"] = id
|
||||||
|
history_user["data"] = ""
|
||||||
|
history_user["created_at"] = history_user["updated_at"]
|
||||||
|
del history_user["original_post"]
|
||||||
|
del history_user["translation_post"]
|
||||||
|
del history_user["link"]
|
||||||
|
del history_user["is_active"]
|
||||||
|
# del history_user["created_at"]
|
||||||
|
del history_user["updated_at"]
|
||||||
|
del history_user["specialist"]
|
||||||
|
del history_user["data"]
|
||||||
|
del history_user["summary"]
|
||||||
|
print(history_user)
|
||||||
|
del history_user["point"]
|
||||||
|
history_new = await db["history"].insert_one(history_user)
|
||||||
|
print(history_user)
|
||||||
|
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
||||||
|
return JSONResponse(status_code=status.HTTP_200_OK, content={"massege": "update successfull"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
|||||||
@@ -54,16 +54,16 @@ async def create_post(post_save: SavePost):
|
|||||||
data = data_output.get("user_name", None)
|
data = data_output.get("user_name", None)
|
||||||
if data == None:
|
if data == None:
|
||||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
count = await db["posts"].count_documents({"post_id": post_save.post_id, "username": data})
|
count = await db["posts"].count_documents({"_id": post_save.post_id})
|
||||||
if count == 0:
|
if count == 0:
|
||||||
return f"Post {post_save.post_id} not found"
|
return JSONResponse(status_code=status.HTTP_409_CONFLICT, content={"message": "Bài viết không tồn tại"})
|
||||||
post_save.created_at = datetime.datetime.now(tz=tz)
|
post_save.created_at = datetime.datetime.now(tz=tz)
|
||||||
post_save = jsonable_encoder(post_save)
|
post_save = jsonable_encoder(post_save)
|
||||||
del post_save["token"]
|
del post_save["token"]
|
||||||
post_save["username"] = data
|
post_save["username"] = data
|
||||||
created_post = await db["post_save"].count_documents({"post_id": post_save["post_id"], "username": data})
|
created_post = await db["post_save"].count_documents({"post_id": post_save["post_id"], "username": data})
|
||||||
if created_post == 1:
|
if created_post == 1:
|
||||||
return {"message": f'Post {post_save["post_id"]} saved'}
|
return JSONResponse(status_code=status.HTTP_409_CONFLICT, content={"message": "Bài viết đã được lưu trước đó"})
|
||||||
new_post = await db["post_save"].insert_one(post_save)
|
new_post = await db["post_save"].insert_one(post_save)
|
||||||
created_post = await db["post_save"].find_one({"_id": new_post.inserted_id})
|
created_post = await db["post_save"].find_one({"_id": new_post.inserted_id})
|
||||||
return JSONResponse(status_code=status.HTTP_201_CREATED, content=created_post)
|
return JSONResponse(status_code=status.HTTP_201_CREATED, content=created_post)
|
||||||
@@ -87,17 +87,15 @@ async def list_post(post_save: SavePost):
|
|||||||
if data == None:
|
if data == None:
|
||||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
posts = await db["post_save"].find({"username": data}).to_list(1000)
|
posts = await db["post_save"].find({"username": data}).to_list(1000)
|
||||||
print(posts)
|
|
||||||
print(len(posts))
|
|
||||||
return JSONResponse(status_code=status.HTTP_200_OK, content=posts)
|
return JSONResponse(status_code=status.HTTP_200_OK, content=posts)
|
||||||
|
|
||||||
|
|
||||||
@post_save.delete("/delete_save_post", response_description="Delete save post")
|
@post_save.delete("/delete_save_post", response_description="Delete save post")
|
||||||
async def delete_save_post(post_save: SavePost):
|
async def delete_save_post(post_id: str, token: str):
|
||||||
# delete_result = await db["post_save"].delete_one({"_id": user_id})
|
# delete_result = await db["post_save"].delete_one({"_id": user_id})
|
||||||
try:
|
try:
|
||||||
url = "https://sandboxapi.ebacsi.com.vn/auth/oauth/check_token"
|
url = "https://sandboxapi.ebacsi.com.vn/auth/oauth/check_token"
|
||||||
payload = {'token': post_save.token}
|
payload = {'token': token}
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||||
}
|
}
|
||||||
@@ -107,13 +105,10 @@ async def delete_save_post(post_save: SavePost):
|
|||||||
data = data_output.get("user_name", None)
|
data = data_output.get("user_name", None)
|
||||||
if data == None:
|
if data == None:
|
||||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||||
|
delete_result = await db["post_save"].delete_one({"post_id": post_id, "username": data})
|
||||||
post_save = jsonable_encoder(post_save)
|
|
||||||
delete_result = await db["post_save"].delete_one({"post_id": post_save["post_id"], "username": data})
|
|
||||||
if delete_result.deleted_count == 1:
|
if delete_result.deleted_count == 1:
|
||||||
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": "Delete post save successful"})
|
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": "Delete post save successful"})
|
||||||
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=404, detail=f'Post save {post_save["post_id"]} not found')
|
status_code=404, detail=f'Post save {post_id} not found')
|
||||||
except NameError:
|
except NameError:
|
||||||
return NameError
|
return NameError
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class TokenModel(BaseModel):
|
|||||||
token: str = None
|
token: str = None
|
||||||
refresh_token: str = None
|
refresh_token: str = None
|
||||||
grant_type: str = None
|
grant_type: str = None
|
||||||
|
created_at: datetime = None
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from fastapi.security import OAuth2PasswordBearer
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
from passlib.context import CryptContext
|
from passlib.context import CryptContext
|
||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
from json import JSONEncoder
|
||||||
import os
|
import os
|
||||||
import motor.motor_asyncio
|
import motor.motor_asyncio
|
||||||
|
|
||||||
@@ -12,6 +14,14 @@ ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
|||||||
|
|
||||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
|
|
||||||
|
|
||||||
|
class DateTimeEncoder(JSONEncoder):
|
||||||
|
# Override the default method
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, (datetime.date, datetime.datetime)):
|
||||||
|
return obj.isoformat()
|
||||||
|
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(
|
oauth2_scheme = OAuth2PasswordBearer(
|
||||||
tokenUrl="https://sandboxapi.ebacsi.com.vn/auth/oauth/token")
|
tokenUrl="https://sandboxapi.ebacsi.com.vn/auth/oauth/token")
|
||||||
ROLE_PUBLIC = "PUBLIC"
|
ROLE_PUBLIC = "PUBLIC"
|
||||||
|
|||||||
Reference in New Issue
Block a user