|
|
@ -1,7 +1,7 @@
|
|
|
|
from app.models.friend import Friend
|
|
|
|
from app.models.friend import Friend
|
|
|
|
|
|
|
|
|
|
|
|
def friend_serialize(friend: list) -> Friend:
|
|
|
|
def friend_serialize(friend: list) -> Friend:
|
|
|
|
status = friend['status'] if 'status' in friend else 'null'
|
|
|
|
status = friend['status'] if 'status' in friend else 'pending'
|
|
|
|
|
|
|
|
|
|
|
|
return Friend(**{
|
|
|
|
return Friend(**{
|
|
|
|
"id": str(friend["_id"]),
|
|
|
|
"id": str(friend["_id"]),
|
|
|
@ -17,23 +17,9 @@ def friends_serialize(friends: list, external_friends: list) -> dict:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for friend in friends:
|
|
|
|
for friend in friends:
|
|
|
|
status = friend['status'] if 'status' in friend else 'null'
|
|
|
|
serialized_friends["friends"].append(friend_serialize(friend))
|
|
|
|
|
|
|
|
|
|
|
|
serialized_friends["friends"].append(Friend(**{
|
|
|
|
|
|
|
|
"id": str(friend["_id"]),
|
|
|
|
|
|
|
|
"user_id": friend["user_id"],
|
|
|
|
|
|
|
|
"friend_user_id": friend["friend_user_id"],
|
|
|
|
|
|
|
|
"status": status
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for external_friend in external_friends:
|
|
|
|
for external_friend in external_friends:
|
|
|
|
status = external_friend['status'] if 'status' in external_friend else 'null'
|
|
|
|
serialized_friends["external_friends"].append(friend_serialize(external_friend))
|
|
|
|
|
|
|
|
|
|
|
|
serialized_friends["external_friends"].append(Friend(**{
|
|
|
|
|
|
|
|
"id": str(external_friend["_id"]),
|
|
|
|
|
|
|
|
"user_id": external_friend["user_id"],
|
|
|
|
|
|
|
|
"friend_user_id": external_friend["friend_user_id"],
|
|
|
|
|
|
|
|
"status": status
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return serialized_friends
|
|
|
|
return serialized_friends
|