File size: 2,553 Bytes
a8ce4bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d5b006
a8ce4bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from firebase_admin import credentials
from firebase_admin import firestore
import threading
from firebase_admin import db
# Import the Firebase Admin SDK
import firebase_admin


class Shakwa(object):
    def __init__(self, address, complaintbody, date, governorate, id, organization, summary, title, userid):
        self.address = address
        self.complaintbody = complaintbody
        self.date = date
        self.governorate = governorate
        self.id = id
        self.organization = organization
        self.summary = summary
        self.title = title
        self.userid = userid

    def set_data(self,db):
        # Create a document reference with the user's email as the ID
        doc_ref = db.collection('complaints').document(self.id)
        # Set the document data with the user's attributes
        doc_ref.set(self.to_dict())

    # Convert a dictionary to a Shkwa object

    @staticmethod
    def from_dict(source):
        # Check if the source is a valid dictionary
        if not isinstance(source, dict):
            raise ValueError('Source is not a dictionary')
        # Create a User object with the source values
        shakwa = Shakwa(
            source['address'],
            source['complaintbody'],
            source['date'],
            source['governorate'],
            source['id'],
            source['organization'],
            source['summary'],
            source['title'],
            source['userid']
        )
        # Return the Shkwa object
        return shakwa

    # Convert a Shkwa object to a dictionary
    def to_dict(self):
        # Create a dictionary with the Shkwa's attributes
        dest = {
            'address': self.address,
            'complaintbody': self.complaintbody,
            'date': self.date,
            'governorate': self.governorate,
            'organization': self.organization,
            'summary': self.summary,
            'title': self.title,
            'userid': self.userid,
            'id': self.id,
        }
        # Return the dictionary
        return dest

    # Represent a Shkwa object as a string
    def __repr__(self):
        return (
            f'address={self.address}'
            f'complaintbody={self.complaintbody},'
            f'date={self.date}, '
            f'governorate={self.governorate}, '
            f'organization={self.organization}, '
            f'summary={self.summary}, '
            f'title={self.title}, '
            f'userid={self.userid}, '
            f'userid={self.id}, '
            f')'
        )