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


Scala AnyContent类代码示例

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


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

示例1: CoinController

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

import javax.inject.Inject

import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import forms.CoinAddForm
import models.User
import models.coin.{Person, WorkEntry}
import models.common.Pagination
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent}

import scala.concurrent.Future


class CoinController @Inject()(
                                val messagesApi: MessagesApi,
                                val env: Environment[User, CookieAuthenticator]
                              ) extends Silhouette[User, CookieAuthenticator] {

  val itemsPerPage = 9

  
  def remove(id: Long): Action[AnyContent] = SecuredAction.async { implicit request =>
    WorkEntry.remove(id)
    Future.successful(Redirect(routes.CoinController.landing()))
  }
} 
开发者ID:wirvomgut,项目名称:curo,代码行数:30,代码来源:CoinController.scala

示例2: MenuController

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

import javax.inject._

import com.github.nscala_time.time.Imports._
import domain.MenuRepo.menuFormat
import domain._
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, Controller}
import services.{MenuNotFound, MenuService, NoNewMenuContentFound}

class MenuController @Inject()(menuService: MenuService) extends Controller {

  def menu(fechaUltimaModificacionRef: Option[String]): Action[AnyContent] = Action {

    menuService.getLatestMenu(fechaUltimaModificacionRef) match {
      case Right(menu: Menu) => Ok(Json.toJson(menu))
      case Left(MenuNotFound()) => NotFound
      case Left(NoNewMenuContentFound()) => NoContent
      case _ => InternalServerError
    }
  }
} 
开发者ID:dtambussi,项目名称:pedidos,代码行数:24,代码来源:MenuController.scala

示例3: ApplicationController

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

import domain.{Categoria, EstadoItemDePedido, EstadoPedido, EstadoSugerencia}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, Controller}

class ApplicationController extends Controller {

  def categorias() : Action[AnyContent] = Action {
    Ok(Json.arr(Categoria.values))
  }

  def estadosDePedido() : Action[AnyContent] = Action {
    Ok(Json.arr(EstadoPedido.values))
  }

  def estadosDeItemDePedido() : Action[AnyContent] = Action {
    Ok(Json.arr(EstadoItemDePedido.values))
  }

  def estadosDeSugerencia() : Action[AnyContent] = Action {
    Ok(Json.arr(EstadoSugerencia.values))
  }
} 
开发者ID:dtambussi,项目名称:pedidos,代码行数:25,代码来源:ApplicationController.scala

示例4: Status2Controller

//设置package包名称以及导入依赖的类
package xyz.mattclifton.play.stringent.test

import play.api.mvc.{Request, AnyContent, Action, Controller}
import xyz.mattclifton.play.stringent.StringentActions
import xyz.mattclifton.play.stringent.test.helpers.FakeParsers._
import xyz.mattclifton.play.stringent.test.models.{TestResponse, TestContent}

import scala.concurrent.{ExecutionContext, Future}

class Status2Controller(implicit executionContext: ExecutionContext) extends Controller with StringentActions {
  def withBodyParser = Action.stringent.withContent[TestContent, OkResult, BadRequestResult](parse.json[TestContent]){ request =>
    Ok
  }

  def anyContent = Action.stringent.anyContent[OkResult, BadRequestResult]{ request =>
    Ok
  }

  def block = Action.stringent[OkResult, BadRequestResult]{
    Ok
  }

  def asyncBlock = Action.stringent.async[OkResult, BadRequestResult]{
    Future(Ok)
  }

  def asyncAnyContent = Action.stringent.anyContentAsync[OkResult, BadRequestResult]{ request =>
    Future(Ok)
  }

  def asyncBodyContent = Action.stringent.withContentAsync[TestContent, OkResult, BadRequestResult](parse.json[TestContent]){ request =>
    Future(Ok)
  }
} 
开发者ID:lynx44,项目名称:play-stringent,代码行数:35,代码来源:Status2Controller.scala

示例5: Route

//设置package包名称以及导入依赖的类
package com.viajobien.busy.models.routing

import com.viajobien.busy.dsl.condition.Condition
import com.viajobien.busy.models.Persistable
import play.api.mvc.{ AnyContent, Request }

