def put(self): args = parser.parse_args() userId = oauth.validate_user_id(args['userId']) if userId == -1 : return { 'error' : 'invalid user id'} result = db.adminCollection.insert_one({ 'userId': userId, 'isAdmin': True }) return {'created': dumps(result.userId)}, 201
def put(self): args = parser.parse_args() userId = oauth.validate_user_id(args['userId']) stats = json.loads(args['stats']) result = db.statsCollection.insert_one({ 'dateTime': get_datetime(), 'userId': userId, 'exerciseId': args['exerciseId'], 'stats': stats }) return {'inserted': dumps(result.inserted_id)}, 201
def post(self, exercise_id): args = parser.parse_args() userId = oauth.validate_user_id(args['userId']) existing = db.scoresCollection.find_one({'userId': userId, 'exerciseId': exercise_id}) if (existing and int(existing['stars']) >= int(args['stars'])): return {'updated': dumps(existing)} result = db.scoresCollection.update_one( { 'userId': userId, 'exerciseId': exercise_id }, { '$set': { 'stars': args['stars'] } }, upsert=True ) return {'updated': dumps(result.upserted_id)}
def get(self): args = parser.parse_args() userId = oauth.validate_user_id(args['userId']) data = db.adminCollection.find_one({'userId': userId}) print("\n \n UserId: " + str(userId) + ", Data: " + dumps(data) + "\n\n") return {'data': {'isAdmin': False if not data else data.get('isAdmin')}}
def get(self): args = parser.parse_args() userId = oauth.validate_user_id(args['userId']) response = db.scoresCollection.find({'userId': userId}) return {'data': dumps(response)}