本文整理汇总了Scala中play.api.routing.SimpleRouter类的典型用法代码示例。如果您正苦于以下问题:Scala SimpleRouter类的具体用法?Scala SimpleRouter怎么用?Scala SimpleRouter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleRouter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: LocationRouter
//设置package包名称以及导入依赖的类
package controllers.location
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class LocationRouter @Inject()(addressTypeCtrl: AddressTypeCtrl,
locationTypeCtrl: LocationTypeCtrl,
contactTypeCtrl: ContactTypeCtrl)
extends SimpleRouter {
override def routes: Routes = {
//address
case GET(p"/addresstype/all") =>
addressTypeCtrl.getAll
case GET(p"/addresstype/$id") =>
addressTypeCtrl.getById(id)
case POST(p"/addresstype/create") =>
addressTypeCtrl.create
//location type
case GET(p"/locationtype/all") =>
locationTypeCtrl.getAll
case GET(p"/locationtype/$id") =>
locationTypeCtrl.getById(id)
case POST(p"/locationtype/create") =>
locationTypeCtrl.create
//contact type
case GET(p"/contacttype/all") =>
contactTypeCtrl.getAll
case GET(p"/contacttype/$id") =>
contactTypeCtrl.getById(id)
case POST(p"/contacttype/create") =>
contactTypeCtrl.create
}
}
示例2: UserRouter
//设置package包名称以及导入依赖的类
package v1.user
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class UserRouter @Inject()(controller: UserController)
extends SimpleRouter {
var prefix = "/v1/users"
def link(id: UserId): String = {
import com.netaporter.uri.dsl._
val url = prefix / id.toString
url.toString()
}
override def routes: Routes = {
case GET(p"/") =>
controller.index
case POST(p"/") =>
controller.process
case GET(p"/$id") =>
controller.show(id)
}
}
示例3: OrganisationRouter
//设置package包名称以及导入依赖的类
package controllers.organisations //Xolela Masebeni(213160447) [email protected]
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class OrganisationRouter @Inject()
(mail: OrganisationController)
extends SimpleRouter {
override def routes: Routes = {
case GET(p"/organisation/$org") =>
mail.getOrganisation(org)
case POST(p"/organisation/create") =>
mail.createOrUpdate
}
}
示例4: UtilRouter
//设置package包名称以及导入依赖的类
package controllers.common.util
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class UtilRouter @Inject()
(mail: MailController)
extends SimpleRouter {
override def routes: Routes = {
case GET(p"/mail/$org") =>
mail.getMail(org)
case POST(p"/mail/create") =>
mail.createOrUpdate
}
}
示例5: PostRouter
//设置package包名称以及导入依赖的类
package v1.post
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class PostRouter @Inject()(controller: PostController)
extends SimpleRouter {
val prefix = "/v1/posts"
def link(id: PostId): String = {
import com.netaporter.uri.dsl._
val url = prefix / id.toString
url.toString()
}
override def routes: Routes = {
case GET(p"/") =>
controller.index
case POST(p"/") =>
controller.process
case GET(p"/$id") =>
controller.show(id)
}
}
示例6: UtilRouter
//设置package包名称以及导入依赖的类
package controllers.util
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class UtilRouter @Inject()(roleController: RoleController)(
keysController: KeysController)(
mailSettingsController: MailSettingsController,
itemsStatusCtrl: ItemsStatusCtrl)
extends SimpleRouter {
override def routes: Routes = {
//ROLES
case GET(p"/roles/all") =>
roleController.getRoles
case POST(p"/roles/create") =>
roleController.create
case GET(p"/roles/$id") =>
roleController.getRoleById(id)
//items status
case POST(p"/roles/create") =>
itemsStatusCtrl.create
case GET(p"/roles/$id") =>
itemsStatusCtrl.getById(id)
//KEYS
case GET(p"/keys/all") =>
keysController.getKeys
case POST(p"/keys/create") =>
keysController.create
case GET(p"/keys/$id") =>
keysController.getKeyById(id)
//MAIL
case GET(p"/mail/all/$siteId") =>
mailSettingsController.getSiteMailSettings(siteId)
case POST(p"/mail/create") =>
mailSettingsController.create
case GET(p"/mail/$siteId/$id") =>
mailSettingsController.getMailSettingById(siteId, id)
}
}
示例7: StorageRouter
//设置package包名称以及导入依赖的类
package controllers.storage
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class StorageRouter @Inject()(storageUrlCtrl: StorageUrlCtrl,
fileResultsCtrl: FileResultsCtrl)
extends SimpleRouter {
override def routes: Routes = {
//storage url
case GET(p"/storageurl/all") =>
storageUrlCtrl.getAll
case GET(p"/storageurl/$id") =>
storageUrlCtrl.getById(id)
case POST(p"/storageurl/create") =>
storageUrlCtrl.create
//file result
case GET(p"/fileresult/all") =>
fileResultsCtrl.getAll
case GET(p"/fileresult/$id") =>
fileResultsCtrl.getById(id)
case POST(p"/fileresult/create") =>
fileResultsCtrl.create
}
}
示例8: Router
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import lib.Constants
import play.api.routing.SimpleRouter
import play.api.http._
import play.api.mvc._
import scala.runtime.AbstractPartialFunction
class Router @Inject() (
internal: Internal,
proxy: ReverseProxy
) extends SimpleRouter {
override def routes = new AbstractPartialFunction[RequestHeader, Handler] {
override def applyOrElse[A <: RequestHeader, B >: Handler](request: A, default: A => B) = {
(request.method, request.path, request.headers.get(Constants.Headers.FlowServer)) match {
case ("GET", "/_internal_/healthcheck", None) => internal.getHealthcheck
case ("GET", "/_internal_/config", None) => internal.getConfig
case ("GET", "/_internal_/route", None) => internal.getRoute()
case ("GET", "/favicon.ico", None) => internal.favicon
case (_, "/_internal_/diagnostics", None) => internal.diagnostics
case ("GET", "/robots.txt", None) => internal.getRobots
case _ => proxy.handle
}
}
override def isDefinedAt(rh: RequestHeader) = true
}
}
示例9: SystemLogRouter
//设置package包名称以及导入依赖的类
package controllers.syslog
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class SystemLogRouter @Inject()(syslogCtrl: SystemLogEventsCtrl)
extends SimpleRouter {
override def routes: Routes = {
//System Log Events
case GET(p"/systemlog/all/$org") =>
syslogCtrl.getAll(org)
case GET(p"/systemlog/$org/$id") =>
syslogCtrl.getById(org, id)
case POST(p"/systemlog/create") =>
syslogCtrl.create
}
}
示例10: OrganisationRouter
//设置package包名称以及导入依赖的类
package controllers.organisation
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class OrganisationRouter @Inject()(locationCtrl: LocationCtrl,
organisationCtrl: OrganisationCtrl,
organisationLogoCtrl: OrganisationLogoCtrl)
extends SimpleRouter {
override def routes: Routes = {
//location
case GET(p"/location/all/$org") =>
locationCtrl.getAll(org)
case GET(p"/location/$org/$id") =>
locationCtrl.getById(org, id)
case POST(p"/location/delete/$org/$id") =>
locationCtrl.delete(org, id)
case POST(p"/location/create") =>
locationCtrl.create
//organisation logo
case GET(p"/organisationlogo/all/$org") =>
organisationLogoCtrl.getAll(org)
case GET(p"/organisationlogo/$org/$id") =>
organisationLogoCtrl.getById(org, id)
case POST(p"/organisationlogo/create") =>
organisationLogoCtrl.create
//organisation
case GET(p"/organisation/all") =>
organisationCtrl.getAll
case GET(p"/organisation/$id") =>
organisationCtrl.getById(id)
case POST(p"/organisation/create") =>
organisationCtrl.create
}
}
示例11: BobRouter
//设置package包名称以及导入依赖的类
package v1.bob
import javax.inject.Inject
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._
class BobRouter @Inject()(
controller: BobController,
interactionController: BobInterActionController
)
extends SimpleRouter {
val prefix = "/slack/bob"
def link(id: Int): String = {
import com.netaporter.uri.dsl._
val url = prefix / id.toString
url.toString()
}
override def routes: Routes = {
case GET(p"/") => controller.index
case POST(p"/") => controller.process
case POST(p"/im") => interactionController.process
}
}
示例12: CustomRouter
//设置package包名称以及导入依赖的类
package api
import javax.inject.{Inject, Named}
import akka.actor.ActorRef
import com.viajobien.busy.actors.ProducerActor
import play.api.Logger
import play.api.libs.json.{JsNull, Json}
import play.api.mvc.Action
import play.api.mvc.Results._
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import repositories.RouteRepository
import services.RouteService
import scala.concurrent.{ExecutionContext, Future}
class CustomRouter @Inject()(@Named(ProducerActor.name) producerActor: ActorRef,
routeService: RouteService, routeRepository: RouteRepository
)(implicit ec: ExecutionContext) extends SimpleRouter {
override def routes: Routes = {
case _ =>
Action.async { implicit request =>
val future = this.routeService.route(
futureJson => futureJson map {
case JsNull => ServiceUnavailable(Json.obj("error" -> "Error on access service"))
case json => Ok(json)
},
() => Future.successful(BadGateway(Json.obj("error" -> "route not found")))
)
future recover {
case e =>
Logger.warn("error on getRoute", e)
ServiceUnavailable(Json.obj("error" -> "error calling route"))
}
}
}
}
示例13: BaseAppModule
//设置package包名称以及导入依赖的类
import controllers._
import scaldi.Module
import akka.actor.ActorSystem
import play.api.http._
import play.api.ApplicationLoader.Context
import play.api.inject.ApplicationLifecycle
import play.api.routing.{Router, SimpleRouter}
import play.api.{Application, BuiltInComponentsFromContext, Configuration, Environment}
class BaseAppModule(aContext: Context) extends Module {
bind[Router] to injected[router.Routes]
bind[Context] to aContext
bind[Application] to inject[BuiltInComponentsFromContext].application
bind[ActorSystem] to inject[Application].actorSystem
bind[Environment] to aContext.environment
bind[Configuration] to aContext.initialConfiguration
bind[ApplicationLifecycle] to aContext.lifecycle
bind[AssetsBuilder] to controllers.Assets
bind[AssetsMetadata] to injected[AssetsMetadataProvider].get
bind[AssetsConfiguration] to AssetsConfiguration()
bind[FileMimeTypes] to new DefaultFileMimeTypesProvider(inject[HttpConfiguration].fileMimeTypes).get
bind[HttpErrorHandler] to DefaultHttpErrorHandler
bind[HttpConfiguration] to HttpConfiguration.fromConfiguration(inject[Configuration],inject[Environment])
bind[BuiltInComponentsFromContext] to new BuiltInComponentsFromContext(inject[Context]) {
implicit val lInjector = BaseAppModule.this
override def router = SimpleRouter{case x => inject[Router].routes(x)}
}
}