Skip to content

Commit

Permalink
Merge pull request #99 from whyphi/feat/family-tree
Browse files Browse the repository at this point in the history
feat: implement family tree get filter api
  • Loading branch information
jinyoungbang authored Aug 4, 2024
2 parents 7c67795 + 3271fe4 commit 47f62a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chalicelib/api/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ def delete_members():
def update_member_roles(user_id):
data = members_api.current_request.json_body
return member_service.update_roles(user_id, data["roles"])


@members_api.route("/members/family-tree", methods=["GET"], cors=True)
@auth(members_api, roles=[Roles.MEMBER])
def get_family_tree():
return member_service.get_family_tree()
15 changes: 15 additions & 0 deletions chalicelib/services/MemberService.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from chalice import ConflictError, NotFoundError, UnauthorizedError

from bson import ObjectId
from collections import defaultdict
import json
import jwt
import boto3
Expand Down Expand Up @@ -118,5 +119,19 @@ def update_roles(self, document_id=str, roles=list) -> bool:
[{"$set": {"roles": roles}}],
)

def get_family_tree(self):
data = mongo_module.get_data_from_collection(self.collection)

# Group by family
family_groups = defaultdict(list)

for member in data:
if "big" not in member or member["big"] == "":
continue
member["_id"] = str(member["_id"])
family_groups[member["family"]].append(member)

return family_groups


member_service = MemberService()

0 comments on commit 47f62a5

Please sign in to comment.