diff --git a/sources/server/app/config/ServiceModule.scala b/sources/server/app/config/ServiceModule.scala new file mode 100644 index 0000000..091198a --- /dev/null +++ b/sources/server/app/config/ServiceModule.scala @@ -0,0 +1,14 @@ +package config + +import javax.inject.Singleton + +import com.google.inject.AbstractModule +import net.codingwell.scalaguice.ScalaModule +import service.entity.{DriverServiceImpl, DriverService, CarServiceImpl, CarService} + +class ServiceModule extends AbstractModule with ScalaModule { + override def configure(): Unit = { + bind[CarService].to[CarServiceImpl].in[Singleton] + bind[DriverService].to[DriverServiceImpl].in[Singleton] + } +} diff --git a/sources/server/app/config/SilhouetteModule.scala b/sources/server/app/config/SilhouetteModule.scala index 2b17d64..3485ca7 100644 --- a/sources/server/app/config/SilhouetteModule.scala +++ b/sources/server/app/config/SilhouetteModule.scala @@ -8,7 +8,10 @@ import com.mohiva.play.silhouette.impl.util.SecureRandomIDGenerator import models.generated.Tables.SystemUser import net.codingwell.scalaguice.ScalaModule import play.api.Play -import service.{LoginInfoService, LoginInfoServiceImpl} +import service.auth.{LoginInfoServiceImpl, LoginInfoService} + +import play.api.Play.current +import scala.concurrent.ExecutionContext.Implicits.global class SilhouetteModule extends AbstractModule with ScalaModule { override def configure(): Unit = { diff --git a/sources/server/app/service/AuthService.scala b/sources/server/app/service/auth/AuthService.scala similarity index 99% rename from sources/server/app/service/AuthService.scala rename to sources/server/app/service/auth/AuthService.scala index 01996a9..46e0bb2 100644 --- a/sources/server/app/service/AuthService.scala +++ b/sources/server/app/service/auth/AuthService.scala @@ -1,4 +1,4 @@ -package service +package service.auth import javax.inject.Inject diff --git a/sources/server/app/service/entity/CarService.scala b/sources/server/app/service/entity/CarService.scala new file mode 100644 index 0000000..fc2ea69 --- /dev/null +++ b/sources/server/app/service/entity/CarService.scala @@ -0,0 +1,24 @@ +package service.entity + +import javax.inject.Inject + +import models.generated.Tables.{CarFilter, Car, CarTable} +import repository.CarRepo + +import scala.concurrent.Future +import scala.concurrent.ExecutionContext.Implicits.global + +trait CarService extends EntityService[Car, CarTable, CarRepo, CarFilter] { + def getDisplayName(carId: Int): Future[String] +} + +class CarServiceImpl @Inject() (val repo: CarRepo) extends CarService { + override def getDisplayName(carId: Int): Future[String] = { + repo.findById(carId) map { + case Some(car) => s"${car.model} ${car.regNumber} (${car.rate}})" + case None => "None" + } + } +} + + diff --git a/sources/server/app/service/entity/DriverService.scala b/sources/server/app/service/entity/DriverService.scala new file mode 100644 index 0000000..2f37040 --- /dev/null +++ b/sources/server/app/service/entity/DriverService.scala @@ -0,0 +1,26 @@ +package service.entity + +import models.generated.Tables.{DriverFilter, Driver, DriverTable} +import repository.DriverRepo + +import scala.concurrent.Future +import scala.concurrent.ExecutionContext.Implicits.global + +trait DriverService extends EntityService[Driver, DriverTable, DriverRepo, DriverFilter] { + def getDisplayName(driverId: Int): Future[String] +} + +class DriverServiceImpl(val repo: DriverRepo) extends DriverService { + override def getDisplayName(driverId: Int): Future[String] = { + repo.findById(driverId) map { + case Some(driver) => + s"${driver.lastName} ${driver.firstName}" + + (driver.middleName match { + case Some(s) => " " + s + case None => "" + }) + case None => "None" + } + } +} + diff --git a/sources/server/app/service/EntityService.scala b/sources/server/app/service/entity/EntityService.scala similarity index 98% rename from sources/server/app/service/EntityService.scala rename to sources/server/app/service/entity/EntityService.scala index 6ea7362..723ff41 100644 --- a/sources/server/app/service/EntityService.scala +++ b/sources/server/app/service/entity/EntityService.scala @@ -1,9 +1,10 @@ -package service +package service.entity import models.entities.Entity import repository.GenericCRUD import slick.driver.PostgresDriver.api._ import utils.EntityNotFoundException + import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future diff --git a/sources/server/conf/application.conf b/sources/server/conf/application.conf index 5373ae5..379c8a4 100644 --- a/sources/server/conf/application.conf +++ b/sources/server/conf/application.conf @@ -37,8 +37,10 @@ play { # db.default.enabled=false } - modules.enabled += "config.ControllerModule" modules.enabled += "config.RepositoryModule" + modules.enabled += "config.ServiceModule" + modules.enabled += "config.SilhouetteModule" + modules.enabled += "config.ControllerModule" } # Database configuration