Coverage for functions \ flipdare \ firestore \ chat_db.py: 88%

17 statements  

« 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# 

12 

13 

14from google.cloud.firestore import Client as FirestoreClient 

15from flipdare.firestore._app_db import AppDb 

16from flipdare.firestore._app_sub_db import AppSubDb 

17from flipdare.generated.model.chat_comment_model import ChatCommentModel 

18from flipdare.generated.model.chat_model import ChatModel 

19from flipdare.generated.shared.firestore_collections import FirestoreCollections 

20from flipdare.wrapper import ChatCommentWrapper, ChatWrapper 

21 

22__all__ = ["ChatDb"] 

23 

24_CHAT: str = FirestoreCollections.CHAT.value 

25_CHAT_COMMENT: str = FirestoreCollections.CHAT_COMMENTS.value 

26 

27 

28class ChatDb(AppDb[ChatWrapper, ChatModel]): 

29 

30 def __init__(self, client: FirestoreClient) -> None: 

31 super().__init__( 

32 client=client, 

33 collection_name=FirestoreCollections.CHAT, 

34 model_class=ChatModel, 

35 wrapper_class=ChatWrapper, 

36 ) 

37 

38 self.comments = AppSubDb[ChatCommentWrapper, ChatCommentModel]( 

39 client=client, 

40 collection_name=FirestoreCollections.CHAT, 

41 sub_collection_name=FirestoreCollections.CHAT_COMMENTS, 

42 wrapper_class=ChatCommentWrapper, 

43 model_class=ChatCommentModel, 

44 ) 

45 

46 def update_comment( 

47 self, 

48 parent_id: str, 

49 comment: ChatCommentWrapper, 

50 ) -> ChatCommentWrapper | None: 

51 """Update an existing chat comment.""" 

52 comment_id = comment.doc_id 

53 return self.comments.update_sub( 

54 parent_id=parent_id, 

55 sub_id=comment_id, 

56 updates=comment.get_updates(), 

57 )