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
b2113809
Commit
b2113809
authored
2 years ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Implement endpoint for fetching all Dailies (
#19
)
parent
92ffb5c2
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/controllers/DailyController.scala
+39
-0
39 additions, 0 deletions
...rvices/feed-service/app/controllers/DailyController.scala
backend-services/feed-service/conf/routes
+2
-0
2 additions, 0 deletions
backend-services/feed-service/conf/routes
with
41 additions
and
0 deletions
backend-services/feed-service/app/controllers/DailyController.scala
0 → 100644
+
39
−
0
View file @
b2113809
package
controllers
import
javax.inject._
import
play.api._
import
play.api.mvc._
import
models.Daily
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.concurrent.
{
Future
,
Await
,
TimeoutException
}
import
scala.concurrent.duration._
import
org.bson.types.ObjectId
/**
* This controller handles all the Daily endpoints.
*/
@Singleton
class
DailyController
@Inject
()(
val
controllerComponents
:
ControllerComponents
)
extends
BaseController
{
/**
* Create an Action to fetch all the Dailies in the DB.
*/
def
getAll
()
=
Action
{
implicit
request
:
Request
[
AnyContent
]
=>
println
(
"DailyController:getAll"
)
var
result
=
Daily
.
getAllDailies
()
try
{
// Wait for 4 seconds for the Future to complete
val
resultCompleted
=
Await
.
result
(
result
,
4.
seconds
)
val
jsonResult
:
Seq
[
String
]
=
resultCompleted
.
map
(
daily
=>
Daily
.
toString
(
daily
))
Ok
(
jsonResult
.
toString
())
}
catch
{
case
e
:
TimeoutException
=>
BadRequest
(
"Request timed out"
)
}
}
}
This diff is collapsed.
Click to expand it.
backend-services/feed-service/conf/routes
+
2
−
0
View file @
b2113809
...
...
@@ -10,3 +10,5 @@ GET / controllers.HomeController.index()
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /mongo_test controllers.MongoTestController.index()
GET /daily/getAll controllers.DailyController.getAll()
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