Пример #1
0
    def getSessionsInWishList(self, request):
        """Get all sessions of a user"""
        # Obtain user information and check user is logged in
        user = endpoints.get_current_user()
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')
        user_id = getUserId(user)
        # Obtain all user wish list matching the user id 
        userwishlist_sessions = UserWishList.query(UserWishList.userID == user_id)

        return UserWishListForms(items=[self._copyUserWishListToForm(session) for session in userwishlist_sessions])
Пример #2
0
    def deleteSessionInWishlist(self, request):
        """Delete session(s) from a user wish list matching the session key"""

        # Check the required field is provided 
        if not request.sessionKey:
            raise endpoints.BadRequestException("Session 'session Key' field required")

        # Obtain all user wish list session matching the given sessionKey
        # and delete all of them
        userwishlist_session = UserWishList.query(UserWishList.sessionKey == request.sessionKey)
        for u in userwishlist_session:
            u.key.delete()
        retval = True
        # return deletion is sucessful
        return BooleanMessage(data=retval)
Пример #3
0
    def getWishList(self, request):
        """Retrieves a list of wishlisted sessions for the current user"""
        user = endpoints.get_current_user()

        # User is logged in
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

        sessions_in_wishlist = UserWishList.query().filter(UserWishList.userId == getUserId(user))

        session_keys = [ndb.Key(urlsafe=wishlist.websafeSessionKey)
                        for wishlist in sessions_in_wishlist]

        sessions = ndb.get_multi(session_keys)

        return UserWishListSessionForms(sessions=[self._copySessionToForm(session) for session in sessions])
Пример #4
0
    def deleteWishList(self, request):
        """Deletes a UserWishList object"""
        user = endpoints.get_current_user()

        # User is logged in
        if not user:
            raise endpoints.UnauthorizedException('Authorization required')

        session_key = ndb.Key(urlsafe=request.websafeSessionKey)
        session = session_key.get()

        if not session:
            raise endpoints.NotFoundException('Session not found')

        wishlist_entity = UserWishList.query().filter(UserWishList.userId == getUserId(user),
                                                      UserWishList.websafeSessionKey == request.websafeSessionKey).fetch()

        for wish in wishlist_entity:

            wish.key.delete()

        return BooleanMessage(data=True)