当前位置: 首页>>代码示例>>Scala>>正文


Scala ControllerComponents类代码示例

本文整理汇总了Scala中play.api.mvc.ControllerComponents的典型用法代码示例。如果您正苦于以下问题:Scala ControllerComponents类的具体用法?Scala ControllerComponents怎么用?Scala ControllerComponents使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ControllerComponents类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: InjectedPageletsAssembly

//设置package包名称以及导入依赖的类
package org.splink.pagelets

import play.api.mvc.{ControllerComponents, InjectedController}

class InjectedPageletsAssembly extends InjectedController with PageletsAssembly

trait PageletsAssembly extends Pagelets
  with PageletActionsImpl
  with PageBuilderImpl
  with LeafBuilderImpl
  with ActionBuilderImpl
  with TreeToolsImpl
  with ResourceActionsImpl
  with ResourcesImpl
  with VisualizerImpl {
  protected def controllerComponents: ControllerComponents
} 
开发者ID:splink,项目名称:pagelets,代码行数:18,代码来源:PageletsAssembly.scala

示例2: UsersController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.{Inject, Singleton}

import database.UsersCollection
import models.User
import play.api.libs.json.JsValue
import play.api.mvc.{Action, BaseController, ControllerComponents}

import scala.concurrent.{ExecutionContext, Future}



@Singleton
class UsersController @Inject()(
  val controllerComponents: ControllerComponents,
  users: UsersCollection
)(implicit ec: ExecutionContext) extends BaseController {

  def create: Action[JsValue] = Action.async(parse.json) { request =>
    request.body.asOpt[User] match {
      case Some(user) => users.insert(user).map(if(_) Created else InternalServerError)
      case None => Future.successful(BadRequest)
    }
  }

  def read(id: String) = Action {
    users.find(id)
    Ok
  }

} 
开发者ID:WilliamJohnathonLea,项目名称:OAuth-Users,代码行数:33,代码来源:UsersController.scala

示例3: OAuth2ProviderActionBuildersSpec

//设置package包名称以及导入依赖的类
package scalaoauth2.provider

import javax.inject.Inject

import org.scalatest._
import org.scalatest.Matchers._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc.{ AbstractController, ControllerComponents }
import play.api.test.Helpers._
import play.api.test.FakeRequest

class OAuth2ProviderActionBuildersSpec extends FlatSpec {

  class MyController @Inject() (components: ControllerComponents)
      extends AbstractController(components) with OAuth2ProviderActionBuilders {

    val action = AuthorizedAction(new MockDataHandler) { request =>
      Ok(request.authInfo.user.name)
    }

  }

  val injector = new GuiceApplicationBuilder().injector()
  val controllerComponents = injector.instanceOf[ControllerComponents]

  it should "return BadRequest" in {
    val controller = new MyController(controllerComponents)
    val result = controller.action(FakeRequest())
    status(result) should be(400)
    contentAsString(result) should be("")
  }

} 
开发者ID:nulab,项目名称:play2-oauth2-provider,代码行数:34,代码来源:OAuth2ProviderActionBuildersSpec.scala

示例4: DBController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.{Inject, Singleton}

import dao.{DatabrickAuditLogDAO, UserDAO}
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import play.api.mvc.{AbstractController, ControllerComponents}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext


@Singleton
class DBController @Inject()(
                            userDao:UserDAO,
                            databrickAuditLogDao: DatabrickAuditLogDAO,
                              protected val dbConfigProvider: DatabaseConfigProvider,
                              cc: ControllerComponents
                            )
                            (implicit ec: ExecutionContext)
  extends AbstractController(cc) with HasDatabaseConfigProvider[JdbcProfile] {
  def init = Action { implicit request =>
    Ok("success")
  }

} 
开发者ID:bkstha,项目名称:my-log-api,代码行数:27,代码来源:DBController.scala

示例5: UserController

//设置package包名称以及导入依赖的类
package controllers

import com.google.inject.Inject
import helpers.Auth0Config
import models.Auth0Model
import play.api.cache.SyncCacheApi
import play.api.libs.json.JsValue
import play.api.mvc.{AbstractController, ControllerComponents}

import scala.concurrent.ExecutionContext

class UserController @Inject()(val components: ControllerComponents, cache: SyncCacheApi, val Auth0Config: Auth0Config,
                               auth0Controller: Auth0Controller)(implicit exec: ExecutionContext)
extends AbstractController(components) {

  def getUser = auth0Controller.AuthenticatedAction { request =>
    val idToken = request.session.get("idToken").get
    val profile = cache.get[JsValue](idToken + "profile").get
    val profileModel = profile.as[Auth0Model]
      Ok(views.html.user(profileModel))
  }

} 
开发者ID:yangwong911,项目名称:yang-service-frontend,代码行数:24,代码来源:UserController.scala

示例6: SignOutController

//设置package包名称以及导入依赖的类
package controllers

import com.google.inject.Inject
import com.mohiva.play.silhouette.api.{LogoutEvent, Silhouette}
import play.api.mvc.{AbstractController, ControllerComponents}
import utils.JsonResults
import utils.auth.DefaultEnv

