Skip to content

Commit

Permalink
#66, #67: несколько сервисов + добавлены пропущенные импорты для conc…
Browse files Browse the repository at this point in the history
…urrency
  • Loading branch information
sedovalx committed Jun 14, 2015
1 parent 03dce75 commit 9dad548
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
14 changes: 14 additions & 0 deletions sources/server/app/config/ServiceModule.scala
Original file line number Diff line number Diff line change
@@ -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]
}
}
5 changes: 4 additions & 1 deletion sources/server/app/config/SilhouetteModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package service.auth

import javax.inject.Inject

Expand Down
24 changes: 24 additions & 0 deletions sources/server/app/service/entity/CarService.scala
Original file line number Diff line number Diff line change
@@ -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"
}
}
}


26 changes: 26 additions & 0 deletions sources/server/app/service/entity/DriverService.scala
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion sources/server/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9dad548

Please sign in to comment.