Skip to content

Commit 7af5b95

Browse files
committed
Added distance and common tags to /users/<id>
1 parent c819f0a commit 7af5b95

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

backend/PyMatcha/routes/api/user.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
from flask import Blueprint
2020
from flask import current_app
2121
from flask import jsonify
22+
from flask_jwt_extended import current_user
2223
from flask_jwt_extended import jwt_required
2324
from PyMatcha.models.user import get_user
2425
from PyMatcha.models.user import User
2526
from PyMatcha.utils.errors import NotFoundError
26-
27+
from PyMatcha.utils.match_score import _get_common_tags
28+
from PyMatcha.utils.match_score import _get_distance
2729

2830
user_bp = Blueprint("user", __name__)
2931

@@ -47,7 +49,12 @@ def get_one_user(uid):
4749
pass
4850
else:
4951
current_app.logger.info(f"Returning info on user {uid}")
50-
return jsonify(u.to_dict())
52+
returned_dict = u.to_dict()
53+
user_tags = [t.name for t in u.get_tags()]
54+
current_user_tags = [t.name for t in current_user.get_tags()]
55+
returned_dict["distance"] = _get_distance(current_user.geohash, u.geohash)
56+
returned_dict["common_tags"] = _get_common_tags(current_user_tags, user_tags)
57+
return jsonify(returned_dict)
5158

5259

5360
@user_bp.route("/users/online", methods=["GET"])

0 commit comments

Comments
 (0)