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
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
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
def get_run(_eid, _id): objects = PropRun.get_object_property(_eid, _id) passed = [] process = [] bonus = 0 ts = time.time() for o in objects: games = EntityGame.get().filter_by(eid=int(o['game_id'])).all() if len(games): for g in games: obj_dict = g.to_dict( ['eid', 'ownerid', 'name', 'desc']) wide_info = EntityGame.get_wide_object( g.eid, ['image', 'scenario', 'rating']) obj_dict.update(wide_info) if o['best_time'] != '0': obj_dict2 = g.to_dict( ['eid', 'ownerid', 'name', 'desc']) obj_dict2.update(wide_info) likes = PropLike.get_like_user_related( obj_dict2['eid'], PROPNAME_MAPPING['rating'], eid) comments = PropComment.get_comment_user_related( obj_dict2['eid'], PROPNAME_MAPPING['comment'], eid) obj_dict2.update({ 'best_time': o['best_time'], 'rate': likes, 'comment': comments }) passed.append(obj_dict2) bonus += int(o['bonus']) if o['status'] == 'process': d_time = datetime.datetime.fromtimestamp(ts) - \ datetime.datetime.strptime(o['start_time'][:-6], '%Y-%m-%d %H:%M:%S') obj_dict.update({ 'step_passed': o['step_passed'], 'delta_time': _interval_to_string(d_time) }) process.append(obj_dict) return { 'game_passed': passed, 'game_process': process, 'bonus': bonus }
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
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