def post(self): ''' Adds a movie to the users' Watchlist. ''' TokenAuthenticator(request.headers.get('Authorization')).authenticate() movieID = request.json.get('movieID') is_valid_integer(movieID) new_watchlist = Watchlist(movieID, g.userID) session = Session() session.add(new_watchlist) try: session.commit() session.close() except IntegrityError: #If Watchlist already present session.rollback() raise BadRequest response = {'message': 'Movie added to Watchlist.'} return response, 201
def post(self): ''' Subscribe to the user. ''' TokenAuthenticator(request.headers.get('Authorization')).authenticate() subscribedUserID = request.json.get('userID') curUserID = g.userID # Can't subscribe to oneself. if curUserID == int(subscribedUserID): raise BadRequest subscribe = Subscription(curUserID, subscribedUserID) session = Session() session.add(subscribe) try: session.commit() except IntegrityError: #If subscription already present session.rollback() raise BadRequest response = {'message': 'Subscribed to User'} return response, 201