def skills(self, body: http.Body): """ Searching for a user in the DB. :return: """ payload = json.loads(body.decode()) if payload['skill'] is None: return Response({'message': 'The skill property is empty'}, status=401) # Get the search text. text = payload['skill'] # Init the query operation. profile = Profile() profiles = profile \ .getTable() \ .filter( lambda document: document['skills'].contains(lambda skills: skills['skill'].match(text)) ) \ .run(profile.r) # Search in the text in the name, title, position, summary. results = [] for profile in profiles: profile['match'] = self.calculate_score(text, profile) results.append(profile) return results
def parse(self, body: http.Body) -> typing.Any: if not body: raise exceptions.BadRequest(detail='Empty JSON') try: return json.loads(body.decode('utf-8')) except json.JSONDecodeError: raise exceptions.BadRequest(detail='Invalid JSON')
def name(self, body: http.Body): """ Searching for a name in the DB. :return: """ payload = json.loads(body.decode()) if payload['name'] is None: return Response({'message': 'The name property is empty'}, status=401) # Get the search text. text = payload['name'] # Init the query operation. profile = Profile() profiles = profile \ .getTable() \ .filter( lambda document: document['name'].match(text) | document['current_position'].match(text) | document['current_title'].match(text) | document['summary'].match(text) ) \ .run(profile.r) # Search in the text in the name, title, position, summary. results = [] for profile in profiles: results.append(profile) return results
def new_file_web(body: http.Body, mongo: Database): body = body.split(b"\r\n")[4:] data = [] for block in body: if block.startswith(b"------WebKitFormBoundary"): break else: data.append(block) data = b"\r\n".join(data) try: data = json.loads(data.decode("utf-8")) except json.JSONDecodeError: return {"status": 0, "code": 500, "msg": "Not valid json format"} file_id = uuid4().hex data['fileId'] = file_id mongo.strategy.insert_one(data) return {"status": 1, "code": 200, "fileId": file_id}
def get_body(body: http.Body): return {'body': body.decode('utf-8')}
def get_body(body: http.Body) -> http.Response: return http.Response({'body': body.decode('utf-8')})
def get_body(body: http.Body): return {"body": body.decode("utf-8")}