class TrolleyRepository: def __init__(self): self.dao = TrolleyDao() def deleteTrolley(self, trolley_id): trolley_id = self.dao.deleteTrolley(trolley_id) return trolley_id def getAllTrolleys(self): result = self.dao.getAllTrolleys() trolleys = [] if result: for row in result: trolley = Trolley(row) trolleys.append(trolley) return trolleys def getTrolleyById(self, trolley_id): result = self.dao.getTrolleyById(trolley_id) trolley = None if result: trolley = Trolley(result) return trolley
def trolleyFactory(plate, capacity, mileage): dao = TrolleyDao() trolley_id = dao.insert(plate, capacity, mileage) data = dao.getTrolleyById(trolley_id) trolley = Trolley(data) return trolley
def getAllTrolleys(self): dao = TrolleyDao() results_list = dao.getAllTrolleys() trolleys_list = [] trolleys_list = trolleyRepository(results_list) trolleys_list = list(map(getInfo, trolleys_list)) return jsonify(Trolleys=trolleys_list)
def getTrolleyByPlate(self, plate): dao = TrolleyDao() result = dao.getTrolleyByPlate(plate) if not result: return jsonify(Error="Trolley Not Found"), 404 else: trolley = trolleyRepository(result) trolley = getInfo(trolley) return jsonify(Trolley=trolley)
def factory(self, plate, capacity, mileage): dao = TrolleyDao() trolley_id = dao.registerTrolley(plate, capacity, mileage) data = dao.getTrolleyById(trolley_id) self.trolley['trolley_id'] = data['trolley_id'] self.trolley['plate'] = data['plate'] self.trolley['capacity'] = data['capacity'] self.trolley['mileage'] = data['mileage']
def getTrolleysByMileageRange(self, mileage_low, mileage_high): dao = TrolleyDao() results_list = dao.getTrolleysByMileageRange(mileage_low, mileage_high) trolleys_list = [] if not results_list: return jsonify(Error="Trolleys Not Found"), 404 else: trolleys_list = trolleyRepository(results_list) trolleys_list = list(map(getInfo, trolleys_list)) return jsonify(Trolleys=trolleys_list)
def getTrolleysByCapacity(self, capacity): dao = TrolleyDao() results_list = dao.getTrolleysByCapacity(capacity) trolleys_list = [] if not results_list: return jsonify(Error="Trolleys Not Found"), 404 else: trolleys_list = trolleyRepository(results_list) trolleys_list = list(map(getInfo, trolleys_list)) return jsonify(Trolleys=trolleys_list)
def __init__(self): self.dao = TrolleyDao()