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
16feb458
Commit
16feb458
authored
1 year ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Add createdAt field to Dailies (
#19
)
parent
871e0ff3
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
+15
-4
15 additions, 4 deletions
backend-services/feed-service/app/models/Daily.scala
backend-services/feed-service/app/repositories/DailyRepository.scala
+9
-5
9 additions, 5 deletions
...vices/feed-service/app/repositories/DailyRepository.scala
with
24 additions
and
9 deletions
backend-services/feed-service/app/models/Daily.scala
+
15
−
4
View file @
16feb458
package
models
import
repositories.DailyRepository
import
org.bson.types.ObjectId
import
scala.concurrent.ExecutionContext.Implicits.global
import
scala.concurrent.
{
Future
,
Await
}
import
scala.concurrent.duration._
import
org.bson.types.ObjectId
import
java.util.Date
import
java.time.Instant
import
java.text.SimpleDateFormat
import
play.api.libs.json.Json
import
play.api.libs.json.
{
Json
,
JsValue
,
JsString
,
JsNumber
,
JsObject
,
JsArray
}
...
...
@@ -15,7 +20,8 @@ case class Daily(
userId
:
ObjectId
,
questionId
:
ObjectId
,
content
:
String
,
likes
:
Int
likes
:
Int
,
createdAt
:
Date
)
object
Daily
{
...
...
@@ -27,9 +33,10 @@ object Daily {
questionId
:
ObjectId
,
content
:
String
,
likes
:
Int
=
0
,
createdAt
:
Date
=
Date
.
from
(
Instant
.
now
()),
timeout
:
Int
=
4
)
:
Daily
=
{
val
daily
:
Daily
=
Daily
(
None
,
userId
,
questionId
,
content
,
likes
)
val
daily
:
Daily
=
Daily
(
None
,
userId
,
questionId
,
content
,
likes
,
createdAt
)
val
future
:
Future
[
Daily
]
=
dailyRepo
.
insertDaily
(
daily
)
Await
.
result
(
future
,
timeout
.
seconds
)
}
...
...
@@ -56,12 +63,16 @@ object Daily {
// Convert from Daily object to JSON (serializing to JSON)
def
toJson
(
daily
:
Daily
)
:
JsValue
=
{
val
dateFormat
:
SimpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
val
formattedDate
:
String
=
dateFormat
.
format
(
daily
.
createdAt
);
val
dailyJson
=
Seq
(
"id"
->
JsString
(
daily
.
id
.
getOrElse
(
""
).
toString
()),
"userId"
->
JsString
(
daily
.
userId
.
toString
()),
"questionId"
->
JsString
(
daily
.
questionId
.
toString
()),
"content"
->
JsString
(
daily
.
content
),
"likes"
->
JsNumber
(
daily
.
likes
)
"likes"
->
JsNumber
(
daily
.
likes
),
"createdAt"
->
JsString
(
formattedDate
)
)
Json
.
toJson
(
JsObject
(
dailyJson
))
...
...
This diff is collapsed.
Click to expand it.
backend-services/feed-service/app/repositories/DailyRepository.scala
+
9
−
5
View file @
16feb458
...
...
@@ -43,14 +43,15 @@ class DailyRepository extends MongoDBClient {
*/
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"
)
doc
.
getInteger
(
"likes"
),
doc
.
getDate
(
"createdAt"
)
))
})
}
...
...
@@ -70,7 +71,8 @@ class DailyRepository extends MongoDBClient {
doc
.
getObjectId
(
"user_id"
),
doc
.
getObjectId
(
"question_id"
),
doc
.
getString
(
"content"
),
doc
.
getInteger
(
"likes"
)
doc
.
getInteger
(
"likes"
),
doc
.
getDate
(
"createdAt"
)
))
})
}
...
...
@@ -92,7 +94,8 @@ class DailyRepository extends MongoDBClient {
doc
.
getObjectId
(
"user_id"
),
doc
.
getObjectId
(
"question_id"
),
doc
.
getString
(
"content"
),
doc
.
getInteger
(
"likes"
)
doc
.
getInteger
(
"likes"
),
doc
.
getDate
(
"createdAt"
)
))
})
}
...
...
@@ -108,7 +111,8 @@ class DailyRepository extends MongoDBClient {
"user_id"
->
daily
.
userId
,
"question_id"
->
daily
.
questionId
,
"content"
->
daily
.
content
,
"likes"
->
daily
.
likes
"likes"
->
daily
.
likes
,
"createdAt"
->
daily
.
createdAt
)
val
result
=
insertOne
(
dailiesCollection
,
document
)
...
...
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