diff --git a/backend-services/feed-service/app/repositories/DailyRepository.scala b/backend-services/feed-service/app/repositories/DailyRepository.scala index 8daeddc43e58efc0caab7ed42577d9d8d812a011..fa8a8370e6f606d56c83cfacdfe78097dc0ab727 100644 --- a/backend-services/feed-service/app/repositories/DailyRepository.scala +++ b/backend-services/feed-service/app/repositories/DailyRepository.scala @@ -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) + }) + } }