File size: 2,852 Bytes
8e1c132
 
 
 
63dfa98
8e1c132
 
 
 
 
 
 
 
6c377a5
8e1c132
 
 
6c377a5
 
 
 
 
63dfa98
6c377a5
8e1c132
 
 
 
6c377a5
7a511fb
 
 
 
6c377a5
8e1c132
6c377a5
 
 
 
 
 
8e1c132
 
 
 
6c377a5
 
 
 
 
8e1c132
6c377a5
 
 
 
 
 
8e1c132
 
 
 
6c377a5
 
 
 
 
8e1c132
6c377a5
 
 
 
 
63dfa98
6c377a5
8e1c132
 
 
 
6c377a5
7a511fb
 
 
 
6c377a5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from enum import Enum as PyEnum

from src.utils import ProposalAIAnalysisClient

from src.models import QueryType, CreateOrUpdateType, Category


class ProposalAIAnalysisService:
    def __init__(self):
        self.proposal_ai_analysis_client = ProposalAIAnalysisClient

    async def __aenter__(self):
        return self

    async def __aexit__(self, exc_type, exc_value, traceback):
        pass

    async def get_all_data(
        self,
        query_type: QueryType = QueryType.ALL,
        id: str = None,
        proposal_id: str = None,
        category: Category = None,
    ):
        async with self.proposal_ai_analysis_client() as client:
            if query_type == QueryType.ALL:
                return await client.get_complete_analysis(proposal_id=proposal_id)
            else:
                return await client.get_all_data(
                    query_type=query_type,
                    id=id,
                    proposal_id=proposal_id,
                    category=category,
                )

    async def create_data(
        self,
        query_type: QueryType = QueryType.ALL,
        create_or_update_type: CreateOrUpdateType = CreateOrUpdateType.ALL,
        data: dict = None,
    ):
        async with self.proposal_ai_analysis_client() as client:
            if query_type == QueryType.ALL:
                return await client.create_complete_analysis(data=data)
            else:
                return await client.create_data(
                    query_type=query_type,
                    create_or_update_type=create_or_update_type,
                    data=data,
                )

    async def update_data(
        self,
        query_type: QueryType = QueryType.ALL,
        create_or_update_type: CreateOrUpdateType = CreateOrUpdateType.ALL,
        data: dict = None,
    ):
        async with self.proposal_ai_analysis_client() as client:
            if query_type == QueryType.ALL:
                return await client.update_complete_analysis(data=data)
            else:
                return await client.update_data(
                    query_type=query_type,
                    create_or_update_type=create_or_update_type,
                    data=data,
                )

    async def delete_data(
        self,
        query_type: QueryType = QueryType.ALL,
        id: str = None,
        proposal_id: str = None,
        category: Category = None,
    ):
        async with self.proposal_ai_analysis_client() as client:
            if query_type == QueryType.ALL:
                return await client.delete_complete_analysis(proposal_id=proposal_id)
            else:
                return await client.delete_data(
                    query_type=query_type,
                    id=id,
                    proposal_id=proposal_id,
                    category=category,
                )