From 9dad5480e9b4e7381d64679875c209696b52e7a1 Mon Sep 17 00:00:00 2001 From: sedovalx Date: Sun, 14 Jun 2015 23:59:41 +0300 Subject: [PATCH] =?UTF-8?q?#66,=20#67:=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D0=BE=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=20+=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=BF=D1=83=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20concurrency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/server/app/config/ServiceModule.scala | 14 ++++++++++ .../server/app/config/SilhouetteModule.scala | 5 +++- .../app/service/{ => auth}/AuthService.scala | 2 +- .../app/service/entity/CarService.scala | 24 +++++++++++++++++ .../app/service/entity/DriverService.scala | 26 +++++++++++++++++++ .../service/{ => entity}/EntityService.scala | 3 ++- sources/server/conf/application.conf | 4 ++- 7 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 sources/server/app/config/ServiceModule.scala rename sources/server/app/service/{ => auth}/AuthService.scala (99%) create mode 100644 sources/server/app/service/entity/CarService.scala create mode 100644 sources/server/app/service/entity/DriverService.scala rename sources/server/app/service/{ => entity}/EntityService.scala (98%) 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