Exemplo n.º 1
0
def getGamesByMuseumId(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    id = getIntPathParam("museumId", **request_handler_args)
    active = getBoolQueryParam('active', **request_handler_args)
    feedback = getBoolQueryParam('feedback', **request_handler_args)

    if id is None:
        resp.body = obj_to_json({'error': 'Invalid parameter supplied'})
        resp.status = falcon.HTTP_400
        return

    quests = EntityMuseum.get_wide_object(id, ['game'])
    res = []
    wide_info_arr = ['image', 'scenario', 'rating']
    if feedback:
        wide_info_arr = ['image', 'scenario', 'rating', 'comment']
    if len(quests['game']):
        for _ in quests['game']:
            if (active and _['active'] == 'True') or not active:
                obj_dict = _
                wide_info = EntityGame.get_wide_object(int(_['eid']),
                                                       wide_info_arr)
                obj_dict.update(wide_info)
                res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 2
0
def getTokenInfo(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    access_token = getStringQueryParam('access_token', **request_handler_args)
    type = getStringQueryParam('type', **request_handler_args)
    expansion = getBoolQueryParam('expansion', **request_handler_args)

    if access_token is None or type is None:
        resp.body = obj_to_json({'error': 'Invalid parameters supplied'})
        resp.status = falcon.HTTP_400
        return

    token, user, error, status = EntityToken.update_from_query({
        'access_token': access_token,
        'type': type
    })

    if not error:
        token_dict = token.to_dict(['eid', 'access_token', 'type', 'user_id'])
        user_dict = user.to_dict(['name', 'image', 'email', 'access_type'])
        if expansion:
            wide_info = EntityUser.get_wide_object(user.eid)
            user_dict.update(wide_info)
        token_dict.update(user_dict)

        resp.body = obj_to_json(token_dict)
        resp.status = falcon.HTTP_200
        return

    resp.body = obj_to_json(error)
    resp.status = status
Exemplo n.º 3
0
def updateMuseum(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    # email = req.context['email']
    # id_email = EntityUser.get_id_from_email(email)

    try:
        params = json.loads(req.stream.read().decode('utf-8'))

        # if params['id'] != id_email or not EntitySuperUser.is_id_super_admin(id_email):
        #    resp.status = falcon.HTTP_403
        #    return

        id = EntityMuseum.update_from_json(params)

        if id:
            objects = EntityMuseum.get().filter_by(eid=id).all()

            res = []
            for _ in objects:
                obj_dict = _.to_dict(['eid', 'ownerid', 'name', 'desc'])
                wide_info = EntityMuseum.get_wide_object(
                    _.eid, ['image', 'location', 'logo'])
                obj_dict.update(wide_info)
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 4
0
def updateStatistic(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))
        params['user_id'] = req.context['user_id']

        id = EntityRun.update_from_json(params)
        if id is not None:
            objects = EntityRun.get().filter_by(eid=id).all()

            res = []
            for _ in objects:
                obj_dict = _.to_dict()
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return

    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 5
0
def updateRatingToGame(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        _id_like = None
        _id_comment = None
        params = json.loads(req.stream.read().decode('utf-8'))
        params['userid'] = req.context['user_id']

        _id_like = EntityLike.update_from_json(params, 'rating')
        if _id_like:
            _id_comment = EntityComment.update_from_json(params, 'comment')

            likes = EntityLike.get().filter_by(eid=_id_like).all()
            comments = []
            if _id_comment:
                comments = EntityComment.get().filter_by(eid=_id_comment).all()

            res = []
            for i, like in enumerate(likes):
                obj_dict = like.to_dict(['userid', 'weight'])
                if _id_comment:
                    comment_info = comments[i].to_dict(['userid', 'text'])
                    obj_dict.update(comment_info)
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 6
0
def createGame(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))
        params['ownerid'] = req.context['user_id']
        id = EntityGame.add_from_json(params)

        if id:
            objects = EntityGame.get().filter_by(eid=id).all()

            res = []
            for _ in objects:
                obj_dict = _.to_dict(
                    ['eid', 'ownerid', 'name', 'desc', 'active'])
                wide_info = EntityGame.get_wide_object(
                    _.eid, ['image', 'scenario', 'rating'])
                obj_dict.update(wide_info)
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 7
0
def updateFeed(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))

        id = EntityNews.update_from_json(params)

        if id:
            objects = EntityNews.get().filter_by(eid=id).all()

            res = []
            for _ in objects:
                obj_dict = _.to_dict(['eid', 'title', 'desc', 'text'])
                wide_info = EntityNews.get_wide_object(_.eid,
                                                       ['image', 'priority'])
                obj_dict.update(wide_info)
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 8
0
def deleteFeed(**request_handler_args):
    resp = request_handler_args['resp']
    req = request_handler_args['req']

    id = getIntPathParam("feedId", **request_handler_args)
    res = []
    try:
        EntityNews.delete(id)
    except FileNotFoundError:
        resp.status = falcon.HTTP_404
        return

    try:
        EntityNews.delete_wide_object(id)
    except FileNotFoundError:
        resp.status = falcon.HTTP_405
        return

    object = EntityNews.get().filter_by(eid=id).all()
    if not len(object):
        resp.body = obj_to_json(res)
        resp.status = falcon.HTTP_200
        return

    resp.status = falcon.HTTP_400
Exemplo n.º 9
0
def GetAllGamesById(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    id = getIntPathParam("ownerId", **request_handler_args)
    active = getBoolQueryParam('active', **request_handler_args)
    objects = []
    if active:
        objects = EntityGame.get().filter_by(ownerid=id, active=True).all()
    else:
        objects = EntityGame.get().filter_by(ownerid=id).all()
    feedback = getBoolQueryParam('feedback', **request_handler_args)

    res = []
    wide_info_arr = ['image', 'scenario', 'rating']
    if feedback:
        wide_info_arr = ['image', 'scenario', 'rating', 'comment']
    for _ in objects:
        obj_dict = _.to_dict(['eid', 'ownerid', 'name', 'desc', 'active'])
        wide_info = EntityGame.get_wide_object(_.eid, wide_info_arr)
        obj_dict.update(wide_info)
        res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 10
0
def deleteGame(**request_handler_args):
    resp = request_handler_args['resp']
    req = request_handler_args['req']

    # TODO: VERIFICATION IF ADMIN DELETE ANY
    # email = req.context['email']
    id = getIntPathParam("gameId", **request_handler_args)
    # id_email = EntityUser.get_id_from_email(email)

    if id is not None:
        # if id != id_email or not EntitySuperUser.is_id_super_admin(id_email):
        #    resp.status = falcon.HTTP_403
        #    return

        res = []

        try:
            EntityGame.delete(id)
        except FileNotFoundError:
            resp.status = falcon.HTTP_404
            return

        try:
            EntityGame.delete_wide_object(id)
        except FileNotFoundError:
            resp.status = falcon.HTTP_405
            return

        object = EntityGame.get().filter_by(eid=id).all()
        if not len(object):
            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return

    resp.status = falcon.HTTP_400
Exemplo n.º 11
0
def revokeToken(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    params = json.loads(req.stream.read().decode('utf-8'))

    res, status = EntityToken.delete_from_json(params)

    resp.body = obj_to_json(res)
    resp.status = status
Exemplo n.º 12
0
def getToken(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    type = getStringQueryParam('type', **request_handler_args)
    expansion = getBoolQueryParam('expansion', **request_handler_args)
    if type == 'swagger':
        query = parse_qs(req.stream.read().decode('utf-8'))
        redirect_uri = query['redirect_uri'][0]
        code = query['code'][0]
    else:
        redirect_uri = getStringQueryParam('redirect_uri',
                                           **request_handler_args)
        code = getStringQueryParam('code', **request_handler_args)

    if redirect_uri is None or code is None or type is None:
        resp.body = obj_to_json({'error': 'Invalid parameters supplied'})
        resp.status = falcon.HTTP_400
        return

    token, user, error, status = EntityToken.add_from_query({
        'redirect_uri': redirect_uri,
        'code': code,
        'type': type
    })

    if not error:
        token_dict = token.to_dict(['eid', 'access_token', 'type', 'user_id'])
        user_dict = user.to_dict(['name', 'image', 'email', 'access_type'])
        if expansion:
            wide_info = EntityUser.get_wide_object(user.eid)
            user_dict.update(wide_info)
        token_dict.update(user_dict)

        resp.body = obj_to_json(token_dict)
        resp.status = falcon.HTTP_200
        return

    resp.body = obj_to_json(error)
    resp.status = status
Exemplo n.º 13
0
def checkImageAnswer(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))

        similar = EntityScenario.check_similar_image(params, img2vec)

        res = [{'result': 1 if similar else 0}]
        resp.body = obj_to_json(res)
        resp.status = falcon.HTTP_200
    except ValueError:
        resp.status = falcon.HTTP_405
Exemplo n.º 14
0
def getAllFeeds(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']
    objects = EntityNews.get().all()
    res = []
    for _ in objects:
        obj_dict = _.to_dict(['eid', 'title', 'desc', 'text'])
        wide_info = EntityNews.get_wide_object(_.eid, ['image', 'priority'])
        obj_dict.update(wide_info)
        res.append(obj_dict)

    res.sort(key=lambda row: row['priority'], reverse=True)
    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 15
0
def getAllMuseums(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    objects = EntityMuseum.get().all()

    res = []
    for _ in objects:
        obj_dict = _.to_dict(['eid', 'ownerid', 'name', 'desc'])
        wide_info = EntityMuseum.get_wide_object(
            _.eid, ['image', 'game', 'location', 'logo'])
        obj_dict.update(wide_info)
        res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 16
0
def getAgreement(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        text = open('./agreement.txt', 'rb').read().decode("windows-1251")
        res = [{'text': text}]

        resp.body = obj_to_json(res)
        resp.status = falcon.HTTP_200
        return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 17
0
def getTapeMuseums(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    first_m = getIntQueryParam('FirstMuseum', **request_handler_args)
    last_m = getIntQueryParam('LastMuseum', **request_handler_args)

    with DBConnection() as session:
        objects = session.db.query(EntityMuseum).order_by(
            EntityMuseum.created.desc()).all()

        count = objects.__len__()

    if first_m < 0:
        first_m = 0

    # if last_f isn't set (==-1), it is supposed to be an infinity
    if last_m == -1:
        museums = objects[first_m:]
    else:
        museums = objects[first_m:last_m + 1]

    if museums.__len__() == 0:
        if count > 0:
            if first_m > 0:
                first_m = min(int(first_m - math.fmod(first_m, 10)),
                              int(count - math.fmod(count, 10)))
            elif first_m < 0:
                first_m = 0
            museums = objects[first_m:first_m + 10]
        else:
            first_m = 0
    page = int((first_m - math.fmod(first_m, 10)) / 10) + 1

    res = []
    for _ in museums:
        obj_dict = _.to_dict(['eid', 'ownerid', 'name', 'desc'])
        wide_info = EntityMuseum.get_wide_object(
            _.eid, ['image', 'game', 'location', 'logo'])
        obj_dict.update(wide_info)
        res.append(obj_dict)

    res_dict = OrderedDict([('count', count), ('page', page), ('result', res)])

    resp.body = obj_to_json(res_dict)
    resp.status = falcon.HTTP_200
Exemplo n.º 18
0
def getFeedById(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    id = getIntPathParam("feedId", **request_handler_args)
    objects = EntityNews.get().filter_by(eid=id).all()

    wide_info = EntityNews.get_wide_object(id, ['image', 'priority'])

    res = []
    for _ in objects:
        obj_dict = _.to_dict(['eid', 'title', 'desc', 'text'])
        obj_dict.update(wide_info)
        res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 19
0
def getTapeFeeds(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    first_f = getIntQueryParam('FirstFeed', **request_handler_args)
    last_f = getIntQueryParam('LastFeed', **request_handler_args)

    with DBConnection() as session:
        objects = session.db.query(EntityNews, PropInt.value) \
            .join(PropInt, PropInt.eid == EntityNews.eid) \
            .order_by(PropInt.value.desc(), EntityNews.created.desc()).all()

        count = objects.__len__()

    if first_f < 0:
        first_f = 0

    # if last_f isn't set (==-1), it is supposed to be an infinity
    if last_f == -1:
        feeds = objects[first_f:]
    else:
        feeds = objects[first_f:last_f + 1]

    if feeds.__len__() == 0:
        if count > 0:
            if first_f > 0:
                first_f = min(int(first_f - math.fmod(first_f, 10)),
                              int(count - math.fmod(count, 10)))
            elif first_f < 0:
                first_f = 0
            feeds = objects[first_f:first_f + 10]
        else:
            first_f = 0
    page = int((first_f - math.fmod(first_f, 10)) / 10) + 1

    res = []
    for _ in feeds:
        obj_dict = _[0].to_dict(['eid', 'title', 'desc', 'text'])
        wide_info = EntityNews.get_wide_object(_[0].eid, ['image', 'priority'])
        obj_dict.update(wide_info)
        res.append(obj_dict)

    res_dict = OrderedDict([('count', count), ('page', page), ('result', res)])

    resp.body = obj_to_json(res_dict)
    resp.status = falcon.HTTP_200
Exemplo n.º 20
0
def dropStatistic(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))
        params['user_id'] = req.context['user_id']

        id = EntityRun.drop_from_json(params)

        resp.body = obj_to_json(id)
        resp.status = falcon.HTTP_200
        return

    except ValueError:
        resp.status = falcon.HTTP_405
        return
Exemplo n.º 21
0
def getMuseumById(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    id = getIntPathParam("Id", **request_handler_args)
    objects = EntityMuseum.get().filter_by(eid=id).all()

    wide_info = EntityMuseum.get_wide_object(
        id, ['image', 'game', 'location', 'logo'])

    res = []
    for _ in objects:
        obj_dict = _.to_dict(['eid', 'ownerid', 'name', 'desc'])
        obj_dict.update(wide_info)
        res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 22
0
def getScenarioUserById(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    id = getIntPathParam("scenarioId", **request_handler_args)
    if id is None:
        resp.status = falcon.HTTP_400
        return

    objects = EntityScenario.get_scenario_for_user(id)

    res = []
    for _ in objects:
        obj_dict = _.to_dict(['eid', 'json'])
        res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 23
0
def findLocationByName(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    start = getStringQueryParam("startswith", **request_handler_args)
    if start is None:
        resp.status = falcon.HTTP_400
        return
    with DBConnection() as session:
        objects = session.db.query(EntityLocation).filter(
            EntityLocation.name.startswith(start)).all()

    res = []
    for _ in objects:
        obj_dict = _.to_dict()
        res.append(obj_dict)

    resp.body = obj_to_json(res)
    resp.status = falcon.HTTP_200
Exemplo n.º 24
0
def getTapeLocations(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    first_l = getIntQueryParam('FirstLocation', **request_handler_args)
    last_l = getIntQueryParam('LastLocation', **request_handler_args)

    with DBConnection() as session:
        objects = session.db.query(EntityLocation).order_by(
            EntityLocation.name).all()
        count = objects.__len__()

    if first_l < 0:
        first_l = 0

    # if last_f isn't set (==-1), it is supposed to be an infinity
    if last_l == -1:
        locations = objects[first_l:]
    else:
        locations = objects[first_l:last_l + 1]

    if locations.__len__() == 0:
        if count > 0:
            if first_l > 0:
                first_l = min(int(first_l - math.fmod(first_l, 10)),
                              int(count - math.fmod(count, 10)))
            elif first_l < 0:
                first_l = 0
            locations = objects[first_l:first_l + 10]
        else:
            first_l = 0
    page = int((first_l - math.fmod(first_l, 10)) / 10) + 1

    res = []
    for _ in locations:
        obj_dict = _.to_dict()
        res.append(obj_dict)

    res_dict = OrderedDict([('count', count), ('page', page), ('result', res)])

    resp.body = obj_to_json(res_dict)
    resp.status = falcon.HTTP_200
Exemplo n.º 25
0
def updateScenario(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))

        id, props = EntityScenario.update_from_json(params)

        res = []
        if id:
            res.append(props)
            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 26
0
def updateGame(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    # email = req.context['email']
    # id_email = EntityUser.get_id_from_email(email)

    try:
        params = json.loads(req.stream.read().decode('utf-8'))
        feedback = getBoolQueryParam('feedback', **request_handler_args)

        # if params['id'] != id_email or not EntitySuperUser.is_id_super_admin(id_email):
        #    resp.status = falcon.HTTP_403
        #    return

        id = EntityGame.update_from_json(params)

        if id:
            objects = EntityGame.get().filter_by(eid=id).all()

            wide_info_arr = ['image', 'scenario', 'rating']
            if feedback:
                wide_info_arr = ['image', 'scenario', 'rating', 'comment']

            res = []
            for _ in objects:
                obj_dict = _.to_dict(
                    ['eid', 'ownerid', 'name', 'desc', 'active'])
                wide_info = EntityGame.get_wide_object(_.eid, wide_info_arr)
                obj_dict.update(wide_info)
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 27
0
def updateAgreement(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        text = getQueryParam('text', **request_handler_args)

        if text is not None and text.headers[
                'content-type'] == "text/plain" and text.filename[-3:] == "txt":

            _bytes = text.file.read()

            open('./agreement.txt', 'wb').write(_bytes)

            resp.body = obj_to_json([])
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 28
0
def deleteLocation(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    res = []
    id = getIntPathParam("locationId", **request_handler_args)
    if id is None:
        resp.status = falcon.HTTP_400
        return

    try:
        EntityLocation.delete(id)
    except FileNotFoundError:
        resp.status = falcon.HTTP_404
        return

    object = EntityLocation.get().filter_by(eid=id).all()
    if not len(object):
        resp.body = obj_to_json(res)
        resp.status = falcon.HTTP_200
        return

    resp.status = falcon.HTTP_400
Exemplo n.º 29
0
def addLocation(**request_handler_args):
    req = request_handler_args['req']
    resp = request_handler_args['resp']

    try:
        params = json.loads(req.stream.read().decode('utf-8'))
        id = EntityLocation.add_from_json(params)

        if id:
            objects = EntityLocation.get().filter_by(eid=id).all()

            res = []
            for _ in objects:
                obj_dict = _.to_dict()
                res.append(obj_dict)

            resp.body = obj_to_json(res)
            resp.status = falcon.HTTP_200
            return
    except ValueError:
        resp.status = falcon.HTTP_405
        return

    resp.status = falcon.HTTP_501
Exemplo n.º 30
0
def getVersion(**request_handler_args):
    resp = request_handler_args['resp']
    resp.status = falcon.HTTP_200
    with open("VERSION") as f:
        resp.body = obj_to_json({"version": f.read()[0:-1]})