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
3f3c2221
Commit
3f3c2221
authored
2 years ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Add a ConfigHelper
parent
f086f821
No related branches found
No related tags found
1 merge request
!10
Initialise a Scala Play project with a MongoDB controller for Feed Service
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend-services/feed-service/app/models/MongoDBClient.scala
+2
-7
2 additions, 7 deletions
backend-services/feed-service/app/models/MongoDBClient.scala
backend-services/feed-service/app/utils/ConfigHelper.scala
+11
-0
11 additions, 0 deletions
backend-services/feed-service/app/utils/ConfigHelper.scala
with
13 additions
and
7 deletions
backend-services/feed-service/app/models/MongoDBClient.scala
+
2
−
7
View file @
3f3c2221
package
models
import
com.typesafe.config.
{
Config
,
ConfigFactory
}
import
utils.ConfigHelper
import
org.mongodb.scala.
{
MongoClient
,
MongoDatabase
,
MongoCollection
,
Document
,
FindObservable
,
Observer
,
Observable
}
import
org.mongodb.scala.model.
{
Filters
,
Projections
,
Sorts
}
...
...
@@ -17,12 +17,7 @@ import scala.util.{Success, Failure, Try}
* @constructor Creates a new instance of the MongoDBClient class.
*/
class
MongoDBClient
{
// Loads the default configuration
private
val
applicationConfig
:
Config
=
ConfigFactory
.
load
(
"application.conf"
)
private
val
referenceConfig
:
Config
=
ConfigFactory
.
parseResources
(
"reference.conf"
)
private
val
config
:
Config
=
referenceConfig
.
withFallback
(
applicationConfig
).
resolve
()
private
val
mongoUri
=
config
.
getString
(
"mongodb.uri"
)
private
val
mongoUri
=
ConfigHelper
.
getString
(
"mongodb.uri"
)
// Connects to a MongoDB Client when class is constructed
private
var
client
:
MongoClient
=
this
.
connect
()
...
...
This diff is collapsed.
Click to expand it.
backend-services/feed-service/app/utils/ConfigHelper.scala
0 → 100644
+
11
−
0
View file @
3f3c2221
package
utils
import
com.typesafe.config.
{
Config
,
ConfigFactory
}
object
ConfigHelper
{
private
val
applicationConfig
:
Config
=
ConfigFactory
.
load
(
"application.conf"
)
private
val
referenceConfig
:
Config
=
ConfigFactory
.
parseResources
(
"reference.conf"
)
private
val
config
:
Config
=
referenceConfig
.
withFallback
(
applicationConfig
).
resolve
()
def
getString
(
key
:
String
)
:
String
=
config
.
getString
(
key
)
}
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