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
99ad7129
Commit
99ad7129
authored
2 years ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Add insert method to Daily repository (
#19
)
parent
bb169e74
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Add endpoints to manage Dailies
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend-services/feed-service/app/repositories/DailyRepository.scala
+23
-0
23 additions, 0 deletions
...vices/feed-service/app/repositories/DailyRepository.scala
with
23 additions
and
0 deletions
backend-services/feed-service/app/repositories/DailyRepository.scala
+
23
−
0
View file @
99ad7129
...
@@ -53,4 +53,27 @@ class DailyRepository extends MongoDBClient {
...
@@ -53,4 +53,27 @@ class DailyRepository extends MongoDBClient {
))
))
})
})
}
}
/**
* Inserts a Daily record into the database.
*
* @return A Future containing the inserted Daily object with the generated ID.
*/
def
insertDaily
(
daily
:
Daily
)
:
Future
[
Daily
]
=
{
// Don't supply an ID as Mongo will generate one for us
val
document
=
Document
(
"user_id"
->
daily
.
userId
,
"question_id"
->
daily
.
questionId
,
"content"
->
daily
.
content
,
"likes"
->
daily
.
likes
)
val
result
=
insertOne
(
dailiesCollection
,
document
)
// Return a Daily entity with the generated ID
result
.
flatMap
(
id
=>
{
val
updatedDaily
=
daily
.
copy
(
id
=
Some
(
new
ObjectId
(
id
)))
Future
.
successful
(
updatedDaily
)
})
}
}
}
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