abstract class Route(val path: String, endpoint: String,
    condition: Condition) extends Persistable with PathUtil {

  def satisfy(request: Request[AnyContent]): Boolean = {
    this.condition.eval(request)
  }

  def generateEndpoint(pathParameter: String): String = {
    val splittedPath = this.splitPath(this.path)
    val splittedPathParameter = this.splitPath(pathParameter, splittedPath.size)
    val zippedPath = splittedPath zip splittedPathParameter

    val wildcardsPath = zippedPath filter (z => z._1 == PATH_PART_WILDCARD || z._1 == PATH_WILDCARD)

    this.splittedEndpoint(wildcardsPath)
  }

  private def splittedEndpoint(wildcardsPath: List[(String, String)]): String = {
    def splitted(splittedEndpoint: List[String], wildcardsPath: List[(String, String)]): List[String] =
      splittedEndpoint match {
        case Nil                                        => Nil
        case (PATH_PART_WILDCARD | PATH_WILDCARD) :: es => wildcardsPath.head._2 :: splitted(es, wildcardsPath.tail)
        case e :: es                                    => e :: splitted(es, wildcardsPath)
      }

    splitted(this.splitPath(this.endpoint, dropChars = 0), wildcardsPath) mkString "/"
  }

} 
开发者ID:viajobien,项目名称:busy,代码行数:36,代码来源:Route.scala

示例6: MainController

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

import javax.inject._

import scala.concurrent.ExecutionContext

import domain.Id
import domain.wordcount.Model._
import parser.WordsBodyParsers
import play.api.Configuration
import play.api.libs.json._
import play.api.mvc.{Action, AnyContent, Controller}
import services.WordCountService
import services.WordCountService._

@Singleton
class MainController @Inject()(
  wordCountService: WordCountService,
  val configuration: Configuration,
  implicit val executionContext: ExecutionContext
) extends Controller with WordsBodyParsers {

  import json.WordCountJson._

  def index = Action {
    Ok("")
  }

  def countWords: Action[Map[String, Long]] = Action.async(parseWords.wordcount) { request =>
    wordCountService
      .createWordCount(CreateWordCountRequest(request.body))
      .map(res => Ok(Json.toJson(res.wordCount)))
  }

  def getWordCounts: Action[AnyContent] = Action.async { request =>
    wordCountService
      .findWordCounts(FindWordCountsRequest())
      .map(res => Ok(Json.toJson(res.wordCounts)))
  }

  def getWordCount(id: String): Action[AnyContent] = Action.async { request =>
    wordCountService
      .findWordCount(FindWordCountRequest(Id[WordCount](id)))
      .map(res =>
        if (res.wordCount.isDefined)
          Ok(Json.toJson(res.wordCount))
        else NotFound
      )
  }
} 
开发者ID:sebtomba,项目名称:wordcount-akka-streams,代码行数:51,代码来源:MainController.scala

示例7: DbPopulationController

//设置package包名称以及导入依赖的类
package au.id.tmm.senatedb.api.controllers

import au.id.tmm.senatedb.api.services.DbPopulationService
import au.id.tmm.senatedb.api.services.exceptions.NoSuchElectionException
import com.google.inject.{Inject, Singleton}
import play.api.mvc.{Action, AnyContent, Controller}

import scala.concurrent.ExecutionContext

@Singleton
class DbPopulationController @Inject()(dbPopulationService: DbPopulationService)
                                      (implicit ec: ExecutionContext) extends Controller {

  def populateFor(electionId: String): Action[AnyContent] = Action.async {
    dbPopulationService.beginPopulationFor(electionId)
      .map(_ => Ok(s"Begun populating for $electionId"))
      .recover {
        case _: NoSuchElectionException => NotFound(electionId) // TODO handle this with an application level error handler
        case e: DbPopulationService.Exceptions.AnotherElectionCurrentlyPopulatingException => Ok(s"Already populating ${e.election}")
      }
  }

  def checkPopulationStatusFor(electionId: String): Action[AnyContent] = Action.async {
    dbPopulationService.isElectionPopulated(electionId)
      .map(electionIsPopulated => Ok(electionIsPopulated.toString))
      .recover {
        case _: NoSuchElectionException => NotFound(electionId) // TODO handle this with an application level error handler
      }
  }
} 
开发者ID:tmccarthy,项目名称:SenateDB,代码行数:31,代码来源:DbPopulationController.scala

示例8: JSONCtrl

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

import javax.inject.Inject

import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import controllers.{ResultFormat, ViewContext}
import models.{PCMAPIUtils, User}
import org.opencompare.api.java.impl.io.KMFJSONExporter
import org.opencompare.formalizer.extractor.CellContentInterpreter
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
import play.api.mvc.{AnyContent, Request, Result}



