def delete(self): current_username = get_jwt_identity()['username'] current_user = User.find_by_username(current_username) data = subscriptions_likes_parser.parse_args() res_id = data.get('research_id') res = Research.find_by_id(res_id) if current_user is None: return { 'response': False, 'message': 'User {} does not exist'.format(current_username) }, 400 if res is None: return { 'response': False, 'message': 'Research {} does not exist'.format(res.topic) }, 400 if current_user.unlike(res): from app import db db.session.commit() return { 'response': True, 'message': '{} removed like froom {}'.format(current_username, res.topic) }
def post(self): current_username = get_jwt_identity() current_user = User.find_by_username(current_username) data = subscriptions_likes_parser.parse_args() res_id = data.get('research_id') res = Research.find_by_id(res_id) if current_user is None: return { 'response': False, 'message': 'User {} does not exist'.format(current_username) }, 400 if res is None: return { 'response': False, 'message': 'Research {} does not exist'.format(res.topic) }, 400 if current_user.subscribe(res): from app import db db.session.commit() return { 'response': True, 'message': '{} is subscribed to {} from now.'.format(current_username, res.topic) }
def post(self): data = subscriptions_likes_parser.parse_args() res_id = data.get('research_id') res = Research.find_by_id(res_id) if res is None: return { 'response': False, 'message': 'Research {} does not exist'.format(res.topic) }, 400 res.views += 1 from app import db db.session.commit() return { 'response': True, 'message': 'Research {} got {} views'.format(res.topic, res.views), 'views': res.views }