def put(self, name): data = Annonce.parser.parse_args() annonce = AnnonceModel.find_by_name(name) if annonce: annonce.theme = data['theme'] else: annonce = AnnonceModel(name, data['theme']) annonce.save_to_db() return annonce.json()
def post(self, name): if AnnonceModel.find_by_name(name): return {'message': "An annonce with name '{}' already exists.".format(name)}, 400 data = Annonce.parser.parse_args() annonce = AnnonceModel(name, data['theme'], data['description'], current_identity.id) try: annonce.save_to_db() except: return {"message": "An error occurred inserting the annonce."}, 500 return annonce.json(), 201
def delete(self, name): annonce = AnnonceModel.find_by_name(name) if annonce: annonce.delete_from_db() return {'message': 'Annonce deleted'}
def get(self, name): annonce = AnnonceModel.find_by_name(name) if annonce: return annonce.json() return {'message': 'Annonce not found'}, 404