示例#1
0
    def create_user():
        app.logger.info("content-type: {}, data: {}".format(
            request.headers.get('content-type'),
            request.get_data(),
        ))

        user_resource = UserResource.from_dict(loads(request.get_data()))
        user = User.from_user_resource(user_resource)
        try:
            db.session.add(user)
            db.session.commit()
            return dumps(user.to_user_resource().to_dict()), codes.created
        except Exception as e:
            app.logger.exception(e)
            db.session.rollback()
            raise
示例#2
0
    def update_user():
        app.logger.info("content-type: {}, data: {}".format(
            request.headers.get('content-type'),
            request.get_data(),
        ))

        user_resource = UserResource.from_dict(loads(request.get_data()))
        user = User.query.get_or_404(user_resource.id)
        try:
            user.email = user_resource.email
            user.name = user_resource.name
            user.phone = user_resource.phone
            user.company = user_resource.company
            user.linkedin_url = user_resource.linkedin_url
            db.session.commit()
            return dumps(user.to_user_resource().to_dict()), codes.ok
        except Exception as e:
            app.logger.exception(e)
            db.session.rollback()
            raise