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 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 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 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
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
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
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
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