Skip to content

Commit b3e3e15

Browse files
committed
Added history routes
1 parent 3f888fc commit b3e3e15

File tree

5 files changed

+105
-18
lines changed

5 files changed

+105
-18
lines changed

backend/PyMatcha/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
from PyMatcha.routes.api.profile.images import images_bp
180180
from PyMatcha.routes.api.search import search_bp
181181
from PyMatcha.routes.api.profile.block import profile_block_bp
182+
from PyMatcha.routes.api.history import history_bp
182183

183184
logging.debug("Registering Flask blueprints")
184185
application.register_blueprint(user_bp)
@@ -197,6 +198,7 @@
197198
application.register_blueprint(images_bp)
198199
application.register_blueprint(search_bp)
199200
application.register_blueprint(profile_block_bp)
201+
application.register_blueprint(history_bp)
200202

201203
if application.debug:
202204
logging.debug("Registering debug route")

backend/PyMatcha/models/user.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ def get_views(self):
245245
logging.debug("Getting all views for user profile {}".format(self.id))
246246
return View.get_multis(profile_id=self.id)
247247

248+
def get_view_history(self):
249+
return View.get_multis(viewer_id=self.id)
250+
248251
def get_reports_received(self):
249252
logging.debug("Getting all reports received for user {}".format(self.id))
250253
return Report.get_multis(reported_id=self.id)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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)

backend/PyMatcha/routes/api/like.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from PyMatcha.utils.errors import BadRequestError
1313
from PyMatcha.utils.errors import NotFoundError
1414
from PyMatcha.utils.success import Success
15-
from PyMatcha.utils.success import SuccessOutput
1615

1716
like_bp = Blueprint("like", __name__)
1817

@@ -75,12 +74,3 @@ def unlike_profile(uid):
7574
raise BadRequestError("You never liked this person in the first place.")
7675
Like.get_multi(liked_id=u.id, liker_id=current_user.id).delete()
7776
return Success(f"Unliked user {u.id}.")
78-
79-
80-
@like_bp.route("/likes", methods=["GET"])
81-
@jwt_required
82-
def see_my_likes():
83-
received = current_user.get_likes_received()
84-
sent = current_user.get_likes_sent()
85-
returned_dict = {"received": [r.to_dict() for r in received], "sent": [s.to_dict() for s in sent]}
86-
return SuccessOutput("likes", returned_dict)

backend/PyMatcha/routes/api/profile/view.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
profile_view_bp = Blueprint("profile_view", __name__)
2929

3030

31-
@profile_view_bp.route("/profile/views", methods=["GET"])
32-
@jwt_required
33-
def get_profile_views():
34-
profile_views = current_user.get_views()
35-
profile_views = [v.to_dict() for v in profile_views]
36-
return SuccessOutput("views", profile_views)
37-
38-
3931
@profile_view_bp.route("/profile/view/<uid>", methods=["GET"])
4032
@jwt_required
4133
def view_profile(uid):

0 commit comments

Comments
 (0)