def post(self): error_message = None try: # Processing input arguments parser.add_argument('name', type=str, required=True, trim=True) parsed_args = parser.parse_args() # Creating team instance team = Team( created=datetime.datetime.utcnow(), name=parsed_args['name'], params=parsed_args['params'], meta=parsed_args['meta'] ) # Saving to DB session.add(team) session.commit() except IntegrityError: error_message = 'Faulty or a duplicate record' except ValueError as e: error_message = str(e) except Exception as e: print(str(e)) error_message = 'Bad request' finally: if error_message: session.rollback() abort(400, message='Unable to create team record: ' + error_message) else: return team, 201
def put(self, id): team = session.query(Team).filter(Team.id == id).first() if not team: abort(404, message="Team {} does not exist".format(id)) error_message = None try: # Processing input arguments parser.add_argument('name', type=str, required=True, trim=True) parsed_args = parser.parse_args() # Updating team instance team.name = parsed_args['name'] if parsed_args['name'] else team.name # Saving to DB session.merge(team) session.commit() except IntegrityError: error_message = 'Faulty or a duplicate record' except ValueError as e: error_message = str(e) except Exception as e: print(str(e)) error_message = 'Bad request' finally: if error_message: session.rollback() abort(400, message='Unable to create team record: ' + error_message) else: return team, 202
def put(self, id): try: property_contoller = PropertyController(id=id, landlord_id=self.landlord_id) parser.add_argument('name', type=str, trim=True, store_missing=False) parser.add_argument('address', type=str, trim=True, store_missing=False) parser.add_argument('city', type=str, trim=True, store_missing=False) parser.add_argument('state', type=str, trim=True, store_missing=False) parser.add_argument('postal_zip', type=str, trim=True, store_missing=False) parsed_args = parser.parse_args() property_contoller.update(**parsed_args) return property_contoller.property, 202 except Exception: abort(400, message="Error editing Property")
def post(self): try: # Processing input arguments parser.add_argument('name', type=str, trim=True) parser.add_argument('address', type=str, required=True, trim=True) parser.add_argument('city', type=str, required=True, trim=True) parser.add_argument('state', type=str, trim=True) parser.add_argument('postal_zip', type=str, trim=True) parsed_args = parser.parse_args() parsed_args['landlord_id'] = self.landlord_id property = PropertyController().create(**parsed_args) return property, 201 except Exception as e: abort(400, message=str(e))
def post(self): try: # Processing input arguments parser.add_argument('first_name', type=str, required=True, trim=True) parser.add_argument('last_name', type=str, required=True, trim=True) parser.add_argument('email', type=str, required=True, trim=True) parser.add_argument('username', type=str, required=False, trim=True) parser.add_argument('password', type=str, required=False) parsed_args = parser.parse_args() parsed_args['type'] = self.type # Creating user object user = UserController().create(**parsed_args) return user, 201 except Exception as e: abort(400, message=str(e))
def put(self): try: user_controller = UserController(id=self.id) except Exception: abort(404, message="User not loaded") return None try: # Processing input arguments parser.add_argument('first_name', type=str, trim=True, store_missing=False) parser.add_argument('last_name', type=str, trim=True, store_missing=False) parser.add_argument('email', type=str, trim=True, store_missing=False) parser.add_argument('username', type=str, trim=True, store_missing=False) parser.add_argument('password', type=str, store_missing=False) parsed_args = parser.parse_args() # Updating user instance user_controller.update(**parsed_args) return user_controller.user, 202 except Exception as e: abort(400, message=str(e))
def post(self): error_message = None try: # Processing input arguments parser.add_argument('name', type=str, required=True, trim=True) parser.add_argument('email', type=str, required=True, trim=True) parser.add_argument('password', type=str) parser.add_argument('user_id', type=str, required=True) parser.add_argument('pin', type=str, required=True) parser.add_argument('profile_picture', type=str) parsed_args = parser.parse_args() # Creating user instance user = User( created=datetime.datetime.utcnow(), name=parsed_args['name'], email=parsed_args['email'], user_id=parsed_args['user_id'], pin=parsed_args['pin'], profile_picture=parsed_args['profile_picture'], ) # Saving to DB session.add(user) session.commit() except IntegrityError: error_message = 'Faulty or a duplicate record' except ValueError as e: error_message = str(e) except Exception as e: print(str(e)) error_message = 'Bad request' finally: if error_message: session.rollback() abort(400, message='Unable to create user record: ' + error_message) else: return user, 201
def get(self): parser.add_argument('limit', type=int) parser.add_argument('offset', type=int) output = session.query(User).all() return output
def put(self, id): user = session.query(User).filter(User.id == id).first() if not user: abort(404, message="User {} does not exist".format(id)) error_message = None try: # Processing input arguments parser.add_argument('name', type=str, trim=True) parser.add_argument('email', type=str, trim=True) parser.add_argument('password', type=str) parser.add_argument('user_id', type=str) parser.add_argument('pin', type=str) parser.add_argument('profile_picture', type=str) parsed_args = parser.parse_args() # Updating user instance user.name = parsed_args['name'] if parsed_args['name'] else user.name user.email = parsed_args['email'] if parsed_args['email'] else user.email user.password = parsed_args['password'] if parsed_args['password'] else user.password user.user_id = parsed_args['user_id'] if parsed_args['user_id'] else user.user_id user.pin = parsed_args['pin'] if parsed_args['pin'] else user.pin user.profile_picture = parsed_args['profile_picture'] if parsed_args[ 'profile_picture'] else user.profile_picture # Saving to DB session.merge(user) session.commit() except IntegrityError: error_message = 'Faulty or a duplicate record' except ValueError as e: error_message = str(e) except Exception as e: print(str(e)) error_message = 'Bad request' finally: if error_message: session.rollback() abort(400, message='Unable to create user record: ' + error_message) else: return user, 202