-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.py
82 lines (65 loc) · 2.39 KB
/
order.py
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
import requests
import json
import datetime
from plugintype import PluginType
from uuid import uuid4
class Order:
# class constructor, takes a dictionary, which is the JSON passed from the HTTP Post, as an argument and
# populates class attributes
def __init__(self, dict):
self._id = str(dict.get("_id", uuid4()))
self._customerId = dict["customerId"]
self._timeStamp = dict.get("timeStamp", datetime.datetime.utcnow()) # Only set by mongo
self._paymentType = dict["paymentType"]
self._orderDestination = dict["orderDestination"]
self._plugin = PluginType[dict["plugin"]]
self._items = dict.get("items", [])
@property
def id(self):
return self._id
@property
def customerId(self):
return self._customerId
@property
def plugin(self):
return self._plugin
@plugin.setter
def plugin(self, value):
self._plugin = value
@property
def timeStamp(self):
return self._timeStamp
@timeStamp.setter
def timeStamp(self, value):
self._timeStamp = value
@property
def paymentType(self):
return self._paymentType
@paymentType.setter
def paymentType(self, value):
self._paymentType = value
@property
def orderDestination(self):
return self._orderDestination
@orderDestination.setter
def orderDestination(self, value):
self._orderDestination = value
@property
def items(self):
return self._items
@items.setter
def items(self, value):
self._items = value
def __str__(self):
return f"Order ( \nid: {self.id} \ncustomerId: {self.customerId} \nplugin: {self.plugin} \ntimeStamp: {self.timeStamp} \npaymentType: {self.paymentType} \norderDestination: {self.orderDestination} \nitems: {self.items} \n)"
def __eq__(self, value):
return isinstance(value, Order) and \
self.id == value.id and \
self.customerId == value.customerId and \
self.plugin == value.plugin and \
self.timeStamp == value.timeStamp and \
self.paymentType == value.paymentType and \
self.orderDestination == value.orderDestination and \
self.items == value.items
def __hash__(self):
return hash((self.id, self.customerId, self.pluginType, self.timeStamp, self.paymentType, self.orderDestination, self.items))