Skip to content
Snippets Groups Projects
Commit 99ad7129 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Add insert method to Daily repository (#19)

parent bb169e74
No related branches found
No related tags found
1 merge request!14Add endpoints to manage Dailies
...@@ -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)
})
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment