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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
bb169e74
Commit
bb169e74
authored
2 years ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Construct Daily repository with fetch method (
#19
)
parent
bf6517ea
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/repositories/DailyRepository.scala
+56
-0
56 additions, 0 deletions
...vices/feed-service/app/repositories/DailyRepository.scala
backend-services/feed-service/conf/application.conf
+3
-3
3 additions, 3 deletions
backend-services/feed-service/conf/application.conf
with
59 additions
and
3 deletions
backend-services/feed-service/app/repositories/DailyRepository.scala
0 → 100644
+
56
−
0
View file @
bb169e74
package
repositories
import
com.typesafe.config.ConfigFactory
import
models.
{
Daily
,
MongoDBClient
}
import
org.mongodb.scala.
{
MongoCollection
,
Document
}
import
org.bson.types.ObjectId
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.concurrent.
{
Future
,
Await
}
import
scala.concurrent.duration._
class
DailyRepository
extends
MongoDBClient
{
// Loads the default configuration
private
val
config
=
ConfigFactory
.
load
()
private
val
databaseName
=
config
.
getString
(
"mongo.feedService.db"
)
private
val
collectionName
=
config
.
getString
(
"mongo.dailies.collection"
)
/**
* Returns a reference to a MongoDB collection within a database.
* Once Future completes, collection reference is returned.
*
* @return a MongoCollection[Document] object representing the dailies collection.
* @throws TimeoutException if the Future doesn't complete within the 3 second timeout.
*/
private
def
dailiesCollection
:
MongoCollection
[
Document
]
=
{
val
futureCollection
=
for
{
database
<-
getDatabase
(
databaseName
)
collection
<-
getCollection
(
database
,
collectionName
)
}
yield
collection
Await
.
result
(
futureCollection
,
3.
seconds
)
}
/**
* Gets all the Daily records.
*
* @return A Future containing a sequence of matching Daily objects.
*/
def
getAllDailies
()
:
Future
[
Seq
[
Daily
]]
=
{
val
documents
:
Future
[
Seq
[
Document
]]
=
find
(
dailiesCollection
)
documents
.
map
(
document
=>
{
document
.
map
(
doc
=>
Daily
(
Some
(
doc
.
getObjectId
(
"_id"
)),
doc
.
getObjectId
(
"user_id"
),
doc
.
getObjectId
(
"question_id"
),
doc
.
getString
(
"content"
),
doc
.
getInteger
(
"likes"
)
))
})
}
}
This diff is collapsed.
Click to expand it.
backend-services/feed-service/conf/application.conf
+
3
−
3
View file @
bb169e74
# Default Configuration File
# MongoDB Connection Strings
mongodb
.
uri
=
"mongodb://localhost:27017/"
mongodb
.
uri
=
"mongodb://localhost:27017/"
mongo
.
feedService
.
db
=
"feed-service"
mongo
.
dailies
.
collection
=
"dailies"
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