|
| 1 | +from flask import Blueprint |
| 2 | +from flask_jwt_extended import current_user |
| 3 | +from flask_jwt_extended import jwt_required |
| 4 | +from PyMatcha.models.user import User |
| 5 | +from PyMatcha.utils.match_score import _get_common_tags |
| 6 | +from PyMatcha.utils.match_score import _get_distance |
| 7 | +from PyMatcha.utils.success import SuccessOutput |
| 8 | + |
| 9 | + |
| 10 | +history_bp = Blueprint("history_bp", __name__) |
| 11 | + |
| 12 | + |
| 13 | +@history_bp.route("/history/viewed") |
| 14 | +@jwt_required |
| 15 | +def history_viewed_people(): |
| 16 | + views = current_user.get_view_history() |
| 17 | + viewed_people = [] |
| 18 | + for view in views: |
| 19 | + user = User.get(id=view.profile_id) |
| 20 | + distance = _get_distance(current_user.geohash, user.geohash) |
| 21 | + user_tags = [t.name for t in user.get_tags()] |
| 22 | + current_user_tags = [t.name for t in current_user.get_tags()] |
| 23 | + common_tags = _get_common_tags(current_user_tags, user_tags) |
| 24 | + user_dict = user.to_dict() |
| 25 | + user_dict["common_tags"] = common_tags |
| 26 | + user_dict["distance"] = distance |
| 27 | + viewed_people.append(user_dict) |
| 28 | + return SuccessOutput("viewed", viewed_people) |
| 29 | + |
| 30 | + |
| 31 | +@history_bp.route("/history/viewed/me", methods=["GET"]) |
| 32 | +@jwt_required |
| 33 | +def history_viewed_me(): |
| 34 | + views = current_user.get_views() |
| 35 | + viewed_people = [] |
| 36 | + for view in views: |
| 37 | + user = User.get(id=view.viewer_id) |
| 38 | + distance = _get_distance(current_user.geohash, user.geohash) |
| 39 | + user_tags = [t.name for t in user.get_tags()] |
| 40 | + current_user_tags = [t.name for t in current_user.get_tags()] |
| 41 | + common_tags = _get_common_tags(current_user_tags, user_tags) |
| 42 | + user_dict = user.to_dict() |
| 43 | + user_dict["common_tags"] = common_tags |
| 44 | + user_dict["distance"] = distance |
| 45 | + viewed_people.append(user_dict) |
| 46 | + return SuccessOutput("viewed_me", viewed_people) |
| 47 | + |
| 48 | + |
| 49 | +@history_bp.route("/history/liked", methods=["GET"]) |
| 50 | +@jwt_required |
| 51 | +def history_liked_people(): |
| 52 | + likes = current_user.get_likes_sent() |
| 53 | + liked_people = [] |
| 54 | + for like in likes: |
| 55 | + user = User.get(id=like.liked_id) |
| 56 | + distance = _get_distance(current_user.geohash, user.geohash) |
| 57 | + user_tags = [t.name for t in user.get_tags()] |
| 58 | + current_user_tags = [t.name for t in current_user.get_tags()] |
| 59 | + common_tags = _get_common_tags(current_user_tags, user_tags) |
| 60 | + user_dict = user.to_dict() |
| 61 | + user_dict["common_tags"] = common_tags |
| 62 | + user_dict["distance"] = distance |
| 63 | + liked_people.append(user_dict) |
| 64 | + return SuccessOutput("liked", liked_people) |
| 65 | + |
| 66 | + |
| 67 | +@history_bp.route("/history/liked/me", methods=["GET"]) |
| 68 | +@jwt_required |
| 69 | +def history_liked_me(): |
| 70 | + likes = current_user.get_likes_received() |
| 71 | + liked_people = [] |
| 72 | + for like in likes: |
| 73 | + user = User.get(id=like.liker_id) |
| 74 | + distance = _get_distance(current_user.geohash, user.geohash) |
| 75 | + user_tags = [t.name for t in user.get_tags()] |
| 76 | + current_user_tags = [t.name for t in current_user.get_tags()] |
| 77 | + common_tags = _get_common_tags(current_user_tags, user_tags) |
| 78 | + user_dict = user.to_dict() |
| 79 | + user_dict["common_tags"] = common_tags |
| 80 | + user_dict["distance"] = distance |
| 81 | + liked_people.append(user_dict) |
| 82 | + return SuccessOutput("liked_me", liked_people) |
| 83 | + |
| 84 | + |
| 85 | +@history_bp.route("/history/blocked", methods=["GET"]) |
| 86 | +@jwt_required |
| 87 | +def history_blocked(): |
| 88 | + blocks = current_user.get_blocks() |
| 89 | + blocked_people = [] |
| 90 | + for block in blocks: |
| 91 | + user = User.get(id=block.blocked_id) |
| 92 | + distance = _get_distance(current_user.geohash, user.geohash) |
| 93 | + user_tags = [t.name for t in user.get_tags()] |
| 94 | + current_user_tags = [t.name for t in current_user.get_tags()] |
| 95 | + common_tags = _get_common_tags(current_user_tags, user_tags) |
| 96 | + user_dict = user.to_dict() |
| 97 | + user_dict["common_tags"] = common_tags |
| 98 | + user_dict["distance"] = distance |
| 99 | + blocked_people.append(user_dict) |
| 100 | + return SuccessOutput("liked_me", blocked_people) |
0 commit comments