Ejemplo n.º 1
0
    def post(self):
        data = ApiContact.parser.parse_args()
        print('you are here')
        contact = Contact(data['name'], data['email'])
        try:
            contact.save_to_db()
        except:
            return {'message' : 'Failed to save'}, 500

        return contact.json(), 201
Ejemplo n.º 2
0
 def put(self, id=None):
     data = ApiContact.parser.parse_args()
     contact = Contact.find_by_id(data['id'])
     if contact is None:
         contact = Contact(data['name'], data['email'])
     else:
         contact.name = data['name']
         contact.email = data['email']
     contact.save_to_db()
     return contact.json()
Ejemplo n.º 3
0
 def get(self):
     contacts = Contact.find_all(Contact)
     return {'contacts' : [Contact.json(myInput) for myInput in contacts]}