def get_shop(shop_id): try: shop = Shop.find_by_id(shop_id) if shop: return dumps(shop.as_json()), 200 else: return dumps({"Error": "Shop Not found"}), 400 except Exception as e: print(e.message) print(traceback.print_exc()) return dumps(e.message), 400
def list_offer_api(shop_id): try: shop = Shop.find_by_id(shop_id=shop_id) offers = Offer.find_by_shop(shop) return dumps([offer.as_json() for offer in offers]), 200 except ValueError as e: return dumps(e.message), 400 except Exception as e: print(e.message) print(traceback.print_exc()) return dumps(e.message), 400
def update_shop(shop_id): try: shop_hash = get_shop_json_attr_from_hash(request.json) shop = Shop.find_by_id(shop_id) if shop: shop = shop.update_shop_details(shop_hash) return dumps(shop.as_json()), 200 else: return dumps({"Error": "Shop Not found"}), 400 except Exception as e: print(e.message) print(traceback.print_exc()) return dumps(e.message), 400
def create_offer_api(shop_id): try: offer_hash = get_offer_json_attr_from_hash(request.json) if Offer.is_valid_hash_for_create(offer_hash): offer_hash['shop'] = Shop.find_by_id(shop_id) offer = Offer.create_offer(offer_hash) return dumps(offer.as_json()), 200 except ValueError as e: return dumps(e.message), 400 except Exception as e: print(e.message) print(traceback.print_exc()) return dumps(e.message), 400
def __init__(self, offer_id=None, title=None, discount=None, address=None, description=None, offer_profile_banner_url=None, geo_location=None, fk_shop_id=None, fk_category_id=None, starting_time=None, end_time=None): self.offer_id = offer_id self.title = title self.discount = discount self.address = address self.description = description self.offer_profile_banner_url = offer_profile_banner_url self.shop = Shop.find_by_id(shop_id=fk_shop_id) self.category = Category.find_by_id(category_id=fk_category_id) self.starting_time = starting_time self.end_time = end_time self.geo_location = geo_location
def test_should_return_None_by_find_by_shop_id(self): shop = Shop.find_by_id("some_wrong_shop_id") self.assertEqual(None, shop)
def test_should_return_shop_by_find_by_shop_id(self): shop = Shop.find_by_id(self.shop.shop_id) self.assertEqual(self.shop, shop)