class JSONCtrl @Inject() (
                           val messagesApi: MessagesApi,
                           val env: Environment[User, CookieAuthenticator],
                           val pcmAPIUtils : PCMAPIUtils) extends IOCtrl("json") {

  val jsonExporter = new KMFJSONExporter()
  val formalizer = new CellContentInterpreter

  val outputParametersForm = Form(
    mapping(
      "file" -> text
    )(JSONExportParameters.apply)(JSONExportParameters.unapply)
  )

  override def importPCMs(format: ResultFormat)(implicit request: Request[AnyContent], viewContext: ViewContext): Result = {
    NotFound("JSON import is not implemented yet")
  }

  override def exportPCM(implicit request: Request[AnyContent]): Result = {
    val parameters = outputParametersForm.bindFromRequest.get
    val pcmJSON = Json.parse(parameters.pcm)

    val container = pcmAPIUtils.parsePCMContainers(pcmJSON).head
    formalizer.interpretCells(container.getPcm)
    val json = jsonExporter.export(container)

    Ok(json)
  }

  case class JSONExportParameters(pcm : String)
} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:50,代码来源:JSONCtrl.scala

示例9: index

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

import play.api.mvc.{Action, Controller, AnyContent}


  def index: Action[AnyContent] = Action { request =>
    if (request.session.get("customer").isDefined) {
      Redirect(routes.LoginController.loginUser())
    } else if (request.session.get("staff").isDefined) {
      Redirect(routes.LoginController.loginStaff())
    } else {
      Ok(views.html.index(controllers.LoginController.loginForm))
    }
  }
} 
开发者ID:ioaccept,项目名称:pizza,代码行数:16,代码来源:Application.scala

示例10: searchUser

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

import forms.LoginUserForm
import models.User
import play.api.mvc.{Action, AnyContent, Controller}
import play.api.data.Form
import play.api.data.Forms._
import services.{ExtrasService, ItemService, UserService}



  def searchUser: Action[AnyContent] = Action {
    implicit request =>
      loginForm.bindFromRequest.fold(
        formWithErrors => {
          BadRequest(views.html.index(formWithErrors))
        },
        userData => {
          val exists = UserService.registeredUsers.exists(_.name == userData.name)

          if (exists) {
            val user = UserService.registeredUsers.find {
              _.name == userData.name
            }.head

            if (user.password == userData.password && user.active) {
              if (!user.admin) {
                Redirect(routes.LoginController.loginUser()) withSession("id" -> user.id.toString, "user" -> user.name, "distance" -> user.distance.toString, "customer" -> "yes")
              } else {
                Redirect(routes.LoginController.loginStaff()) withSession("id" -> user.id.toString, "user" -> user.name, "staff" -> "yes")
              }
            } else Redirect(routes.Application.index())

          } else Redirect(routes.Application.index())

        }
      )
  }


} 
开发者ID:ioaccept,项目名称:pizza,代码行数:42,代码来源:LoginController.scala

示例11: changeGott

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

import forms.GottForm
import models.Gott
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, AnyContent, Controller}



  def changeGott: Action[AnyContent] = Action { implicit request =>
    gottForm.bindFromRequest.fold(
      formWithErrors => {
        BadRequest(views.html.error("Fehler Gott"))
      },
      userData => {
        val gott = new Gott(userData.gottId, userData.userId, userData.gott, userData.passiv, userData.erweckt, userData.skill, userData.skillE,
          0)
        gott.getGesamt()
        services.GottService.changeGott(gott)
        Redirect(routes.DefController.showMemberDef(userData.userId.toString))
      })
  }
} 
开发者ID:ioaccept,项目名称:semperfidog,代码行数:25,代码来源:GottController.scala

示例12: Images

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

import java.io.File
import javax.inject.Inject

import com.smule.smg.SMGLogger
import play.Play
import play.api.mvc.{Action, AnyContent, Controller}


class Images  @Inject() () extends Controller {
  val log = SMGLogger

  def at(rootPath: String, file: String): Action[AnyContent] = Action { request =>
    if (file.contains(File.pathSeparator)) {
      log.error("Refusing to serve files outside my root: " + file)
      NotFound
    } else {
      val fileToServe = new File(Play.application.getFile(rootPath), file)
      if (fileToServe.exists) {
        Ok.sendFile(fileToServe, inline = true).withHeaders(CACHE_CONTROL -> "max-age=30")
      } else {
        NotFound
      }
    }
  }

} 
开发者ID:asen,项目名称:smg,代码行数:29,代码来源:Images.scala

示例13: ServiceHealthCheck

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

import javax.inject.{Inject, _}