class SignOutController @Inject() (
                                    components: ControllerComponents,
                                    silhouette: Silhouette[DefaultEnv]
                                  ) extends AbstractController(components) {

  def submit = silhouette.SecuredAction.async { implicit request =>
    silhouette.env.eventBus.publish(
      LogoutEvent(request.identity, request)
    )
    silhouette.env.authenticatorService.discard(
      request.authenticator,
      Ok(JsonResults.success("User signed out"))
    )
  }
} 
开发者ID:edgarmueller,项目名称:plog-backend,代码行数:24,代码来源:SignOutController.scala

示例7: UserController

//设置package包名称以及导入依赖的类
package controllers

import java.util.Locale
import javax.inject.{Inject, Singleton}
import play.api.mvc.{AbstractController, AnyContent, ControllerComponents}

@Singleton
class UserController @Inject() (cc: ControllerComponents) extends AbstractController(cc) {
  def create = Action { request =>
    val body: AnyContent = request.body

    val contentType: Option[String] = request.contentType.map(_.toLowerCase(Locale.ENGLISH))
    println(contentType)

    val name = body.asText
    println(name)
    Ok("not implemented")
  }

  def get(id: Int) = Action {
    println(id)
    Ok("not implemented")
  }

  def delete(id: Int) = Action {
    println(id)
    Ok("not implemented")
  }
} 
开发者ID:takayuky,项目名称:Play2.6_Scala2.12_tutorial,代码行数:30,代码来源:UserController.scala

示例8: FoodFormData

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import play.api.Logger
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.I18nSupport
import play.api.libs.json.Json
import play.api.mvc.{AbstractController, ControllerComponents}
import v1.food.FoodResourceHandler
import views.html.defaultpages.notFound

import scala.concurrent.{ExecutionContext, Future}

case class FoodFormData(name: String)

class FoodController @Inject()(handler: FoodResourceHandler, cc: ControllerComponents)(implicit ec: ExecutionContext)
  extends AbstractController(cc) with I18nSupport {

  private val log = Logger(classOf[FoodController])
  val foodForm = Form(
    mapping(
      "name" -> text
    )(FoodFormData.apply)(FoodFormData.unapply)
  )

  def index(filters: String) = Action.async {
    log.info(s"filters=$filters")
    if (log.isInfoEnabled) println("Info is enabled")
    handler.list.map { foodResources =>
      Ok(Json.toJson(foodResources))
    }
  }

  def show(id: String) = Action.async { implicit request =>
    handler.get(id).map {
      case Some(foodResource) => Ok(Json.toJson(foodResource))
      case None => NotFound(notFound(request.method, request.uri))
    }
  }

  def create = Action.async { implicit request =>
    def failure(badForm: Form[FoodFormData]) = {
      Future.successful(BadRequest(badForm.errorsAsJson))
    }

    def success(input: FoodFormData) = {
      handler.create(input).map { food =>
        Created(Json.toJson(food)).withHeaders(LOCATION -> food.link)
      }
    }

    foodForm.bindFromRequest().fold(failure, success)
  }
} 
开发者ID:sleb,项目名称:shift-food-guide,代码行数:57,代码来源:FoodController.scala

示例9: SubscriptionController

//设置package包名称以及导入依赖的类
package controllers.subscription

import javax.inject.Inject

import model.CommonProps
import play.api.libs.json.Json
import play.api.mvc.{AbstractController, ControllerComponents}
import repo.SubscriptionRepo
import model.b2c.Error

class SubscriptionController @Inject()(cc:ControllerComponents,subscriptionRepo: SubscriptionRepo)
  extends AbstractController(cc) {

  def getSubscriptionById(id: String) = Action {
    if (id.size == 24 && id.matches(CommonProps.HexadecimalRegexp)) {
      val subscription = subscriptionRepo.getSubscriptionById(id)
      if (subscription == None) {
        NotFound(CommonProps.EmptyResponse)
      } else {
        Ok(Json.toJson(subscriptionRepo.getSubscriptionById(id)))
      }
    }
    else BadRequest(Json.toJson(Error.mustBeHexadecimal("SubscriptionId")))
  }

  def deleteSubscriptionById(id: String) = Action {
    if (id.size == 24 && id.matches(CommonProps.HexadecimalRegexp)) {
      if (subscriptionRepo.deleteSubscriptionById(id) > 0) {
        Ok(CommonProps.EmptyResponse)
      }
      else NotFound(CommonProps.EmptyResponse)
    }
    else BadRequest(Json.toJson(Error.mustBeHexadecimal("SubscriptionId")))
  }

  def getAllSubscriptionsForEmail(email: String) = Action {
    if (email.matches(CommonProps.EmailRegexp)){
      Ok(Json.toJson(subscriptionRepo.findAllSubscriptionsForEmail(email)))
    } else {
      BadRequest(Json.toJson(new Error("Invalid email","Invalid email format")))
    }
  }

} 
开发者ID:oginskis,项目名称:play-vo-flats,代码行数:45,代码来源:SubscriptionController.scala


注:本文中的play.api.mvc.ControllerComponents类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。