Skip to content

Commit 5d0bb34

Browse files
authored
Merge pull request #356 from Seluj78/feature/notifications
2 parents 369825e + 9f7ca6f commit 5d0bb34

File tree

13 files changed

+283
-50
lines changed

13 files changed

+283
-50
lines changed

PyMatcha.postman_collection.json

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,6 @@
13141314
"",
13151315
"tests[\"Is email correct\"] = response.email == user_email",
13161316
"tests[\"Is username correct\"] = response.username == user_username",
1317-
"tests[\"Are tags present\"] = response.tags.length == 0",
13181317
"",
13191318
"pm.collectionVariables.set(\"user_id\", response.id)"
13201319
],
@@ -1801,7 +1800,6 @@
18011800
"",
18021801
"tests[\"Is email correct\"] = response.email == user_email",
18031802
"tests[\"Is username correct\"] = response.username == user_username",
1804-
"tests[\"Are tags present\"] = response.tags.length == 4",
18051803
"tests[\"User orientation is correct\"] = response.orientation == user_orientation",
18061804
"tests[\"User gender is correct\"] = response.gender == user_gender",
18071805
"pm.collectionVariables.set(\"user_id\", response.id)"
@@ -6792,137 +6790,137 @@
67926790
],
67936791
"variable": [
67946792
{
6795-
"id": "84e910f9-4c08-4246-902f-0de6e1ea294e",
6793+
"id": "77b59289-361a-4042-9d17-5ce9094569c1",
67966794
"key": "host",
67976795
"value": "http://127.0.0.1:5000"
67986796
},
67996797
{
6800-
"id": "862f3d2c-4062-4687-b54b-beba8997fa14",
6798+
"id": "1132fe17-e51a-4216-a987-076b9fc84cbc",
68016799
"key": "user_id",
68026800
"value": ""
68036801
},
68046802
{
6805-
"id": "817cc4dd-f982-48bd-a2be-d1a654ea54fd",
6803+
"id": "eb6bb7f3-ee7d-4baa-8904-8641b51dfd3c",
68066804
"key": "user_email",
68076805
"value": "foo@example.org"
68086806
},
68096807
{
6810-
"id": "b20f7a10-fb29-42aa-89e8-2f85b260407a",
6808+
"id": "853fc8a6-589c-4c5a-90ee-a9099a5013cc",
68116809
"key": "user_username",
68126810
"value": "foo"
68136811
},
68146812
{
6815-
"id": "6c4f48fc-c6f6-4bce-a285-4ac93be46bd5",
6813+
"id": "3fa425fa-ecf2-488a-b447-7b0ccd98a284",
68166814
"key": "user_password",
68176815
"value": "admin"
68186816
},
68196817
{
6820-
"id": "2e641600-3581-4b3d-b812-de9e8d91ef40",
6818+
"id": "964625a3-340c-4bf1-8e91-abaeb3145ac7",
68216819
"key": "user_firstname",
68226820
"value": "Foo"
68236821
},
68246822
{
6825-
"id": "7c71bf8a-5d8e-49eb-921a-49ce8eb2e025",
6823+
"id": "6e8cd344-9b65-483c-b5a2-ded746b45041",
68266824
"key": "user_lastname",
68276825
"value": "Bar"
68286826
},
68296827
{
6830-
"id": "d3eb6bf8-6e58-4848-aa15-7e3d970a3d17",
6828+
"id": "5d912e78-090a-4e10-a896-8e73f692124b",
68316829
"key": "debug_token",
68326830
"value": "xX69jules69Xx"
68336831
},
68346832
{
6835-
"id": "750efa6b-eb7f-49b3-b273-532bbd3c5a21",
6833+
"id": "3f5efb62-435b-49ca-992b-7bf6e3cd9544",
68366834
"key": "user_access_token",
68376835
"value": ""
68386836
},
68396837
{
6840-
"id": "eafd1b95-9189-42e2-ba9a-4253ad877a9b",
6838+
"id": "75a3bc19-f99d-4741-b5d7-906c8516c800",
68416839
"key": "user_refresh_token",
68426840
"value": ""
68436841
},
68446842
{
6845-
"id": "b6bb8998-fc1d-404c-bc38-bc607231ac08",
6843+
"id": "0f9f831c-f484-4cfc-b66f-39905cbd3c5b",
68466844
"key": "expired_token",
68476845
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU"
68486846
},
68496847
{
6850-
"id": "2292884f-f26e-4dca-bf5a-2dbd6931b7d6",
6848+
"id": "444b3620-1eea-4289-811d-3e3cb92fdd42",
68516849
"key": "user_orientation",
68526850
"value": "heterosexual"
68536851
},
68546852
{
6855-
"id": "0a58f34f-09e7-4a30-8788-8eae5ddbbfdd",
6853+
"id": "04dab3b8-ec1e-48cc-9341-81b7a0d6629c",
68566854
"key": "user_bio",
68576855
"value": "Lorem Ipsum is the single greatest threat. We are not - we are not keeping up with other websites. Lorem Ipsum best not make any more threats to your website. It will be met with fire and fury like the world has never seen. Does everybody know that pig named Lorem Ipsum? An ‘extremely credible source’ has called my office and told me that Barack Obama’s placeholder text is a fraud."
68586856
},
68596857
{
6860-
"id": "26fe27b4-a059-41fa-be5d-6805e234c9a9",
6858+
"id": "fa0ace2d-fc85-4bdc-ac91-962598607bcb",
68616859
"key": "user_gender",
68626860
"value": "male"
68636861
},
68646862
{
6865-
"id": "6fd49a77-f3e7-43bd-8134-289d7c79c748",
6863+
"id": "e1dfcdb9-a32f-4cb2-976b-0b3c459b7cb7",
68666864
"key": "user_birthdate",
68676865
"value": "06/04/1998"
68686866
},
68696867
{
6870-
"id": "2146206a-faf6-4ddc-8fa1-37f987aceeb2",
6868+
"id": "bcc67554-7f8d-429d-9be6-ac51beae6392",
68716869
"key": "user_lat",
68726870
"value": "44.8404"
68736871
},
68746872
{
6875-
"id": "4ab98f8d-f0e9-4387-83b6-ab9bd3616485",
6873+
"id": "bd3aa75a-62d2-4273-a48b-f2776e9c2851",
68766874
"key": "user_lng",
68776875
"value": "-0.5805"
68786876
},
68796877
{
6880-
"id": "737bac0f-640a-48ff-901a-0f014647f9a1",
6878+
"id": "94b6ebf4-a1bf-40d0-aecf-0351f97f02a7",
68816879
"key": "user_ip",
68826880
"value": "77.205.46.181"
68836881
},
68846882
{
6885-
"id": "2c109873-7286-49ef-87d3-ce335ddca6fa",
6883+
"id": "39f5a6a2-e1a4-46e0-ade3-1da7673aeed2",
68866884
"key": "user_username2",
68876885
"value": "FooBar"
68886886
},
68896887
{
6890-
"id": "9f95a3c7-9746-4f35-a0ba-24680ae8329b",
6888+
"id": "f9693eeb-d746-440c-b388-e45fa31f4f47",
68916889
"key": "user_email2",
68926890
"value": "bar@example.org"
68936891
},
68946892
{
6895-
"id": "89c9863c-bb61-4920-86a2-5c926191db43",
6893+
"id": "2a66170a-b518-4d27-818e-f476f14bf64d",
68966894
"key": "user_password2",
68976895
"value": "dolphin2"
68986896
},
68996897
{
6900-
"id": "ff2e7ef9-4614-49ed-9d45-0fcc9a319899",
6898+
"id": "5fcb9909-4c30-434a-84ed-977a1c249e96",
69016899
"key": "user_first_name2",
69026900
"value": "Foo2"
69036901
},
69046902
{
6905-
"id": "67bed50e-fd6d-4bc5-a352-9083bc7f62ee",
6903+
"id": "145f67a8-6f56-4889-a47c-d5e408d034c6",
69066904
"key": "user_last_name2",
69076905
"value": "Bar2"
69086906
},
69096907
{
6910-
"id": "1284f930-b60b-4956-885a-557b2202fbb1",
6908+
"id": "9ed484b6-9bd8-4456-8149-e801c22595ee",
69116909
"key": "user_bio2",
69126910
"value": "Could you rotate the picture to show the other side of the room? thanks for taking the time to make the website, but i already made it in wix or I know somebody who can do this for a reasonable cost. Labrador submit your meaningless business jargon to be used on the site! nor start on it today and we will talk about what i want next time and it's great, can you add a beard though . Needs to be sleeker make it original i know you've made thirty iterations but can we go back to the first one that was the best version. Are you busy this weekend? I have a new project with a tight deadline im not sure, try something else we are your relatives, and I know somebody who can do this for a reasonable cost, yet that's going to be a chunk of change can you rework to make the pizza look more delicious. Labrador I like it, but can the snow look a little warmer, concept is bang on, but can we look at a better execution, and the website doesn't have the theme i was going for other agencies charge much lesser. Can you make the blue bluer? can you punch up the fun level on these icons but is there a way we can make the page feel more introductory without being cheesy. There is too much white space is this the best we can do try a more powerful colour thanks for taking the time to make the website, but i already made it in wix, the flier should feel like a warm handshake can you please change the color theme of the website to pink and purple? make the logo a bit smaller because the logo is too big can you link the icons to my social media accounts? oh and please put pictures of cats everywhere. There are more projects lined up charge extra the next time the website doesn't have the theme i was going for, I need a website. How much will it cost, or you can get my logo from facebook the website doesn't have the theme i was going for this is just a 5 minutes job. Can you help me out? you will get a lot of free exposure doing this this red is too red. Something summery; colourful. Can you punch up the fun level on these icons we are a big name to have in your portfolio we don't need a contract, do we or could you rotate the picture to show the other side of the room? for can you make it look more designed , the flier should feel like a warm handshake can it handle a million in one go. Needs to be sleeker. Do less with more can it be more retro. You might wanna give it another shot i love it, but can you invert all colors? was i smoking crack when i sent this? hahaha!. I need a website. How much will it cost. Thanks for taking the time to make the website, but i already made it in wix are you busy this weekend? I have a new project with a tight deadline, and try making it a bit less blah just do what you think. I trust you. Anyway, you are the designer, you know what to do make it original I like it, but can the snow look a little warmer theres all this spanish text on my site can it handle a million in one go but there are more projects lined up charge extra the next time, so i was wondering if my cat could be placed over the logo in the flyer. "
69136911
},
69146912
{
6915-
"id": "93e7ae24-d669-4367-9627-0cccb06cf720",
6913+
"id": "fb197ca8-e553-4180-babb-e2c9fbc0fd1d",
69166914
"key": "user_gender2",
69176915
"value": "other"
69186916
},
69196917
{
6920-
"id": "8cd1ec37-26e0-44fc-8cf9-197e14f6f082",
6918+
"id": "92a77c91-6269-484d-8b34-9d2949b3d2c7",
69216919
"key": "user_orientation2",
69226920
"value": "bisexual"
69236921
},
69246922
{
6925-
"id": "0dd4afab-bfc5-4cfe-93bf-e61c575ea3bb",
6923+
"id": "72196e46-d068-4cc1-a773-912bae378d55",
69266924
"key": "user_birthdate2",
69276925
"value": "01/01/1996"
69286926
}

backend/PyMatcha/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
from PyMatcha.routes.api.search import search_bp
181181
from PyMatcha.routes.api.profile.block import profile_block_bp
182182
from PyMatcha.routes.api.history import history_bp
183+
from PyMatcha.routes.api.notifications import notifications_bp
183184

184185
logging.debug("Registering Flask blueprints")
185186
application.register_blueprint(user_bp)
@@ -199,6 +200,7 @@
199200
application.register_blueprint(search_bp)
200201
application.register_blueprint(profile_block_bp)
201202
application.register_blueprint(history_bp)
203+
application.register_blueprint(notifications_bp)
202204

203205
if application.debug:
204206
logging.debug("Registering debug route")
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
PyMatcha - A Python Dating Website
3+
Copyright (C) 2018-2019 jlasne/gmorer
4+
<jlasne@student.42.fr> - <lauris.skraucis@gmail.com>
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
"""
19+
from __future__ import annotations
20+
21+
import logging
22+
from datetime import datetime
23+
from typing import Optional
24+
25+
from PyMatcha.utils import create_notifications_table
26+
from PyMatcha.utils.orm import Field
27+
from PyMatcha.utils.orm import Model
28+
29+
30+
class Notification(Model):
31+
table_name = "notifications"
32+
33+
id = Field(int, modifiable=False)
34+
user_id = Field(int)
35+
dt_received = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
36+
content = Field(str)
37+
type = Field(str)
38+
is_seen = Field(bool)
39+
link_to = Field(str)
40+
41+
@staticmethod
42+
def create(
43+
trigger_id: int,
44+
user_id: int,
45+
content: str,
46+
type: str,
47+
link_to: Optional[str],
48+
is_seen: bool = False,
49+
dt_received: datetime = datetime.utcnow(),
50+
) -> Optional[Notification]:
51+
if type not in ["match", "like", "superlike", "unlike", "view", "message", "message_like"]:
52+
raise ValueError(
53+
"type must be one of ['match', 'like', 'superlike', 'unlike', 'view', 'message', 'message_like']"
54+
)
55+
from PyMatcha.models.user import get_user # noqa
56+
57+
blocked_ids = [block.blocked_id for block in get_user(user_id).get_blocks()]
58+
if trigger_id in blocked_ids:
59+
return None
60+
new_notif = Notification(
61+
user_id=user_id, content=content, type=type, link_to=link_to, is_seen=is_seen, dt_received=dt_received
62+
)
63+
new_notif.save()
64+
logging.debug("Creating new notification")
65+
return new_notif
66+
67+
@classmethod
68+
def create_table(cls):
69+
create_notifications_table(cls.db)

backend/PyMatcha/models/user.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from PyMatcha.models.like import Like
3232
from PyMatcha.models.match import Match
3333
from PyMatcha.models.message import Message
34+
from PyMatcha.models.notification import Notification
3435
from PyMatcha.models.report import Report
3536
from PyMatcha.models.tag import Tag
3637
from PyMatcha.models.view import View
@@ -267,6 +268,12 @@ def get_likes_sent(self):
267268
def get_blocks(self):
268269
return Block.get_multis(blocker_id=self.id)
269270

271+
def get_all_notifications(self):
272+
return Notification.get_multis(user_id=self.id)
273+
274+
def get_unread_notifications(self):
275+
return Notification.get_multis(user_id=self.id, is_seen=False)
276+
270277
def already_likes(self, liked_id: int) -> bool:
271278
with self.db.cursor() as c:
272279
c.execute(

backend/PyMatcha/routes/api/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from PyMatcha.utils.success import SuccessOutput
88

99

10-
history_bp = Blueprint("history_bp", __name__)
10+
history_bp = Blueprint("history", __name__)
1111

1212

1313
@history_bp.route("/history/viewed")

backend/PyMatcha/routes/api/like.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from flask_jwt_extended import jwt_required
88
from PyMatcha.models.like import Like
99
from PyMatcha.models.match import Match
10+
from PyMatcha.models.notification import Notification
1011
from PyMatcha.models.user import get_user
1112
from PyMatcha.utils.decorators import validate_params
1213
from PyMatcha.utils.errors import BadRequestError
@@ -53,11 +54,46 @@ def like_profile(uid):
5354

5455
if u.already_likes(current_user.id):
5556
Match.create(user_1=current_user.id, user_2=u.id)
57+
Notification.create(
58+
trigger_id=current_user.id,
59+
user_id=u.id,
60+
content=f"{current_user.first_name} liked you! Go check them out!",
61+
type="like",
62+
link_to=f"users/{current_user.id}",
63+
)
64+
Notification.create(
65+
trigger_id=current_user.id,
66+
user_id=u.id,
67+
content=f"You and {current_user.first_name} matched!",
68+
type="match",
69+
link_to=f"conversation/{current_user.id}",
70+
)
71+
Notification.create(
72+
trigger_id=u.id,
73+
user_id=current_user.id,
74+
content=f"You and {u.first_name} matched!",
75+
type="match",
76+
link_to=f"conversation/{u.id}",
77+
)
5678
return Success("It's a match !")
5779

5880
if is_superlike:
81+
Notification.create(
82+
trigger_id=current_user.id,
83+
user_id=u.id,
84+
content=f"{current_user.first_name} superliked you 😏! Go check them out!",
85+
type="superlike",
86+
link_to=f"users/{current_user.id}",
87+
)
5988
return Success("Superliked user.")
6089
else:
90+
Notification.create(
91+
trigger_id=current_user.id,
92+
user_id=u.id,
93+
content=f"{current_user.first_name} liked you! Go check them out!",
94+
type="like",
95+
link_to=f"users/{current_user.id}",
96+
)
6197
return Success("Liked user.")
6298

6399

@@ -73,4 +109,13 @@ def unlike_profile(uid):
73109
if not current_user.already_likes(u.id):
74110
raise BadRequestError("You never liked this person in the first place.")
75111
Like.get_multi(liked_id=u.id, liker_id=current_user.id).delete()
112+
113+
Notification.create(
114+
trigger_id=current_user.id,
115+
user_id=u.id,
116+
content=f"{current_user.first_name} unliked you.",
117+
type="unlike",
118+
link_to=None,
119+
)
120+
76121
return Success(f"Unliked user {u.id}.")

0 commit comments

Comments
 (0)