def create(respJson): try: valid = DogSchema().load(respJson) except ValidationError as e: return BadRequest(e.messages) else: # Make sure the owner is actually real... o = Owner.query.get(valid['owner']) if o: d = Dog(name=valid['name'], owner=valid['id'], breed=valid['breed']) db.session.add(d) db.session.commit() return OkRequest(DogSchema().dump(d)) return BadRequest("Owner not found")
def create(respJson): try: valid = OwnerSchema().load(respJson) except ValidationError as e: return BadRequest(e.messages) else: h = str(hashlib.md5(valid['password'].encode())) o = Owner(firstname=valid['firstname'], lastname=valid['lastname'], username=valid['username'], email=valid['email'], password_hash=h, city=valid['city'], state=valid['state'], zip_code=valid['zip_code'], ) db.session.add(o) db.session.commit() return OkRequest(OwnerSchema().dump(o))
def delete(id): o = Owner.query.get(id) db.session.delete(o) db.session.commit() return OkRequest("Deleted")
def getOwner(id): return OkRequest(OwnerSchema().dump(Owner.query.get(id)))
def getList(): return OkRequest(OwnerSchema(many=True).dump(Owner.query.all()))
def delete(id): d = Dog.query.get(id) db.session.delete(d) db.session.commit() return OkRequest("Deleted")
def getDog(id): return OkRequest(DogSchema().dump(Dog.query.get(id)))
def getList(): return OkRequest(DogSchema(many=True).dump(Dog.query.all()))
def getAll(): return OkRequest(MetricSchema(many=True).dump(Metrics.query.all()))