Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Daily Thought App
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
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
COM3014-Coursework
Daily Thought App
Commits
8a13c6ed
Commit
8a13c6ed
authored
1 year ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Add functionality to like a post
parent
8f2629ff
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Add endpoints to manage Dailies
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend-services/feed-service/app/models/Daily.scala
+9
-0
9 additions, 0 deletions
backend-services/feed-service/app/models/Daily.scala
backend-services/feed-service/app/repositories/DailyRepository.scala
+12
-1
12 additions, 1 deletion
...vices/feed-service/app/repositories/DailyRepository.scala
with
21 additions
and
1 deletion
backend-services/feed-service/app/models/Daily.scala
+
9
−
0
View file @
8a13c6ed
...
...
@@ -61,6 +61,15 @@ object Daily {
Await
.
result
(
result
,
timeout
.
seconds
)
}
def
likeAsync
(
dailyId
:
ObjectId
,
userId
:
ObjectId
,
timeout
:
Int
=
4
)
:
Unit
=
{
val
result
:
Future
[
Unit
]
=
for
{
daily
:
Daily
<-
dailyRepo.getDaily
(
dailyId
)
unit:
Unit
<-
dailyRepo.like
(
daily
,
userId
)
}
yield
unit
Await
.
result
(
result
,
timeout
.
seconds
)
}
// Convert from Daily object to JSON (serializing to JSON)
def
toJson
(
daily
:
Daily
)
:
JsValue
=
{
val
usersLikedAsJsStrings
=
daily
.
usersLiked
.
map
(
id
=>
JsString
(
id
.
toString
()))
...
...
This diff is collapsed.
Click to expand it.
backend-services/feed-service/app/repositories/DailyRepository.scala
+
12
−
1
View file @
8a13c6ed
...
...
@@ -5,8 +5,9 @@ import com.typesafe.config.ConfigFactory
import
models.
{
Daily
,
MongoDBClient
}
import
org.mongodb.scala.
{
MongoCollection
,
Document
}
import
org.mongodb.scala.model.
{
Filters
}
import
org.mongodb.scala.model.
{
Filters
,
Updates
}
import
org.bson.types.ObjectId
import
org.bson.conversions.Bson
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.concurrent.
{
Future
,
Await
}
...
...
@@ -108,6 +109,16 @@ class DailyRepository extends MongoDBClient {
Future
.
successful
(
updatedDaily
)
})
}
def
like
(
daily
:
Daily
,
user
:
ObjectId
)
:
Future
[
Unit
]
=
{
val
updatedUsersLiked
:
Seq
[
ObjectId
]
=
daily
.
usersLiked
:+
user
val
update
:
Bson
=
Updates
.
set
(
"usersLiked"
,
updatedUsersLiked
)
val
updates
:
Seq
[
Bson
]
=
Seq
(
update
)
val
dailyId
=
daily
.
id
.
getOrElse
(
throw
new
RuntimeException
)
val
result
=
updateOne
(
dailiesCollection
,
dailyId
,
updates
)
Future
.
successful
(
result
)
}
}
...
...
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