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

Seed Question DB when application starts

parent fcf02ad8
No related branches found
No related tags found
1 merge request!31Implement Mongo Seeder v2
This commit is part of merge request !31. Comments created here will be created in the context of that merge request.
import scala.concurrent.Future
import javax.inject._
import play.api.inject.ApplicationLifecycle
import repositories.QuestionRepository
// Creates an `ApplicationStart` object once at start-up and registers hook for shut-down.
@Singleton
class ApplicationStart @Inject() (lifecycle: ApplicationLifecycle) {
println("Starting...")
QuestionRepository.seedDatabase()
// Shut-down hook
lifecycle.addStopHook { () =>
......
......@@ -29,3 +29,22 @@ class QuestionRepository extends Repository[Question] (
})
}
}
object QuestionRepository {
def seedDatabase(): Unit = {
println("Seeding Question Database...")
try {
Question.createQuestionAsync("Who is there?")
Question.createQuestionAsync("How is that there?")
Question.createQuestionAsync("Where is there?")
println("Successfully seeded Question Database!")
} catch {
case ex: Throwable => {
println("Error seeding Question Database...")
println(ex)
}
}
}
}
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