예제 #1
0
    def post_answer():
        body = request.json
        meme_id = body['memeId']
        user_id = body['userId']
        result = body['result']
        feedback = body.get('feedback')
        # insert_answer(meme_id, user_id, subject_id, result, feedback)

        # Update Meme
        meme = Meme.from_bson(find_one_meme(meme_id))
        update_meme(meme_id, {'shown': meme.shown + 1})
        if result == 'correct':
            update_meme(meme_id,
                        {'answered_correctly': meme.answered_correctly + 1})
        if result == 'incorrect':
            print("HERE")
            update_meme(
                meme_id,
                {'answered_incorrectly': meme.answered_incorrectly + 1})

        # Update urer
        user = User.from_bson(find_one_user(user_id))
        update_user(user_id, {'memes_shown': user.memes_shown + 1})
        if result == 'correct':
            update_user(user_id, {'correct_answers': user.correct_answers + 1})
        if result == 'incorrect':
            print("THERE")
            update_user(user_id,
                        {'incorrect_answers': user.incorrect_answers + 1})

        return success_response({})
예제 #2
0
파일: memes.py 프로젝트: goodmove/hm-back
 def get_next_meme():
     body = request.json
     user_id = body['user_id']
     subject_id = body['subject_id']
     meme_id = get_next_meme_id(user_id, subject_id)
     meme = Meme.from_bson(find_one_meme(meme_id))
     return success_response({'meme': meme.to_json()})
예제 #3
0
파일: memes.py 프로젝트: goodmove/hm-back
 def get_meme(meme_id):
     res = find_one_meme(meme_id)
     if res:
         result_json = Meme.from_bson(res).to_json()
         return success_response({'meme': result_json})
     else:
         return error_response('Meme with id {} not found'.format(meme_id),
                               404, None)
예제 #4
0
 def get_subject(subject_id):
     res = find_one_subject(subject_id)
     if res:
         subject_json = Subject.from_bson(res).to_json()
         return success_response({'subject': subject_json})
     else:
         return error_response(
             'Subject with id {} not found'.format(subject_id), 404, None)
예제 #5
0
파일: users.py 프로젝트: goodmove/hm-back
 def get_user(user_id):
     res = find_one_user(user_id)
     if res:
         result_json = User.from_bson(res).to_json()
         return success_response({'user': result_json})
     else:
         return error_response('User with id {} not found'.format(user_id),
                               404, None)
예제 #6
0
파일: users.py 프로젝트: goodmove/hm-back
 def add_user():
     body = request.json
     inserted = insert_user(first_name=body['first_name'],
                            last_name=body['last_name'],
                            location=body.get('location'),
                            age=body.get('age'),
                            school=body.get('school'),
                            interests=body.get('interests', []),
                            memes_shown=0,
                            correct_answers=0,
                            incorrect_answers=0)
     return success_response({'user': inserted.to_json()})
예제 #7
0
파일: memes.py 프로젝트: goodmove/hm-back
    def generate_meme():
        subjectId = request.json['subjectId']
        file_path = get_quoted_meme(request.json['caption'])
        description = get_quote(
            request.json['caption']) + 'said ' + request.json['caption']

        if file_path is None:
            return error_response('Failed to create mem', 500, {})

        image_key = str(uuid.uuid4()) + '.png'
        upload_file(file_path, image_key)
        image_url = 'https://hack-moscow-bucket.s3.eu-north-1.amazonaws.com/' + image_key
        meme = insert_meme(image_url, subjectId, description)
        return success_response({'image': {'id': meme.id, 'url': image_url}})
예제 #8
0
파일: users.py 프로젝트: goodmove/hm-back
    def patch_user(user_id):
        body = request.json
        patch_object = {
            'first_name': body.get('first_name'),
            'last_name': body.get('last_name'),
            'location': body.get('location'),
            'age': body.get('age'),
            'school': body.get('school'),
            'interests': body.get('interests'),
            'memes_shown': body.get('memes_shown'),
            'correct_answers': body.get('correct_answers'),
            'incorrect_answers': body.get('incorrect_answers')
        }

        null_keys = []

        for key in patch_object:
            if not patch_object[key]:
                null_keys.append(key)

        for key in null_keys:
            del patch_object[key]

        return success_response(update_user(user_id, patch_object).to_json())
예제 #9
0
파일: memes.py 프로젝트: goodmove/hm-back
 def add_meme():
     body = request.json
     meme = insert_meme(body['url'], body['subject_id'],
                        body['explanation'], 0, 0, 0)
     print(meme.to_json())
     return success_response({'meme': meme.to_json()})
예제 #10
0
파일: memes.py 프로젝트: goodmove/hm-back
 def list_memes():
     memes = find_all_memes()
     return success_response({'memes': [m.to_json() for m in memes]})
예제 #11
0
 def add_subject():
     body = request.json
     subject = insert_subject(body['name'])
     return success_response({'subject': subject.to_json()})
예제 #12
0
 def list_answers():
     answers = find_all_answers()
     return success_response({'answers': [m.to_json() for m in answers]})
예제 #13
0
파일: users.py 프로젝트: goodmove/hm-back
 def list_users():
     data = find_all_users()
     return success_response({'users': [d.to_json() for d in data]})
예제 #14
0
 def list_user_answers():
     body = request.json
     user_id = body['user_id']
     answers = find_user_answers(user_id)
     return success_response(
         {'user_answers': [m.to_json() for m in answers]})
예제 #15
0
 def list_meme_answers():
     body = request.json
     meme_id = body['meme_id']
     answers = find_meme_answers(meme_id)
     return success_response({'answers': [m.to_json() for m in answers]})
예제 #16
0
파일: memes.py 프로젝트: goodmove/hm-back
 def validate_meme():
     body = request.json
     imageId = body['id']
     decision = body['decision']
     print("Image decision:", imageId, decision)
     return success_response({})
예제 #17
0
 def list_subjects():
     subjects = get_all_subjects()
     return success_response({'subjects': [d.to_json() for d in subjects]})