Exemplo n.º 1
0
 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 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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
def get_body(body: http.Body):
    return {'body': body.decode('utf-8')}
Exemplo n.º 5
0
def get_body(body: http.Body) -> http.Response:
    return http.Response({'body': body.decode('utf-8')})
Exemplo n.º 6
0
def get_body(body: http.Body) -> http.Response:
    return http.Response({'body': body.decode('utf-8')})
Exemplo n.º 7
0
def get_body(body: http.Body):
    return {"body": body.decode("utf-8")}