save 19.8
This commit is contained in:
@@ -74,43 +74,42 @@ class PostModel(BaseModel):
|
||||
"original_post": "Joh111",
|
||||
"translation_post": "Doe11111",
|
||||
"link": "simple mortal111",
|
||||
"tag": "",
|
||||
"is_active": False,
|
||||
"created_at": "07/20/22 02: 26: 54",
|
||||
"specialist": "",
|
||||
"summary": "",
|
||||
"data": [
|
||||
{
|
||||
"name": "abc1",
|
||||
"tag": [""],
|
||||
"is_active": False,
|
||||
"specialist": "",
|
||||
"summary": "",
|
||||
"data": [
|
||||
{
|
||||
"name": "abc1",
|
||||
"level": ["ORG_USER", "ORG_DICTIONARY"],
|
||||
"content": "aab"
|
||||
},
|
||||
{
|
||||
"name": "abc2",
|
||||
},
|
||||
{
|
||||
"name": "abc2",
|
||||
"level": ["ORG_USER", "ORG_DICTIONARY"],
|
||||
"content": "aab"
|
||||
},
|
||||
{
|
||||
"name": "abc",
|
||||
},
|
||||
{
|
||||
"name": "abc",
|
||||
"level": ["ORG_USER", "ORG_DICTIONARY"],
|
||||
"content": "aab"
|
||||
},
|
||||
{
|
||||
"name": "abc3",
|
||||
},
|
||||
{
|
||||
"name": "abc3",
|
||||
"level": ["ORG_USER"],
|
||||
"content": "aab"
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"point": {
|
||||
"less10": 0,
|
||||
"form10to20": 0,
|
||||
"form20to30": 0,
|
||||
"form30to40": 0,
|
||||
"form40to50": 0,
|
||||
"form50to60": 0,
|
||||
"bigger60": 0,
|
||||
"total": 0
|
||||
}
|
||||
"less10": 0,
|
||||
"form10to20": 0,
|
||||
"form20to30": 0,
|
||||
"form30to40": 0,
|
||||
"form40to50": 0,
|
||||
"form50to60": 0,
|
||||
"bigger60": 0,
|
||||
"total": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,42 +135,42 @@ class UpdatePostModel(BaseModel):
|
||||
"original_post": "Joh111",
|
||||
"translation_post": "Doe11111",
|
||||
"link": "simple mortal111",
|
||||
"tag": "",
|
||||
"is_active": False,
|
||||
"specialist": "",
|
||||
"summary": "",
|
||||
"data": [
|
||||
{
|
||||
"name": "abc1",
|
||||
"tag": [""],
|
||||
"is_active": False,
|
||||
"specialist": "",
|
||||
"summary": "",
|
||||
"data": [
|
||||
{
|
||||
"name": "abc1",
|
||||
"level": ["ORG_USER", "ORG_DICTIONARY"],
|
||||
"content": "aab"
|
||||
},
|
||||
{
|
||||
"name": "abc2",
|
||||
},
|
||||
{
|
||||
"name": "abc2",
|
||||
"level": ["ORG_USER", "ORG_DICTIONARY"],
|
||||
"content": "aab"
|
||||
},
|
||||
{
|
||||
"name": "abc",
|
||||
},
|
||||
{
|
||||
"name": "abc",
|
||||
"level": ["ORG_USER", "ORG_DICTIONARY"],
|
||||
"content": "aab"
|
||||
},
|
||||
{
|
||||
"name": "abc3",
|
||||
},
|
||||
{
|
||||
"name": "abc3",
|
||||
"level": ["ORG_USER"],
|
||||
"content": "aab"
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"point": {
|
||||
"less10": 0,
|
||||
"form10to20": 0,
|
||||
"form20to30": 0,
|
||||
"form30to40": 0,
|
||||
"form40to50": 0,
|
||||
"form50to60": 0,
|
||||
"bigger60": 0,
|
||||
"total": 0
|
||||
}
|
||||
"less10": 0,
|
||||
"form10to20": 0,
|
||||
"form20to30": 0,
|
||||
"form30to40": 0,
|
||||
"form40to50": 0,
|
||||
"form50to60": 0,
|
||||
"bigger60": 0,
|
||||
"total": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ from bson.objectid import ObjectId
|
||||
import re
|
||||
import pytz
|
||||
import datetime
|
||||
from ..models.models import *
|
||||
tz = pytz.timezone('Asia/Ho_Chi_Minh')
|
||||
history = APIRouter()
|
||||
##############################POST###############################################
|
||||
@@ -46,7 +47,6 @@ async def create_history(username: str, status: str, note: str, history: History
|
||||
history["user_name"] = username
|
||||
history["status"] = status
|
||||
history["note"] = note
|
||||
print(history)
|
||||
history_new = await db["history"].insert_one(history)
|
||||
create_history = await db["history"].find_one({"_id": history_new.inserted_id})
|
||||
create_history = jsonable_encoder(create_history)
|
||||
@@ -58,45 +58,53 @@ async def create_history(username: str, status: str, note: str, history: History
|
||||
"/list_history", response_description="List all posts", response_model=List[HistoryByUserModel]
|
||||
)
|
||||
async def list_post():
|
||||
history_find = await db["history"].find().to_list(1000)
|
||||
history_find = await db["history"].find().to_list(20)
|
||||
return history_find
|
||||
|
||||
|
||||
@history.get("/user_history", response_description="Get list history", response_model=List[HistoryByUserModel])
|
||||
async def get_list_post_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"})
|
||||
history_find = await db["history"].find({"user_name": user_name}).to_list(100)
|
||||
output = []
|
||||
for dt in history_find:
|
||||
if dt.get("note", None) != '':
|
||||
post = await db["posts"].find_one({"_id": dt.get("note", None)})
|
||||
input = []
|
||||
if post == None:
|
||||
dt["data"] = "bài viết đã bị xóa"
|
||||
else:
|
||||
dt["data"] = post["translation_post"]
|
||||
output.append(dt)
|
||||
return output
|
||||
async def get_list_post_view_by_username(token: token_test = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
history_find = await db["history"].find({"user_name": user_name}).to_list(20)
|
||||
output = []
|
||||
for dt in history_find:
|
||||
if dt.get("note", None) != '':
|
||||
post = await db["posts"].find_one({"_id": dt.get("note", None)})
|
||||
input = []
|
||||
if post == None:
|
||||
dt["data"] = "bài viết đã bị xóa"
|
||||
else:
|
||||
dt["data"] = post["translation_post"]
|
||||
output.append(dt)
|
||||
return output
|
||||
except NameError:
|
||||
return NameError
|
||||
|
||||
|
||||
@history.get("/user_history_key_find", response_description="Get list history key find", response_model=List[HistoryByUserModel])
|
||||
async def get_key_find_view_by_username(token: str = None):
|
||||
if token != None:
|
||||
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"})
|
||||
async def get_key_find_view_by_username(token: token_test = Depends(get_current_user),
|
||||
):
|
||||
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name != None:
|
||||
history_find = await db["history"].find({"user_name": user_name, "status": "Tìm kiếm bài viết theo từ khóa"}).sort("created_at", -1).to_list(1000)
|
||||
all_user = []
|
||||
out_data = []
|
||||
i = 0
|
||||
if history_find == []:
|
||||
return history_find
|
||||
print(history_find[0])
|
||||
|
||||
all_user.append(history_find[0])
|
||||
out_data.append(history_find[0]["data"])
|
||||
for dt in history_find:
|
||||
@@ -128,27 +136,30 @@ async def get_key_find_view_by_username(token: str = None):
|
||||
|
||||
|
||||
@history.delete("/delete_user_history/{id}", response_description="Delete history by user")
|
||||
async def delete_user(id: str,
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
token: str,
|
||||
):
|
||||
data_token = await get_current_user(token)
|
||||
user_name = data_token.get("user_name", None)
|
||||
user_type = data_token.get("user_type", None)
|
||||
print(ObjectId(id))
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
delete_result = await db["history"].delete_one({"_id": ObjectId(id)})
|
||||
delete = await db["history"].delete_one({"_id": id})
|
||||
print(delete.deleted_count)
|
||||
if delete_result.deleted_count == 1:
|
||||
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content={"message": "Delete successfull"})
|
||||
elif delete.deleted_count == 1:
|
||||
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content={"message": "Delete successfull"})
|
||||
raise HTTPException(status_code=404, detail=f"History not found")
|
||||
async def delete_user_history(id: str,
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
token: token_test = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
delete = await db["history"].delete_one({"_id": id})
|
||||
delete_result = await db["history"].delete_one({"_id": ObjectId(id)})
|
||||
if delete_result.deleted_count == 1:
|
||||
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content={})
|
||||
elif delete.deleted_count == 1:
|
||||
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content={})
|
||||
raise HTTPException(status_code=404, detail=f"History not found")
|
||||
except NameError:
|
||||
return NameError
|
||||
|
||||
|
||||
@history.get("/statistics_key_find", response_description="Get list history key find", response_model=List[HistoryByUserModel])
|
||||
@ history.get("/statistics_key_find", response_description="Get list history key find", response_model=List[HistoryByUserModel])
|
||||
async def statistics_view_by_username():
|
||||
history_find = await db["history"].find({"status": "Tìm kiếm bài viết theo từ khóa"}).sort("count", -1).to_list(1000)
|
||||
all_user = []
|
||||
@@ -168,10 +179,9 @@ async def statistics_view_by_username():
|
||||
return all_user
|
||||
|
||||
|
||||
@history.post("/create_khoa", response_description="history", response_model=StatisticalSpecialistModel)
|
||||
@ history.post("/create_khoa", response_description="history", response_model=StatisticalSpecialistModel)
|
||||
async def create_history(token: str, ss: StatisticalSpecialistModel = None):
|
||||
ss = jsonable_encoder(ss)
|
||||
print(ss)
|
||||
StatisticalSpecialist_new = await db["StatisticalSpecialist"].insert_one(ss)
|
||||
create_ss = await db["StatisticalSpecialist"].find_one({"_id": StatisticalSpecialist_new.inserted_id})
|
||||
create_ss = jsonable_encoder(create_ss)
|
||||
@@ -179,18 +189,17 @@ async def create_history(token: str, ss: StatisticalSpecialistModel = None):
|
||||
return create_ss
|
||||
|
||||
|
||||
@history.post("/auto_create_khoa", response_description="history", response_model=List[StatisticalSpecialistModel])
|
||||
@ history.post("/auto_create_khoa", response_description="history", response_model=List[StatisticalSpecialistModel])
|
||||
async def create_history():
|
||||
data = []
|
||||
for i in KHOA:
|
||||
print(i)
|
||||
StatisticalSpecialist_new = await db["StatisticalSpecialist"].insert_one(i)
|
||||
create_ss = await db["StatisticalSpecialist"].find_one({"_id": StatisticalSpecialist_new.inserted_id})
|
||||
data.append(create_ss)
|
||||
return JSONResponse(status_code=status.HTTP_201_CREATED, content=data)
|
||||
|
||||
|
||||
@history.get(
|
||||
@ history.get(
|
||||
"/statistical_specialist", response_description="Statistical Specialist", response_model=List[StatisticalSpecialistModel]
|
||||
)
|
||||
async def list_post():
|
||||
@@ -198,8 +207,8 @@ async def list_post():
|
||||
return StatisticalSpecialist
|
||||
|
||||
|
||||
@history.delete("/statistical_specialist111"
|
||||
)
|
||||
@ history.delete("/statistical_specialist111"
|
||||
)
|
||||
async def delete():
|
||||
StatisticalSpecialist = await db["StatisticalSpecialist"].delete_many({})
|
||||
return StatisticalSpecialist.deleted_count
|
||||
|
||||
@@ -63,7 +63,6 @@ async def get_list_post_view_by_username(username: str, current_user: ShowUserMo
|
||||
# history_find = await db["history_find"].find({"username": username}).to_list(10)
|
||||
# post_view = []
|
||||
# for dt in history_find:
|
||||
# print(dt["post_id"])
|
||||
# post = await db["posts"].find_one({"_id": dt["post_id"]})
|
||||
# post_view.append(post)
|
||||
# return post_view
|
||||
@@ -74,7 +73,6 @@ async def get_list_post_view_by_username(current_user: ShowUserModel = Depends(g
|
||||
history_find = await db["history_find"].find({"username": current_user["username"]}).to_list(10)
|
||||
post_view = []
|
||||
for dt in history_find:
|
||||
print(dt["post_id"])
|
||||
post = await db["posts"].find_one({"_id": dt["post_id"]})
|
||||
dt["post"] = post
|
||||
return history_find
|
||||
|
||||
@@ -56,18 +56,20 @@ async def post_html(content: str, request: Request):
|
||||
|
||||
|
||||
@post.post("/create_post", response_description="Add new post", response_model=PostModel)
|
||||
async def create_post(post: PostModel,
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
# token: TokenModel
|
||||
token: str
|
||||
):
|
||||
async def create_post(
|
||||
post: PostModel,
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
# token: TokenModel
|
||||
token: token_test = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
# print(post)
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# 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"})
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
|
||||
# post.created_at = datetime.datetime.now(tz=tz)
|
||||
post = jsonable_encoder(post)
|
||||
@@ -107,7 +109,6 @@ async def create_post(post: PostModel,
|
||||
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
|
||||
@@ -121,7 +122,6 @@ async def create_post(post: PostModel,
|
||||
del history_user["data"]
|
||||
del history_user["summary"]
|
||||
history_user["data"] = "post name"
|
||||
print(history_user)
|
||||
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)
|
||||
@@ -133,38 +133,28 @@ async def create_post(post: PostModel,
|
||||
"/list_post", response_description="List all posts"
|
||||
)
|
||||
async def list_post(
|
||||
token: TokenModel = None,
|
||||
token: token_test = Depends(get_current_user),
|
||||
is_active: bool = True,
|
||||
page: int = 0,
|
||||
limit: int = 10,
|
||||
):
|
||||
posts = await db["posts"].find().sort("created_at", -1).sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
count_total = await db["posts"].count_documents({})
|
||||
|
||||
# print(count)
|
||||
if is_active == True:
|
||||
posts = await db["posts"].find({"is_active": is_active}).sort("created_at", -1).sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
count_total = await db["posts"].count_documents({"is_active": is_active})
|
||||
else:
|
||||
posts = await db["posts"].find().sort("created_at", -1).sort("is_active", -1).sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
count_total = await db["posts"].count_documents({})
|
||||
output = []
|
||||
|
||||
if token.token != None:
|
||||
user_name = token.get("user_name", None)
|
||||
if token != None:
|
||||
posts = jsonable_encoder(posts)
|
||||
for post in posts:
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
|
||||
payload = {'token': token.token}
|
||||
|
||||
headers = {
|
||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||
}
|
||||
|
||||
response = requests.request(
|
||||
"POST", url, headers=headers, data=payload)
|
||||
data_token = json.loads(response.text)
|
||||
|
||||
data = data_token.get("user_name", None)
|
||||
user_type = data_token.get("user_type", None)
|
||||
if data == None:
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
post = jsonable_encoder(post)
|
||||
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": data})
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": user_name})
|
||||
if count != 0:
|
||||
post["post_save"] = True
|
||||
else:
|
||||
@@ -184,7 +174,14 @@ async def list_post(
|
||||
@post.post(
|
||||
"/find_list_post", response_description="search list posts"
|
||||
)
|
||||
async def find_list_post(page: int = 0, limit: int = 10, key_find: str = None, token: str = None, history: HistoryFindModel = None):
|
||||
async def find_list_post(
|
||||
page: int = 0,
|
||||
limit: int = 10,
|
||||
key_find: str = None,
|
||||
history: HistoryFindModel = None,
|
||||
token: token_test = Depends(get_current_user),
|
||||
):
|
||||
user_name = token.get("user_name", None)
|
||||
# point_data = ["point.less10",
|
||||
# "point.form10to20",
|
||||
# "point.form20to30",
|
||||
@@ -205,33 +202,44 @@ async def find_list_post(page: int = 0, limit: int = 10, key_find: str = None, t
|
||||
|
||||
# ]).sort(age_sort, -1).to_list(100)
|
||||
|
||||
posts = await db["posts"].find({
|
||||
"$or": [
|
||||
{"translation_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"data.content": {"$regex": key_find, "$options": 'i'}},
|
||||
{"original_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"summary": {"$regex": key_find, "$options": 'i'}},
|
||||
{"tag": {"$regex": key_find, "$options": 'xi'}},
|
||||
]
|
||||
}).sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
count_total = await db["posts"].count_documents({
|
||||
"$or": [
|
||||
{"translation_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"data.content": {"$regex": key_find, "$options": 'i'}},
|
||||
{"original_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"summary": {"$regex": key_find, "$options": 'i'}},
|
||||
{"tag": {"$regex": key_find, "$options": 'xi'}},
|
||||
]
|
||||
})
|
||||
posts = await db["posts"].find(
|
||||
{"$and":
|
||||
[
|
||||
{
|
||||
"$or": [
|
||||
{"translation_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"data.content": {"$regex": key_find, "$options": 'i'}},
|
||||
{"original_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"summary": {"$regex": key_find, "$options": 'i'}},
|
||||
{"tag": {"$regex": key_find, "$options": 'xi'}},
|
||||
]
|
||||
},
|
||||
{"is_active": True}
|
||||
]
|
||||
}
|
||||
).sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
count_total = await db["posts"].count_documents(
|
||||
{"$and":
|
||||
[
|
||||
{
|
||||
"$or": [
|
||||
{"translation_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"data.content": {"$regex": key_find, "$options": 'i'}},
|
||||
{"original_post": {"$regex": key_find, "$options": 'i'}},
|
||||
{"summary": {"$regex": key_find, "$options": 'i'}},
|
||||
{"tag": {"$regex": key_find, "$options": 'xi'}},
|
||||
]
|
||||
},
|
||||
{"is_active": True}
|
||||
]
|
||||
}
|
||||
)
|
||||
output = []
|
||||
# history.created_at = datetime.datetime.now(tz=tz)
|
||||
if token != None:
|
||||
data_token = await get_current_user(token)
|
||||
data = data_token.get("user_name", None)
|
||||
user_type = data_token.get("user_type", None)
|
||||
if user_name != None:
|
||||
history = jsonable_encoder(history)
|
||||
history_user = history
|
||||
history_user["user_name"] = data
|
||||
history_user["user_name"] = user_name
|
||||
history_user["status"] = "Tìm kiếm bài viết theo từ khóa"
|
||||
history_user["note"] = ""
|
||||
history_user["data"] = key_find
|
||||
@@ -244,14 +252,13 @@ async def find_list_post(page: int = 0, limit: int = 10, key_find: str = None, t
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
print(history_user)
|
||||
history_new = await db["history"].insert_one(history_user)
|
||||
for post in posts:
|
||||
if data == None:
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
post = jsonable_encoder(post)
|
||||
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": data})
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": user_name})
|
||||
if count != 0:
|
||||
post["post_save"] = True
|
||||
else:
|
||||
@@ -277,7 +284,6 @@ async def find_list_post(page: int = 0, limit: int = 10, key_find: str = None, t
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
print(history_user)
|
||||
history_new = await db["history"].insert_one(history_user)
|
||||
return {
|
||||
"total": count_total,
|
||||
@@ -339,7 +345,6 @@ async def find_list_post(key_find: str, token: str = None, history: HistoryFindM
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
print(history_user)
|
||||
history_new = await db["history"].insert_one(history_user)
|
||||
for post in posts:
|
||||
if data == None:
|
||||
@@ -369,7 +374,6 @@ async def find_list_post(key_find: str, token: str = None, history: HistoryFindM
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
print(history_user)
|
||||
history_new = await db["history"].insert_one(history_user)
|
||||
return posts
|
||||
|
||||
@@ -378,20 +382,20 @@ async def find_list_post(key_find: str, token: str = None, history: HistoryFindM
|
||||
"/get_post_by_name"
|
||||
# , response_description="Get a single post", response_model=PostModel
|
||||
)
|
||||
async def get_post_by_name(history: HistoryFindModel):
|
||||
async def get_post_by_name(history: HistoryFindModel = None, access: token_test = Depends(get_current_user),):
|
||||
try:
|
||||
# history.created_at = datetime.datetime.now(tz=tz)
|
||||
|
||||
user_name = access.get("user_name", None)
|
||||
history = jsonable_encoder(history)
|
||||
token = history.get("token", None)
|
||||
if token == '':
|
||||
if user_name == None:
|
||||
post = await db["posts"].find_one({"_id": history["post_id"]})
|
||||
for dt in post["data"]:
|
||||
if not ROLE_PUBLIC in dt["level"]:
|
||||
if dt["level"] != ["*"]:
|
||||
post["data"].remove(dt)
|
||||
history_find = jsonable_encoder(history)
|
||||
history = jsonable_encoder(history)
|
||||
check_data = await db["history"].find({"post_id": post["_id"], "username": data, "status": "xem bài viết"}).sort("created_at", -1).to_list(1)
|
||||
# history = jsonable_encoder(history)
|
||||
check_data = await db["history"].find({"post_id": post["_id"], "username": user_name, "status": "xem bài viết"}).sort("created_at", -1).to_list(1)
|
||||
if check_data != []:
|
||||
history_user["count"] = int(check_data[0]["count"]) + 1
|
||||
else:
|
||||
@@ -420,9 +424,8 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
content={'message': "Bài viết không tồn tại"}
|
||||
)
|
||||
data_token = await get_current_user(token)
|
||||
data = data_token.get("user_name", None)
|
||||
user_type = data_token.get("user_type", None)
|
||||
|
||||
user_type = access.get("user_type", None)
|
||||
if "ADMIN" == user_type:
|
||||
user_type = "ORG_ADMIN"
|
||||
if "PATIENT" == user_type:
|
||||
@@ -431,7 +434,7 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
user_type = "ORG_OPERATOR"
|
||||
if "RECEIPTION" == user_type:
|
||||
user_type = "SITE_RECEIPTION"
|
||||
if data == None:
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
else:
|
||||
post = await db["posts"].find_one({"_id": history["post_id"]})
|
||||
@@ -441,7 +444,7 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
if not user_type in dt["level"]:
|
||||
post["data"].remove(dt)
|
||||
history_find = jsonable_encoder(history)
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": data})
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": user_name})
|
||||
if count != 0:
|
||||
post["post_save"] = True
|
||||
else:
|
||||
@@ -449,7 +452,7 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
new_his = await db["history_find"].insert_one(history_find)
|
||||
created = await db["history_find"].find_one({"_id": new_his.inserted_id})
|
||||
history_user = history_find
|
||||
history_user["user_name"] = data
|
||||
history_user["user_name"] = user_name
|
||||
history_user["status"] = "xem bài viết"
|
||||
history_user["note"] = history_user["post_id"]
|
||||
history_user["data"] = "post name"
|
||||
@@ -457,7 +460,7 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
check_data = await db["history"].find({"post_id": post["_id"], "username": data, "status": "xem bài viết"}).sort("created_at", -1).to_list(1)
|
||||
check_data = await db["history"].find({"post_id": post["_id"], "username": user_name, "status": "xem bài viết"}).sort("created_at", -1).to_list(1)
|
||||
if check_data != []:
|
||||
history_user["count"] = int(check_data[0]["count"]) + 1
|
||||
else:
|
||||
@@ -472,6 +475,7 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
content={'message': "Bài viết không tồn tại"}
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
content={'message': str(e)}
|
||||
@@ -481,9 +485,11 @@ async def get_post_by_name(history: HistoryFindModel):
|
||||
@post.post(
|
||||
"/get_post_edit"
|
||||
)
|
||||
async def get_post_edit(history: HistoryFindModel):
|
||||
async def get_post_edit(history: HistoryFindModel, token: token_test = Depends(get_current_user),):
|
||||
try:
|
||||
# history.created_at = datetime.datetime.now(tz=tz)
|
||||
user_name = token.get("user_name", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
history = jsonable_encoder(history)
|
||||
post = await db["posts"].find_one({"_id": history["post_id"]})
|
||||
new_his = await db["history_find"].insert_one(history)
|
||||
@@ -505,41 +511,39 @@ async def get_post_edit(history: HistoryFindModel):
|
||||
@post.delete("/delete_post/{id}", response_description="Delete a post")
|
||||
async def delete_user(id: str,
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
token: str,
|
||||
post: UpdatePostModel = None
|
||||
):
|
||||
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:
|
||||
token: token_test = Depends(get_current_user),):
|
||||
|
||||
# post.updated_at = datetime.datetime.now(tz=tz)
|
||||
user_name = token.get("user_name", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
delete_result = await db["posts"].delete_one({"_id": id})
|
||||
if delete_result.deleted_count == 1:
|
||||
post = jsonable_encoder(post)
|
||||
print(data)
|
||||
# post = jsonable_encoder(post)
|
||||
delete_post_save = await db["post_save"].delete_many({"post_id": id})
|
||||
history_user = {}
|
||||
history_user["user_name"] = data
|
||||
history_user["user_name"] = user_name
|
||||
history_user["status"] = "xóa bài viết"
|
||||
history_user["note"] = id
|
||||
history_user["data"] = "post name"
|
||||
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"})
|
||||
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content=True)
|
||||
raise HTTPException(status_code=404, detail=f"Post {id} not found")
|
||||
|
||||
|
||||
@post.get("/score", response_description="score all post", response_model=List[ShowPostModel])
|
||||
async def score_all_post(
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
token: token_test = Depends(get_current_user),
|
||||
):
|
||||
|
||||
user_name = token.get("user_name", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
posts = await db["posts"].find().to_list(1000)
|
||||
print(post)
|
||||
for dt_post in posts:
|
||||
data_old = dt_post
|
||||
dt_post["point"]["total"] = await db["history_find"].count_documents({"post_id": dt_post["_id"]})
|
||||
# await db["posts"].update_one(data_old, dt_post)
|
||||
await db["posts"].update_one({"_id": dt_post["_id"]}, {"$set": {
|
||||
"point": {
|
||||
|
||||
@@ -550,15 +554,7 @@ async def score_all_post(
|
||||
return posts
|
||||
|
||||
|
||||
# @post.post("/uploadfiles/")
|
||||
# async def create_upload_files(
|
||||
# files: List[UploadFile] = File(...),
|
||||
# # current_user: UserModel = Depends(get_current_user)
|
||||
# ):
|
||||
# try:
|
||||
# file_name = []
|
||||
# i = 0
|
||||
# file_location = f"../media/"
|
||||
# @post.post("/uploadfiles/")data
|
||||
# for file in files:
|
||||
# current_time = datetime.datetime.now(tz=tz)
|
||||
# file_save = file_location + current_time + str(i) + file.filename
|
||||
@@ -657,24 +653,20 @@ async def create_upload_post(
|
||||
|
||||
|
||||
@post.post("/edit_post/{id}", response_description="score all post")
|
||||
async def edit_post(id: str, post: UpdatePostModel, token: str):
|
||||
async def edit_post(id: str, post: UpdatePostModel, token: token_test = Depends(get_current_user),):
|
||||
try:
|
||||
# post.updated_at = datetime.datetime.now(tz=tz)
|
||||
user_name = token.get("user_name", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
post = jsonable_encoder(post)
|
||||
created_post = await db["posts"].find_one({"_id": id})
|
||||
post["created_at"] = created_post["created_at"]
|
||||
await db["posts"].update_one({"_id": id}, {"$set":
|
||||
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["user_name"] = user_name
|
||||
history_user["status"] = "sửa bài viết"
|
||||
history_user["note"] = id
|
||||
history_user["created_at"] = history_user["updated_at"]
|
||||
@@ -687,11 +679,9 @@ async def edit_post(id: str, post: UpdatePostModel, token: str):
|
||||
del history_user["specialist"]
|
||||
del history_user["data"]
|
||||
del history_user["summary"]
|
||||
print(history_user)
|
||||
del history_user["point"]
|
||||
history_user["data"] = "post_name"
|
||||
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:
|
||||
@@ -757,7 +747,6 @@ async def find_list_post(status: str = None, specialist: str = None, key_find: s
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
print(history_user)
|
||||
history_new = await db["history"].insert_one(history_user)
|
||||
for post in posts:
|
||||
if data == None:
|
||||
@@ -795,7 +784,7 @@ async def find_list_post(status: str = None, specialist: str = None, key_find: s
|
||||
"/find_post_save", response_description="search list posts save"
|
||||
)
|
||||
async def find_post_save(
|
||||
token: str,
|
||||
token: token_test = Depends(get_current_user),
|
||||
page: int = 0,
|
||||
limit: int = 10,
|
||||
# key_find: str = None,
|
||||
@@ -809,6 +798,7 @@ async def find_post_save(
|
||||
# "point.form50to60",
|
||||
# ]
|
||||
age_sort = "point.total"
|
||||
print(11111)
|
||||
# history = jsonable_encoder(history)
|
||||
# if history.get("age", None) != None:
|
||||
# if history.get("age") > 59:
|
||||
@@ -818,7 +808,6 @@ async def find_post_save(
|
||||
# posts = await db["posts"].find("$or": [
|
||||
# {"translation_post": {"$regex": key_find}},
|
||||
# {"translation_post": {"$regex": key_find}},
|
||||
# print(key_find)
|
||||
# # ]).sort(age_sort, -1).to_list(100)
|
||||
# if key_find != None:
|
||||
# posts = await db["posts"].find({
|
||||
@@ -831,21 +820,21 @@ async def find_post_save(
|
||||
# ]
|
||||
# }).sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
# else:
|
||||
posts = await db["posts"].find().sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
count_total = 0
|
||||
# posts = await db["posts"].find().sort("point.total", -1).skip(page*limit).to_list(limit)
|
||||
|
||||
output = []
|
||||
# history.created_at = datetime.datetime.now(tz=tz)
|
||||
if token != None:
|
||||
data_token = await get_current_user(token)
|
||||
data = data_token.get("user_name", None)
|
||||
user_type = data_token.get("user_type", None)
|
||||
user_name = token.get("user_name", None)
|
||||
if user_name != None:
|
||||
posts_save = await db["post_save"].find({"username": user_name}).skip(page*limit).to_list(limit)
|
||||
count_total = await db["post_save"].count_documents({"username": user_name})
|
||||
history = jsonable_encoder(history)
|
||||
history_user = history
|
||||
history_user["user_name"] = data
|
||||
history_user["user_name"] = user_name
|
||||
history_user["status"] = "Xem danh sách bài viết đã lưu"
|
||||
history_user["note"] = ""
|
||||
history_user["data"] = ""
|
||||
check_data = await db["history"].find({"user_name": data, "status": "Xem danh sách bài viết đã lưu"}).sort("created_at", -1).to_list(1)
|
||||
check_data = await db["history"].find({"user_name": user_name, "status": "Xem danh sách bài viết đã lưu"}).sort("created_at", -1).to_list(1)
|
||||
if check_data != []:
|
||||
history_user["count"] = int(check_data[0]["count"]) + 1
|
||||
else:
|
||||
@@ -854,20 +843,19 @@ async def find_post_save(
|
||||
del history_user["token"]
|
||||
del history_user["sick"]
|
||||
del history_user["authorities"]
|
||||
print(history_user)
|
||||
history_new = await db["history"].insert_one(history_user)
|
||||
|
||||
for post in posts:
|
||||
if data == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
for post in posts_save:
|
||||
post = jsonable_encoder(post)
|
||||
|
||||
count = await db["post_save"].count_documents({"post_id": post["_id"], "username": data})
|
||||
if count != 0:
|
||||
post["post_save"] = True
|
||||
output.append(post)
|
||||
count_total = count_total + 1
|
||||
count = await db["posts"].find_one({"_id": post["post_id"]})
|
||||
if count == None:
|
||||
print(post["post_id"])
|
||||
count["post_save"] = True
|
||||
output.append(count)
|
||||
print(output)
|
||||
return {
|
||||
"total": count_total,
|
||||
"data": output,
|
||||
}
|
||||
else:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
|
||||
@@ -27,7 +27,7 @@ from ..settings import *
|
||||
import json
|
||||
from typing import List
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from ..models.models import *
|
||||
import requests
|
||||
import re
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -41,27 +41,25 @@ post_save = APIRouter()
|
||||
|
||||
|
||||
@post_save.post("/save_post", response_description="save new post", response_model=SavePostModel)
|
||||
async def create_post(post_save: SavePost):
|
||||
async def create_post(post_save: SavePost, token: token_test = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
payload = {'token': post_save.token}
|
||||
headers = {
|
||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||
}
|
||||
response = requests.request(
|
||||
"POST", url, headers=headers, data=payload)
|
||||
data_output = json.loads(response.text)
|
||||
data = data_output.get("user_name", None)
|
||||
if data == None:
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
count = await db["posts"].count_documents({"_id": post_save.post_id})
|
||||
if count == 0:
|
||||
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 = jsonable_encoder(post_save)
|
||||
del post_save["token"]
|
||||
post_save["username"] = data
|
||||
created_post = await db["post_save"].count_documents({"post_id": post_save["post_id"], "username": data})
|
||||
post_save["username"] = user_name
|
||||
created_post = await db["post_save"].count_documents({"post_id": post_save["post_id"], "username": user_name})
|
||||
if created_post == 1:
|
||||
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)
|
||||
@@ -74,38 +72,34 @@ async def create_post(post_save: SavePost):
|
||||
@post_save.post(
|
||||
"/list_save_post_by_user", response_description="List save posts", response_model=SavePostModel
|
||||
)
|
||||
async def list_post(post_save: SavePost):
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
payload = {'token': post_save.token}
|
||||
headers = {
|
||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||
}
|
||||
response = requests.request(
|
||||
"POST", url, headers=headers, data=payload)
|
||||
data_output = json.loads(response.text)
|
||||
data = data_output.get("user_name", None)
|
||||
if data == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
posts = await db["post_save"].find({"username": data}).to_list(1000)
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content=posts)
|
||||
async def list_post(post_save: SavePost, token: token_test = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
posts = await db["post_save"].find({"username": user_name}).to_list(20)
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content=posts)
|
||||
except NameError:
|
||||
return NameError
|
||||
|
||||
|
||||
@post_save.delete("/delete_save_post", response_description="Delete save post")
|
||||
async def delete_save_post(post_id: str, token: str):
|
||||
# delete_result = await db["post_save"].delete_one({"_id": user_id})
|
||||
async def delete_save_post(post_id: str, token: token_test = Depends(get_current_user),
|
||||
):
|
||||
try:
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
payload = {'token': token}
|
||||
headers = {
|
||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||
}
|
||||
response = requests.request(
|
||||
"POST", url, headers=headers, data=payload)
|
||||
data_output = json.loads(response.text)
|
||||
data = data_output.get("user_name", None)
|
||||
if data == None:
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name == None:
|
||||
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})
|
||||
delete_result = await db["post_save"].delete_one({"post_id": post_id, "username": user_name})
|
||||
if delete_result.deleted_count == 1:
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": "Delete post save successful"})
|
||||
raise HTTPException(
|
||||
|
||||
@@ -89,8 +89,10 @@ async def login_for_access_token(body: LoginRequest):
|
||||
"POST", url, headers=headers, data=payload, files=files)
|
||||
|
||||
access_token = json.loads(response.text)
|
||||
|
||||
print(access_token)
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
if access_token.get("access_token", None) == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
payload = {'token': access_token["access_token"]}
|
||||
headers = {
|
||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||
@@ -162,23 +164,17 @@ async def login_for_access_token_2(body: OAuth2PasswordRequestForm = Depends()):
|
||||
|
||||
|
||||
@router.post("/current", response_description="Current User")
|
||||
async def current_user(token: TokenModel):
|
||||
try:
|
||||
url = URL_OAUTH2_GET_CHECK_TOKEN
|
||||
payload = {'token': token.token}
|
||||
headers = {
|
||||
'Authorization': 'Basic RGljdGlvbmFyeU1lZGlob21lOlJ4aXR6ZnZvaWFmZmNtb2l0ZW0='
|
||||
}
|
||||
response = requests.request(
|
||||
"POST", url, headers=headers, data=payload)
|
||||
data_output = json.loads(response.text)
|
||||
data = data_output.get("user_name", None)
|
||||
if data == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
else:
|
||||
return json.loads(response.text)
|
||||
except ValueError:
|
||||
pass
|
||||
async def current_user(token: token_test = Depends(get_current_user),
|
||||
):
|
||||
user_name = token.get("user_name", None)
|
||||
|
||||
# data_token = await get_current_user(Nonetoken)
|
||||
# data = data_token.get("user_name", None)
|
||||
# user_type = data_token.get("user_type", None)
|
||||
if user_name == None:
|
||||
return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content={"message": "UNAUTHORIZED"})
|
||||
else:
|
||||
return token
|
||||
|
||||
|
||||
# @router.get("/current", response_description="Current User", response_model=ShowUserModel)
|
||||
|
||||
@@ -21,6 +21,7 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
URL_SERVER = os.getenv('URL_SERVER')
|
||||
URL_OAUTH2_GET_CHECK_TOKEN = os.getenv("URL_OAUTH2_GET_CHECK_TOKEN")
|
||||
URL_OAUTH2_GET_TOKEN = os.getenv("URL_OAUTH2_GET_TOKEN")
|
||||
SWAGGER = os.getenv("URL_SWAGGER")
|
||||
|
||||
|
||||
class DateTimeEncoder(JSONEncoder):
|
||||
@@ -360,4 +361,4 @@ KHOA = [
|
||||
]
|
||||
# ----------------- Database variables (MongoDB) --------------------------
|
||||
client = motor.motor_asyncio.AsyncIOMotorClient(os.environ["DB_URL"])
|
||||
db = client.myTestDB
|
||||
db = client.mdDB
|
||||
|
||||
Reference in New Issue
Block a user