|
1 | 1 | import datetime |
| 2 | +import json |
2 | 3 |
|
3 | 4 | from flask import Blueprint |
4 | 5 | from flask import request |
5 | 6 | from flask_jwt_extended import current_user |
6 | 7 | from flask_jwt_extended import jwt_required |
| 8 | +from PyMatcha import redis |
7 | 9 | from PyMatcha.utils.decorators import validate_params |
8 | 10 | from PyMatcha.utils.errors import BadRequestError |
9 | 11 | from PyMatcha.utils.match_score import _get_common_tags |
10 | 12 | from PyMatcha.utils.match_score import _get_distance |
11 | 13 | from PyMatcha.utils.match_score import _get_gender_query |
12 | 14 | from PyMatcha.utils.success import SuccessOutput |
| 15 | +from PyMatcha.utils.tasks import calc_search_min_max |
13 | 16 |
|
14 | 17 | search_bp = Blueprint("search", __name__) |
15 | 18 |
|
@@ -71,16 +74,29 @@ def search(): |
71 | 74 | if max_distance != -1: |
72 | 75 | continue |
73 | 76 | else: |
| 77 | + distance = -1 |
74 | 78 | if max_distance != -1: |
75 | 79 | raise BadRequestError("user needs to sets his location first") |
76 | 80 |
|
77 | 81 | user_tags = [t.name for t in user.get_tags()] |
78 | 82 | common_tags = _get_common_tags(tags, user_tags) |
79 | 83 | if not common_tags: |
| 84 | + common_tags = [] |
80 | 85 | if tags: |
81 | 86 | continue |
82 | 87 |
|
83 | 88 | user_dict = user.to_dict() |
84 | | - user_dict.update({"distance": distance, "common_tags": common_tags}) |
| 89 | + user_dict["distance"] = distance |
| 90 | + user_dict["common_tags"] = common_tags |
85 | 91 | returned_list.append(user_dict) |
86 | 92 | return SuccessOutput("search_results", returned_list) |
| 93 | + |
| 94 | + |
| 95 | +@search_bp.route("/search/values", methods=["GET"]) |
| 96 | +def get_min_maxes_values(): |
| 97 | + try: |
| 98 | + minmax = json.loads(redis.get("search_minmax")) |
| 99 | + except TypeError: |
| 100 | + calc_search_min_max() |
| 101 | + minmax = json.loads(redis.get("search_minmax")) |
| 102 | + return SuccessOutput("search_minmax", minmax) |
0 commit comments