Coverage for functions \ flipdare \ search \ factory \ group_member_search_factory.py: 97%
34 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
14from typing import Any, override
15from flipdare.core.tokenizer import Tokenizer
16from flipdare.firestore.context.group_context import GroupContext
17from flipdare.generated.shared.search.friend_document_type import FriendDocumentType
18from flipdare.generated.shared.search.search_obj_type import SearchObjType
19from flipdare.search.doc._search_document import SearchDocument
20from flipdare.search.doc.friend_document import FriendDocument
21from flipdare.search.factory._search_document_factory import SearchDocumentFactory
22from flipdare.util.time_util import TypesenseTime
24__all__ = ["GroupMemberSearchFactory"]
27class GroupMemberSearchFactory(SearchDocumentFactory):
29 def __init__(
30 self,
31 group_context: GroupContext,
32 index: int,
33 tokenizer: Tokenizer | None = None,
34 ) -> None:
35 self.group_context = group_context
36 self.index = index
38 super().__init__(tokenizer=tokenizer)
40 @property
41 @override
42 def obj_type(self) -> SearchObjType:
43 return SearchObjType.GROUP
45 @override
46 def get_documents(self) -> list[SearchDocument[Any]] | None:
47 # This is for friends only where
48 # obj_id = user.doc_id (group owner)
49 # friend_id = member.uid (group member)
50 # friend_values = user.safe_name (group owner)
51 # search_type = SearchType.GROUP
52 group_context = self.group_context
53 index = self.index
55 owner = group_context.owner
56 group = group_context.group
57 member = group_context[index]
58 if member is None:
59 raise ValueError(
60 f"GroupMemberModelTag could not find member at index {index} "
61 f"for group {group.doc_id}.",
62 )
64 user_id = owner.doc_id
65 assert user_id is not None # narrowing
67 friend_id = member.uid
68 created_at = TypesenseTime.from_firestore(group.created_at_db)
69 updated_at = TypesenseTime.from_firestore(group.updated_at_db)
71 return [
72 FriendDocument.create(
73 uid=user_id,
74 friend_type=FriendDocumentType.GROUP,
75 keywords=[],
76 friend_uid=friend_id,
77 friend_keywords=[],
78 created_at=created_at,
79 updated_at=updated_at,
80 ),
81 FriendDocument.create(
82 uid=friend_id,
83 friend_type=FriendDocumentType.GROUP,
84 keywords=[],
85 friend_uid=user_id,
86 friend_keywords=[],
87 created_at=created_at,
88 updated_at=updated_at,
89 ),
90 ]