class Access(object): def __init__(self): self.db = Database() self.collection_name = 'access' self.fields = { "role": "string", "ability": "string", "type": "string", "amount": "string", "status": "string", "created": "datetime", "updated": "datetime", } def create(self, access): res = self.db.insert(access, self.collection_name) return "Inserted Id " + res def find(self): return self.db.find(self.collection_name) def find_by_id(self, id): return self.db.find_by_id(id, self.collection_name) def update(self, id, access): return self.db.update(id, access, self.collection_name) def delete(self, id): return self.db.delete(id, self.collection_name)
class Wallet(object): def __init__(self): self.db = Database() self.collection_name = 'wallet' self.fields = { "customerID": "string", "VIP": "string", "balance": "string", "status": "string", "created": "datetime", "updated": "datetime", } def create(self, wallet): res = self.db.insert(wallet, self.collection_name) return "Inserted Id " + res def find(self): return self.db.find(self.collection_name) def find_by_id(self, id): return self.db.find_by_id(id, self.collection_name) def update(self, id, wallet): return self.db.update(id, wallet, self.collection_name) def delete(self, id): return self.db.delete(id, self.collection_name) def find_by_customer_id(self, id): return self.db.find_by_customer_id(id, self.collection_name)
class Customer(object): def __init__(self): self.db = Database() self.collection_name = 'customer' self.fields = { "name": "string", "created": "datetime", "updated": "datetime", "wallets":[] } def create(self, customer): res = self.db.insert(customer, self.collection_name) return "Inserted Id " + res def find(self): return self.db.find(self.collection_name) def find_by_id(self, id): return self.db.find_by_id(id, self.collection_name) def update(self, id, customer): return self.db.update(id, customer, self.collection_name) def delete(self, id): return self.db.delete(id, self.collection_name)
class Todo(object): def __init__(self): self.validator = Validator() self.db = Database() self.collection_name = 'todos' # collection name self.fields = { "title": "string", "body": "string", "created": "datetime", "updated": "datetime" } self.create_required_fields = ["title", "body"] # Fields optional for CREATE self.create_optional_fields = [] # Fields required for UPDATE self.update_required_fields = ["title", "body"] # Fields optional for UPDATE self.update_optional_fields = [] def create(self, todo): # Validator will throw error if invalid self.validator.validate(todo, self.fields, self.create_required_fields, self.create_optional_fields) res = self.db.insert(todo, self.collection_name) return "Inserted Id " + res def find(self, todo): # find all return self.db.find(todo, self.collection_name) def find_by_id(self, id): return self.db.find_by_id(id, self.collection_name) def update(self, id, todo): self.validator.validate(todo, self.fields, self.update_required_fields, self.update_optional_fields) return self.db.update(id, todo, self.collection_name) def delete(self, id): return self.db.delete(id, self.collection_name)