import com.sharecare.lib.play.healthcheck.HealthCheckCriticality.High
import com.sharecare.lib.play.healthcheck.HealthCheckStatus.{Error, Healthy}
import com.sharecare.lib.play.healthcheck.controllers.HealthCheckController
import com.sharecare.lib.play.healthcheck.mongoDB.MongoReporterFactory
import com.sharecare.lib.play.healthcheck.{HealthCheck, HealthReporter}
import play.api.Configuration
import play.api.libs.ws.WSClient
import play.api.mvc.{Action, AnyContent, Controller}

import scala.concurrent.Await
import scala.concurrent.duration._



@Singleton
class ServiceHealthCheck @Inject() (mongoReporterFactory: MongoReporterFactory,
                                    careTeamReporter: CareTeamServiceReporter,
                                    config: Configuration,
                                    healthCheckController: HealthCheckController) extends Controller {

  lazy val mainCollection     = "collections.main"
  lazy val mongoReporters = mongoReporterFactory.report(mainCollection)

  val check: (Option[Boolean], Option[Boolean]) => Action[AnyContent] = healthCheckController.check (
    healthChecks = mongoReporters ++ Set(careTeamReporter),
    parentLabel  = config.getString("application.name"   ).getOrElse("<Specify name in conf>"   ),
    version      = config.getString("application.version").getOrElse("<Specify version in conf>")
  )
}

class CareTeamServiceReporter  @Inject() (config: Configuration, ws: WSClient) extends HealthReporter {
  val isInternal: Boolean = false

  def report: HealthCheck = {
    val careTeam = config.getConfig("application.healthchecks.careTeam")
    val url      = careTeam.flatMap(c => c.getString("url"))
    val timeout  = careTeam.flatMap(c => c.getInt("timeoutSeconds")).getOrElse(10)

    url match {
      case Some(u) => val response = Await.result(ws.url(u).get(), timeout.seconds)
        response.status match {
          case 200 => HealthCheck("CareTeamService", Healthy, High, "Ok")
          case _  => HealthCheck("CareTeamService", Error, High, response.body)
        }
      case None => HealthCheck("CareTeamService", Error, High, "careteam url has not been defined")
    }
  }
} 
开发者ID:Sharecare,项目名称:health-profile-social-history-play,代码行数:53,代码来源:ServiceHealthCheck.scala

示例14: MispCtrl

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

import javax.inject.Inject

import models.InvalidRequestError
import play.api.Logger
import play.api.libs.json.{ JsObject, JsValue }
import play.api.mvc.{ Action, AnyContent, Controller }
import services.MispSrv

import scala.concurrent.ExecutionContext

class MispCtrl @Inject() (mispSrv: MispSrv, implicit val ec: ExecutionContext) extends Controller {

  private[MispCtrl] lazy val logger = Logger(getClass)
  def modules: Action[AnyContent] = Action { _ ?
    Ok(mispSrv.moduleList)
  }

  def query: Action[JsValue] = Action.async(parse.json) { request ?
    val module = (request.body \ "module").asOpt[String].getOrElse(throw InvalidRequestError("Module parameter is not present in request"))
    val (mispType, dataJson) = request.body.as[JsObject].fields
      .collectFirst {
        case kv @ (k, _) if k != "module" ? kv
      }
      .getOrElse(throw InvalidRequestError("Request doesn't contain data to analyze"))
    val data = dataJson.asOpt[String].getOrElse(throw InvalidRequestError("Data has invalid type (expected string)"))
    mispSrv.query(module, mispType, data)
      .map(Ok(_))
  }
} 
开发者ID:CERT-BDF,项目名称:Cortex,代码行数:32,代码来源:MispCtrl.scala

示例15: get

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

import javax.inject.{ Inject, Singleton }

import play.api.Environment
import play.api.http.HttpErrorHandler
import play.api.mvc.{ Action, AnyContent }

trait AssetCtrl {
  def get(file: String): Action[AnyContent]
}

@Singleton
class AssetCtrlProd @Inject() (errorHandler: HttpErrorHandler) extends Assets(errorHandler) with AssetCtrl {
  def get(file: String): Action[AnyContent] = at("/ui", file)
}

@Singleton
class AssetCtrlDev @Inject() (environment: Environment) extends ExternalAssets(environment) with AssetCtrl {
  def get(file: String): Action[AnyContent] = {
    if (file.startsWith("bower_components/")) {
      at("ui", file)
    }
    else {
      at("ui/app", file)
    }
  }
} 
开发者ID:CERT-BDF,项目名称:Cortex,代码行数:29,代码来源:Asset.scala


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