def put(self, name): data = Country.parser.parse_args() today = str(date.today()) country = CountryModel(name, today, **data) country.send_to_queue() return country.json()
def put(self, country_name): data = CountryName.parser.parse_args() country = CountryModel.find_by_name(country_name) if country: country.country_code = data['country_code'] else: country = CountryModel(data['country_code'], country_name) country.save_to_db() return country.json()
def put(self, name): data = Country.parser.parse_args() country = CountryModel.find_by_country(name) if country is None: country = CountryModel(name, **data) else: country.cases = data['cases'] country.deaths = data['deaths'] country.deaths = data['deaths'] country.save_to_db() return country.json()
def post(self, name): if CountryModel.find_by_country(name): return { "message": "An country with the name '{}' already exist.".format(name) }, 400 data = Country.parser.parse_args() country = CountryModel(name, **data) try: country.save_to_db() except: return { "message": "An error occured while inserting the country." }, 500 return country.json(), 201
def post(self, country_name): if CountryModel.find_by_name(country_name): return { 'message': "A country with name '{}' already exists.".format(country_name) }, 400 data = CountryName.parser.parse_args() if CountryModel.find_by_code(data['country_code']): return { 'message': "A country with code '{}' already exists.".format( data['country_code']) }, 400 country = CountryModel(data['country_code'], country_name) try: country.save_to_db() except: return {'message': "An error occurred inserting the country."}, 500 return country.json(), 201