Skip to content

Commit

Permalink
fix: update entry point of the chess game service
Browse files Browse the repository at this point in the history
  • Loading branch information
madina9229 authored and jahrim committed Aug 26, 2023
1 parent 2ace213 commit 925c8ee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ dependencies {

application {
mainClass.set(projectInfo.implementationClass)
tasks.withType(JavaExec::class.java){ args() }
tasks.withType(JavaExec::class.java){
properties["statisticsService"]?.apply { args("--statistics-service", this) }
properties["httpHost"]?.apply { args("--http-host", this) }
properties["httpPort"]?.apply { args("--http-port", this) }
properties["allowedOrigins"]?.apply { args("--allowed-origins", this) }
}
}

spotless {
Expand Down
48 changes: 46 additions & 2 deletions src/main/scala/io/github/jahrim/chess/game/service/main/Main.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package io.github.jahrim.chess.game.service.main

import io.github.chess.engine.model.board.{File, Rank}
import io.github.jahrim.chess.game.service.components.data.PositionData
import io.github.jahrim.chess.game.service.components.adapters.http.ChessGameHttpAdapter
import io.github.jahrim.chess.game.service.components.ports.{ChessGameModel, ChessGamePort}
import io.github.jahrim.hexarc.architecture.vertx.core.dsl.VertxDSL.*
import io.vertx.core.Vertx
import io.vertx.core.http.HttpServerOptions
import org.bson.BsonDocument
import org.rogach.scallop.*

/** Main of the application. */
@main def main(args: String*): Unit =
val arguments: Args = Args(args)
println("Hello world!")

DeploymentGroup.deploySingle(Vertx.vertx()) {
new Service:
name = "ChessGameService"

new Port[ChessGamePort]:
model = ChessGameModel( /* TODO pass a statistics proxy */ )

new Adapter(
adapter = ChessGameHttpAdapter(
httpOptions = HttpServerOptions()
.setHost(arguments.httpHost())
.setPort(arguments.httpPort()),
allowedOrigins = arguments.allowedOrigins()
)
)
}

/**
* The parsed command line arguments accepted by this application.
Expand All @@ -18,4 +38,28 @@ import org.rogach.scallop.*
* @see [[https://github.com/scallop/scallop Scallop Documentation on Github]].
*/
class Args(private val arguments: Seq[String]) extends ScallopConf(arguments):
val statisticsService: ScallopOption[String] = opt[String](
name = "statistics-service",
descr = "The host of the statistics service where the result of the matches will be stored.",
default = Some("localhost:8082"),
required = false
)
val httpHost: ScallopOption[String] = opt[String](
name = "http-host",
descr = "The server host for the http adapter of this service.",
default = Some("localhost"),
required = false
)
val httpPort: ScallopOption[Int] = opt[Int](
name = "http-port",
descr = "The server port for the http adapter of this service.",
default = Some(8080),
required = false
)
val allowedOrigins: ScallopOption[Seq[String]] = opt[String](
name = "allowed-origins",
descr = "A list of colon separated origins that are allowed to access this service.",
default = Some(""),
required = false
).map(_.split(";").toSeq)
verify()
18 changes: 0 additions & 18 deletions src/test/scala/test/TemplateTest.scala

This file was deleted.

0 comments on commit 925c8ee

Please sign in to comment.