Coverage for functions \ flipdare \ task \ report \ dare_reporter.py: 88%
24 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#
13from __future__ import annotations
15from typing import TYPE_CHECKING
16from flipdare.core.app_backend_link import AppBackendLink
17from flipdare.service._service_provider import ServiceProvider
18from flipdare.task.report.core.query_report import QueryReport
19from flipdare.result.output_result import OutputResult
20from flipdare.generated.schema.report.dare_report_schema import DareReportSchema
21from flipdare.generated.shared.backend.app_job_type import AppJobType
22from flipdare.util.time_util import FirestoreTime
23from flipdare.wrapper import DareWrapper
25if TYPE_CHECKING:
26 from flipdare.manager.db_manager import DbManager
27 from flipdare.manager.backend_manager import BackendManager
29__all__ = ["DareReporter"]
32class DareReporter(ServiceProvider):
33 def __init__(
34 self,
35 db_manager: DbManager,
36 backend_manager: BackendManager,
37 ) -> None:
38 super().__init__(
39 db_manager=db_manager,
40 backend_manager=backend_manager,
41 )
43 def review_required(self) -> OutputResult:
44 job_type = AppJobType.REPORT_DARE_REVIEW_REQUIRED
45 report = QueryReport[DareReportSchema](
46 job_type=job_type,
47 schema_cls=DareReportSchema,
48 query_fn=lambda: self.dare_db.get_recent_requires_review(),
49 process_fn=self._dare_entry_processor,
50 app_logger=self.app_logger,
51 mailer=self.admin_mailer,
52 )
54 return report.create_and_send()
56 def auto_restricted(self) -> OutputResult:
57 job_type = AppJobType.REPORT_DARE_AUTO_RESTRICTED
58 report = QueryReport[DareReportSchema](
59 job_type=job_type,
60 schema_cls=DareReportSchema,
61 query_fn=lambda: self.dare_db.get_recent_auto_restricted(),
62 process_fn=self._dare_entry_processor,
63 app_logger=self.app_logger,
64 mailer=self.admin_mailer,
65 )
67 return report.create_and_send()
69 def _dare_entry_processor(self, dare: DareWrapper) -> DareReportSchema:
70 return DareReportSchema(
71 {
72 "dare_id": dare.doc_id,
73 "title": dare.title,
74 "message": dare.message,
75 "from_uid": dare.from_uid,
76 "status": dare.status.value,
77 "disputed_progress": (
78 dare.disputed_progress.value if dare.disputed_progress else "N/A"
79 ),
80 "link": AppBackendLink.DARE.link(dare.doc_id) if dare.doc_id else "N/A",
81 "created_at": FirestoreTime.internal_str(dare.created_at_db),
82 "updated_at": FirestoreTime.internal_str(dare.updated_at_db),
83 },
84 )