You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
964 B
30 lines
964 B
from app.models.friend import Friend
|
|
|
|
|
|
def friends_serialize(friends: list, external_friends: list) -> dict:
|
|
serialized_friends: dict = {
|
|
'friends': [],
|
|
'external_friends': []
|
|
}
|
|
|
|
for friend in friends:
|
|
status = friend['status'] if 'status' in friend else 'null'
|
|
|
|
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:
|
|
status = external_friend['status'] if 'status' in external_friend else 'null'
|
|
|
|
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 |