Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tddd80-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Gullander
tddd80-server
Commits
eb76bbd2
Commit
eb76bbd2
authored
2 months ago
by
kevgu916
Browse files
Options
Downloads
Patches
Plain Diff
Puts
parent
7a038dc0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.py
+10
-5
10 additions, 5 deletions
app.py
with
10 additions
and
5 deletions
app.py
+
10
−
5
View file @
eb76bbd2
...
@@ -141,12 +141,16 @@ class Notification(db.Model):
...
@@ -141,12 +141,16 @@ class Notification(db.Model):
user
=
db
.
relationship
(
'
User
'
,
backref
=
db
.
backref
(
'
notifications
'
,
lazy
=
True
))
user
=
db
.
relationship
(
'
User
'
,
backref
=
db
.
backref
(
'
notifications
'
,
lazy
=
True
))
def
create_notification
(
user_id
,
message
):
def
create_notification
(
user_id
,
message
,
username
):
# Hämta användaren från databasen
# Hämta användaren från databasen
# Det är bara relevant att spara 20 notifikationer, därför raderar vi om det är över 30.
user
=
db
.
session
.
get
(
User
,
user_id
)
user
=
db
.
session
.
get
(
User
,
user_id
)
if
user
:
if
user
:
# Kolla om username matchar användarens username (alltså att användaren försöker skapa notis till sig själv)
if
user
.
username
==
username
:
# Om samma användare, gör inget
return
# Skapa en ny notis
# Skapa en ny notis
new_notification
=
Notification
(
user_id
=
user_id
,
message
=
message
)
new_notification
=
Notification
(
user_id
=
user_id
,
message
=
message
)
...
@@ -162,6 +166,7 @@ def create_notification(user_id, message):
...
@@ -162,6 +166,7 @@ def create_notification(user_id, message):
db
.
session
.
delete
(
oldest_notification
)
db
.
session
.
delete
(
oldest_notification
)
db
.
session
.
commit
()
db
.
session
.
commit
()
# Klass för kommentarer
# Klass för kommentarer
class
Comment
(
db
.
Model
):
class
Comment
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
...
@@ -417,7 +422,7 @@ def follow():
...
@@ -417,7 +422,7 @@ def follow():
follower
.
follow
(
following
)
follower
.
follow
(
following
)
db
.
session
.
commit
()
db
.
session
.
commit
()
create_notification
(
following
.
id
,
f
"
{
follower
.
username
}
just started following you
"
)
create_notification
(
following
.
id
,
f
"
{
follower
.
username
}
just started following you
"
,
follower
.
username
)
return
jsonify
({
"
message
"
:
f
"
{
follower
.
username
}
is now following
{
following
.
username
}
"
}),
200
return
jsonify
({
"
message
"
:
f
"
{
follower
.
username
}
is now following
{
following
.
username
}
"
}),
200
...
@@ -603,7 +608,7 @@ def add_comment():
...
@@ -603,7 +608,7 @@ def add_comment():
db
.
session
.
commit
()
db
.
session
.
commit
()
# Skapa en notis för användaren som har reviewn.
# Skapa en notis för användaren som har reviewn.
create_notification
(
review
.
user_id
,
f
"
{
user
.
username
}
commented
'
{
comment_text
}
'
on your review.
"
)
create_notification
(
review
.
user_id
,
f
"
{
user
.
username
}
commented
'
{
comment_text
}
'
on your review.
"
,
user
.
username
)
return
jsonify
({
return
jsonify
({
"
message
"
:
"
Comment added successfully
"
,
"
message
"
:
"
Comment added successfully
"
,
...
@@ -696,7 +701,7 @@ def like_review():
...
@@ -696,7 +701,7 @@ def like_review():
db
.
session
.
commit
()
db
.
session
.
commit
()
# Skapa en notis för användaren som har reviewn.
# Skapa en notis för användaren som har reviewn.
create_notification
(
review
.
user_id
,
f
"
{
user
.
username
}
liked your review
'
{
review
.
drink_name
}
'"
)
create_notification
(
review
.
user_id
,
f
"
{
user
.
username
}
liked your review
'
{
review
.
drink_name
}
'"
,
user
.
username
)
return
jsonify
({
"
message
"
:
f
"
Review
{
review
.
id
}
liked by
{
user
.
username
}
"
}),
200
return
jsonify
({
"
message
"
:
f
"
Review
{
review
.
id
}
liked by
{
user
.
username
}
"
}),
200
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment