135 lines
4.0 KiB
Python
Executable File
135 lines
4.0 KiB
Python
Executable File
import socket
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
from typing import Union
|
|
|
|
from dataclasses_json import dataclass_json
|
|
|
|
|
|
class PublishType(Enum):
|
|
SUCCESS = "SUCCESS"
|
|
ERROR = "ERROR"
|
|
PENDING = "PENDING"
|
|
DUPLICATED = "DUPLICATED"
|
|
|
|
|
|
@dataclass_json
|
|
@dataclass
|
|
class ReserveResultPojo:
|
|
type: PublishType = PublishType.ERROR
|
|
phone: str = ""
|
|
message: str = ""
|
|
url: str = ""
|
|
firstName: Union[None, str] = ""
|
|
lastName: Union[None, str] = ""
|
|
email: Union[None, str] = ""
|
|
id: str = ""
|
|
accepted = None
|
|
passport: str = ""
|
|
slot_position = None
|
|
sim_position = None
|
|
ccid: str = ""
|
|
source_from: str = socket.gethostname()
|
|
store_type = 0
|
|
url_validated = None
|
|
created_at = None
|
|
validated_at = None
|
|
proxy: str = None
|
|
|
|
@staticmethod
|
|
def from_firestore_dict(source):
|
|
publish_type = PublishType.ERROR
|
|
if 'type' in source:
|
|
publish_type = source['type']
|
|
if publish_type:
|
|
publish_type = PublishType[publish_type]
|
|
if 'phone' in source:
|
|
phone = source['phone']
|
|
else:
|
|
phone = ""
|
|
if 'url' in source:
|
|
url = source['url']
|
|
else:
|
|
url = ""
|
|
if 'id' in source:
|
|
id = source['id']
|
|
if '_id' in source:
|
|
id = source['_id']
|
|
else:
|
|
id = ""
|
|
if 'email' in source:
|
|
email = source['email']
|
|
else:
|
|
email = ""
|
|
if 'lastName' in source:
|
|
lastName = source['lastName']
|
|
else:
|
|
lastName = ""
|
|
|
|
if 'firstName' in source:
|
|
firstName = source['firstName']
|
|
else:
|
|
firstName = ""
|
|
|
|
result = ReserveResultPojo(type=publish_type, phone=phone,
|
|
url=url, email=email,
|
|
firstName=firstName, lastName=lastName)
|
|
if 'accepted' in source:
|
|
accepted = source['accepted']
|
|
result.accepted = accepted
|
|
if 'message' in source:
|
|
message = source['message']
|
|
result.message = message
|
|
if 'source' in source:
|
|
source_from = source['source']
|
|
result.source_from = source_from
|
|
if 'sim_position' in source:
|
|
sim_position = source['sim_position']
|
|
result.sim_position = sim_position
|
|
if 'slot_position' in source:
|
|
slot_position = source['slot_position']
|
|
result.slot_position = slot_position
|
|
if 'passport' in source:
|
|
passport = source['passport']
|
|
result.passport = passport
|
|
if 'ccid' in source:
|
|
ccid = source['ccid']
|
|
result.ccid = ccid
|
|
if 'store_type' in source:
|
|
store_type = source['store_type']
|
|
result.store_type = store_type
|
|
if 'url_validated' in source:
|
|
url_validated = source['url_validated']
|
|
result.url_validated = bool(url_validated)
|
|
if 'created_at' in source:
|
|
created_at = source['created_at']
|
|
result.created_at = created_at
|
|
if 'validated_at' in source:
|
|
validated_at = source['validated_at']
|
|
result.validated_at = validated_at
|
|
result.id = id
|
|
return result
|
|
|
|
def to_firestore_dict(self):
|
|
dest = {
|
|
u'type': self.type.value,
|
|
u'id': self.id,
|
|
u'phone': self.phone,
|
|
u'firstName': self.firstName,
|
|
u'lastName': self.lastName,
|
|
u'email': self.email,
|
|
u'passport': self.passport,
|
|
u'url': self.url,
|
|
# u'sim_position': self.sim_position,
|
|
# u'slot_position': self.slot_position,
|
|
u'source_from': self.source_from,
|
|
u'hostName': self.source_from,
|
|
u'created_at': self.created_at,
|
|
u'store_type': self.store_type,
|
|
u'accepted': self.accepted,
|
|
u'url_validated': self.url_validated,
|
|
u'proxy': self.proxy,
|
|
}
|
|
|
|
return dest
|