def get(self): """ Search active projects --- tags: - search produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token type: string default: Token sessionTokenHere== - in: header name: Accept-Language description: Language user is requesting type: string required: true default: en - in: query name: mapperLevel type: string default: BEGINNER - in: query name: mappingTypes type: string default: ROADS,BUILDINGS - in: query name: organisationTag type: string default: red cross - in: query name: campaignTag type: string default: malaria - in: query name: page description: Page of results user requested type: integer default: 1 - in: query name: textSearch description: text to search type: string default: serbia - in: query name: projectStatuses description: Authenticated PMs can search for archived or draft statuses type: string responses: 200: description: Projects found 404: description: No projects found 500: description: Internal Server Error """ try: search_dto = ProjectSearchDTO() search_dto.preferred_locale = request.environ.get( 'HTTP_ACCEPT_LANGUAGE') search_dto.mapper_level = request.args.get('mapperLevel') search_dto.organisation_tag = request.args.get('organisationTag') search_dto.campaign_tag = request.args.get('campaignTag') search_dto.page = int( request.args.get('page')) if request.args.get('page') else 1 search_dto.text_search = request.args.get('textSearch') # See https://github.com/hotosm/tasking-manager/pull/922 for more info try: verify_token( request.environ.get('HTTP_AUTHORIZATION').split(None, 1)[1]) if UserService.is_user_a_project_manager( tm.authenticated_user_id): search_dto.is_project_manager = True except: pass mapping_types_str = request.args.get('mappingTypes') if mapping_types_str: search_dto.mapping_types = map( str, mapping_types_str.split(',')) # Extract list from string project_statuses_str = request.args.get('projectStatuses') if project_statuses_str: search_dto.project_statuses = map( str, project_statuses_str.split(',')) search_dto.validate() except DataError as e: current_app.logger.error(f'Error validating request: {str(e)}') return str(e), 400 try: results_dto = ProjectSearchService.search_projects(search_dto) return results_dto.to_primitive(), 200 except NotFound: return {"Error": "No projects found"}, 404 except Exception as e: error_msg = f'Project GET - unhandled error: {str(e)}' current_app.logger.critical(error_msg) return {"error": error_msg}, 500
def get(self): """ Search active projects --- tags: - search produces: - application/json parameters: - in: header name: Accept-Language description: Language user is requesting type: string required: true default: en - in: query name: mapperLevel type: string default: BEGINNER - in: query name: mappingTypes type: string default: ROADS,BUILDINGS - in: query name: organisationTag type: string default: red cross - in: query name: campaignTag type: string default: malaria - in: query name: page description: Page of results user requested type: integer default: 1 - in: query name: textSearch description: text to search type: string default: serbia responses: 200: description: Projects found 404: description: No projects found 500: description: Internal Server Error """ try: search_dto = ProjectSearchDTO() search_dto.preferred_locale = request.environ.get('HTTP_ACCEPT_LANGUAGE') search_dto.mapper_level = request.args.get('mapperLevel') search_dto.organisation_tag = request.args.get('organisationTag') search_dto.campaign_tag = request.args.get('campaignTag') search_dto.page = int(request.args.get('page')) if request.args.get('page') else 1 search_dto.text_search = request.args.get('textSearch') mapping_types_str = request.args.get('mappingTypes') if mapping_types_str: search_dto.mapping_types = map(str, mapping_types_str.split(',')) # Extract list from string search_dto.validate() except DataError as e: current_app.logger.error(f'Error validating request: {str(e)}') return str(e), 400 try: results_dto = ProjectSearchService.search_projects(search_dto) return results_dto.to_primitive(), 200 except NotFound: return {"Error": "No projects found"}, 404 except Exception as e: error_msg = f'Project GET - unhandled error: {str(e)}' current_app.logger.critical(error_msg) return {"error": error_msg}, 500