def add_friend(self, request):
     print "in add_Friend"
     with db(session):
         try:
             friend = User.query.filter(User.email == request.friend_email).first()
             friendship = Friendship(user_id=request.userId, friend_id=friend.id)
             session.add(friendship)
             session.commit()
             return AddFriendResponse(friend_added=True)
         except Exception as e:
             session.rollback()
             return AddFriendResponse(friend_added=False)
    def create_user(self, request):
        if not isinstance(request, RegistrationRequest):
            return RpcError(message = "Wrong message type, expecting RegistrationRequest", error_code=1)
        # TODO: add more logic before insert the user to db
        if None in (request.email, request.password):
            return RpcError(message="Both email and password requires to be set", error_code=10)
        try:
            user = User(
                email = request.email,
                password = request.password
            )
            session.add(user)
            session.commit()

            return RegistrationResponse(userId=user.id)
        except IntegrityError as e:
            session.rollback()
            return RpcError(message="E-mail already used", error_code=11)
        except Exception as e:
            session.rollback()
            return RpcError(message=e.message) # TODO: improve this