Skip to content

Commit

Permalink
add mongo-db dependency and create collection in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
DonatJR committed Nov 3, 2018
1 parent 200a824 commit fe4483f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.0.0"

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0"

libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "2.3.0"
4 changes: 3 additions & 1 deletion src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>

<logger name="org.mongodb.driver" level="INFO" />
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import de.htwg.se.sudoku.model.fileIoComponent.FileIOInterface
import de.htwg.se.sudoku.model.gridComponent.GridInterface
import de.htwg.se.sudoku.util.UndoManager

import scala.util.{Success, Failure}
import scala.util.{Failure, Success}
import com.typesafe.scalalogging.{LazyLogging, Logger}
import org.mongodb.scala.{MongoClient, MongoDatabase}

class Controller @Inject()(var grid: GridInterface)
extends ControllerInterface
Expand All @@ -24,6 +25,14 @@ class Controller @Inject()(var grid: GridInterface)
val injector = Guice.createInjector(new SudokuModule)
val fileIo = injector.instance[FileIOInterface]

// database connection (could be injected later if database is running on another server)
// connects to the default server localhost on port 27017
private val mongoClient: MongoClient = MongoClient()
private val db: MongoDatabase = mongoClient.getDatabase("sudoku-in-scala")
private val collection = db.getCollection("sudoku-in-scala-col")
// uncomment to delete the current database
//Await.result(collection.drop().toFuture(), Duration.Inf)

def createEmptyGrid: Unit = {
grid.size match {
case 1 => grid = injector.instance[GridInterface](Names.named("tiny"))
Expand Down

0 comments on commit fe4483f

Please sign in to comment.