本文整理汇总了Scala中play.api.mvc.PathBindable类的典型用法代码示例。如果您正苦于以下问题:Scala PathBindable类的具体用法?Scala PathBindable怎么用?Scala PathBindable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PathBindable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MultipartPostResponses200
//设置package包名称以及导入依赖的类
package form_data
import java.io.File
import scala.math.BigInt
import de.zalando.play.controllers.PlayPathBindables
//noinspection ScalaStyle
package yaml {
case class MultipartPostResponses200(name: BothPostResponses200Name, year: BothPostYear, fileSize: BothPostYear, fileName: BothPostResponses200Name)
case class BothPostResponses200(name: BothPostResponses200Name, year: BothPostYear, avatarSize: BothPostYear, ringtoneSize: BothPostYear)
import play.api.libs.json._
import play.api.libs.functional.syntax._
import de.zalando.play.controllers.MissingDefaultWrites
object ResponseWrites extends MissingDefaultWrites {
implicit val BothPostResponses200Writes: Writes[BothPostResponses200] = new Writes[BothPostResponses200] {
def writes(ss: BothPostResponses200) =
Json.obj(
"name" -> ss.name,
"year" -> ss.year,
"avatarSize" -> ss.avatarSize,
"ringtoneSize" -> ss.ringtoneSize
)
}
implicit val MultipartPostResponses200Writes: Writes[MultipartPostResponses200] = new Writes[MultipartPostResponses200] {
def writes(ss: MultipartPostResponses200) =
Json.obj(
"name" -> ss.name,
"year" -> ss.year,
"fileSize" -> ss.fileSize,
"fileName" -> ss.fileName
)
}
}
}
// should be defined after the package because of the https://issues.scala-lang.org/browse/SI-9922
//noinspection ScalaStyle
package object yaml {
type MultipartPostAvatar = Option[File]
type BothPostResponses200Name = Option[String]
type BothPostYear = Option[BigInt]
import play.api.mvc.{QueryStringBindable, PathBindable}
implicit val bindable_FileQuery = PlayPathBindables.queryBindableFile
implicit val bindable_BigIntQuery = PlayPathBindables.queryBindableBigInt
implicit val bindable_OptionFileQuery: QueryStringBindable[Option[File]] = PlayPathBindables.createOptionQueryBindable[File]
implicit val bindable_OptionBigIntQuery: QueryStringBindable[Option[BigInt]] = PlayPathBindables.createOptionQueryBindable[BigInt]
}
示例2: ErrorModel
//设置package包名称以及导入依赖的类
import de.zalando.play.controllers.ArrayWrapper
import de.zalando.play.controllers.PlayPathBindables
//noinspection ScalaStyle
package simple_petstore_api_yaml {
case class ErrorModel(code: Int, message: String)
case class Pet(id: Long, name: String, tag: NewPetTag)
case class NewPet(name: String, id: NewPetId, tag: NewPetTag)
import play.api.libs.json._
import play.api.libs.functional.syntax._
import de.zalando.play.controllers.MissingDefaultReads
object BodyReads extends MissingDefaultReads {
implicit val NewPetReads: Reads[NewPet] = (
(JsPath \ "name").read[String] and (JsPath \ "id").readNullable[Long] and (JsPath \ "tag").readNullable[String]
)(NewPet.apply _)
}
import play.api.libs.json._
import play.api.libs.functional.syntax._
import de.zalando.play.controllers.MissingDefaultWrites
object ResponseWrites extends MissingDefaultWrites {
implicit val PetWrites: Writes[Pet] = new Writes[Pet] {
def writes(ss: Pet) =
Json.obj(
"id" -> ss.id,
"name" -> ss.name,
"tag" -> ss.tag
)
}
}
}
// should be defined after the package because of the https://issues.scala-lang.org/browse/SI-9922
//noinspection ScalaStyle
package object simple_petstore_api_yaml {
type PetsIdDeleteResponses204 = Null
type NewPetTag = Option[String]
type PetsGetLimit = Option[Int]
type NewPetId = Option[Long]
type PetsGetTagsOpt = ArrayWrapper[String]
type PetsGetResponses200 = Seq[Pet]
type PetsGetTags = Option[PetsGetTagsOpt]
import play.api.mvc.{QueryStringBindable, PathBindable}
implicit val bindable_OptionIntQuery: QueryStringBindable[Option[Int]] = PlayPathBindables.createOptionQueryBindable[Int]
implicit val bindable_ArrayWrapperStringQuery: QueryStringBindable[ArrayWrapper[String]] = PlayPathBindables.createArrayWrapperQueryBindable[String]("csv")
implicit val bindable_OptionPetsGetTagsOptQuery: QueryStringBindable[Option[PetsGetTagsOpt]] = PlayPathBindables.createOptionQueryBindable[PetsGetTagsOpt]
}
示例3: Company
//设置package包名称以及导入依赖的类
package models
import java.util.Date
import com.github.stonexx.play.mvc.binders.enum._
import com.github.stonexx.scala.data.OrderedEnumeration
import play.api.mvc.{QueryStringBindable, PathBindable}
case class Company(id: Option[Long], name: String)
case class Computer(
id: Option[Long] = None,
name: String,
introduced: Option[Date] = None,
discontinued: Option[Date] = None,
companyId: Option[Long] = None
)
object Computer {
object forms {
object Sorts extends OrderedEnumeration {
type Sorts = Value
val Id = Value
val Name = Value
val Introduced = Value
val Discontinued = Value
val Company = Value
implicit val pathBindable : PathBindable[Ordered] = enumOrderedPathBindable(this)
implicit val queryStringBindable: QueryStringBindable[Ordered] = enumOrderedQueryStringBindable(this)
}
}
}
示例4: Task
//设置package包名称以及导入依赖的类
package models
import com.github.stonexx.play.mvc.binders.enum._
import com.github.stonexx.scala.data.OrderedEnumeration
import play.api.libs.json.{Json, OFormat}
import play.api.mvc.{PathBindable, QueryStringBindable}
case class Task(id: Option[Long], label: Option[String])
object Task {
implicit val jsonFormat: OFormat[Task] = Json.format[Task]
object forms {
import play.api.data._
import play.api.data.Forms._
val labelForm = Form(
"label" -> nonEmptyText(maxLength = 20)
)
object Sorts extends OrderedEnumeration {
type Sorts = Value
val Id = Value
val Label = Value
implicit val pathBindable : PathBindable[Ordered] = enumOrderedPathBindable(this)
implicit val queryStringBindable: QueryStringBindable[Ordered] = enumOrderedQueryStringBindable(this)
}
}
}
示例5: enumIdPathBindable
//设置package包名称以及导入依赖的类
package com.github.stonexx.play.mvc.binders
import com.github.stonexx.scala.data.OrderedEnumeration
import com.github.stonexx.scala.util.string._
import play.api.mvc.{QueryStringBindable, PathBindable}
trait EnumBinders {
def enumIdPathBindable[E <: Enumeration](enum: E): PathBindable[E#Value] = new PathBindable.Parsing[E#Value](
value => enum(value.toInt), _.id.toString,
(key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
)
def enumIdQueryStringBindable[E <: Enumeration](enum: E): QueryStringBindable[E#Value] = new QueryStringBindable.Parsing[E#Value](
value => enum(value.toInt), _.id.toString,
(key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
)
def enumNamePathBindable[E <: Enumeration](enum: E): PathBindable[E#Value] = new PathBindable.Parsing[E#Value](
value => enum.values.find(_.toString.camelToUnderscore == value.camelToUnderscore).get, _.toString,
(key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
)
def enumNameQueryStringBindable[E <: Enumeration](enum: E): QueryStringBindable[E#Value] = new QueryStringBindable.Parsing[E#Value](
value => enum.values.find(_.toString.camelToUnderscore == value.camelToUnderscore).get, _.toString,
(key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum, classOf[Enumeration].getSimpleName, e.getMessage)
)
def enumOrderedPathBindable[E <: OrderedEnumeration](enum: E): PathBindable[E#Ordered] = new PathBindable.Parsing[E#Ordered](
enum.Ordered.parse(_), _.toString,
(key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum.getClass.getName, classOf[OrderedEnumeration].getSimpleName, e.getMessage)
)
def enumOrderedQueryStringBindable[E <: OrderedEnumeration](enum: E): QueryStringBindable[E#Ordered] = new QueryStringBindable.Parsing[E#Ordered](
enum.Ordered.parse(_), _.toString,
(key, e) => "Cannot parse parameter %s as %s[%s]: %s".format(key, enum.getClass.getName, classOf[OrderedEnumeration].getSimpleName, e.getMessage)
)
// aliases
@inline def enumPathBindable[E <: Enumeration](enum: E): PathBindable[E#Value] = enumNamePathBindable(enum)
@inline def enumQueryStringBindable[E <: Enumeration](enum: E): QueryStringBindable[E#Value] = enumNameQueryStringBindable(enum)
}
示例6: URN
//设置package包名称以及导入依赖的类
package models
import play.api.mvc.PathBindable
import play.modules.reactivemongo.json._
case class URN(namespace:String="",domain:String="",textgroup:String="",work:String="",edition:String="",passage:String="",sentence:String="")
object URN {
val sentence = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)\\.([^:^\\.]+):([^:]+):([^:]+)".r
val passage = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)\\.([^:^\\.]+):([^:]+)".r
val edition = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)\\.([^:^\\.]+)".r
val work = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)\\.([^:^\\.]+)".r
val textgroup = "urn:([^:^\\.]+):([^:^\\.]+):([^:^\\.]+)".r
val domain = "urn:([^:^\\.]+):([^:^\\.]+)".r
val namespace = "^urn:([^:^\\.]+)$".r
def apply(urn: String) = urn match {
case sentence(a, b, c, d, e, f, g) => new URN(a, b, c, d, e, f, g)
case passage(a, b, c, d, e, f) => new URN(a, b, c, d, e, f)
case edition(a, b, c, d, e) => new URN(a, b, c, d, e)
case work(a, b, c, d) => new URN(a, b, c, d)
case textgroup(a, b, c) => new URN(a, b, c)
case domain(a, b) => new URN(a, b)
case namespace(a) => new URN(a)
case _ => new URN("")
}
implicit def urnPathBindable(implicit stringBinder:PathBindable[String]):PathBindable[models.URN] = new PathBindable[models.URN] {
override def bind(key:String, value:String):Either[String,models.URN] = for {
id <- stringBinder.bind(key, value).right
} yield models.URN(value)
override def unbind(key: String, value: models.URN): String = value match {
case URN(ns,"","","","","","") => "urn:"+ns
case URN(ns,dm,"","","","","") => "urn:"+ns+":"+dm
case URN(ns,dm,tg,"","","","") => "urn:"+ns+":"+dm+":"+tg
case URN(ns,dm,tg,wk,"","","") => "urn:"+ns+":"+dm+":"+tg+"."+wk
case URN(ns,dm,tg,wk,ed,"","") => "urn:"+ns+":"+dm+":"+tg+"."+wk+"."+ed
case URN(ns,dm,tg,wk,ed,ps,"") => "urn:"+ns+":"+dm+":"+tg+"."+wk+"."+ed+":"+ps
case URN(ns,dm,tg,wk,ed,ps,sn) => "urn:"+ns+":"+dm+":"+tg+"."+wk+"."+ed+":"+ps+"."+sn
case _ => "urn:"
}
}
}
case class Word(id:String, form:String, lemma:String, morphology:Map[String,String], head:String, relation:String)
case class Sentence(_id:URN,words:Seq[Word])
// case class Adress(val scheme:String, )
object JsonFormats {
import play.api.libs.json.Json
implicit val urnFormat = Json.format[URN]
implicit val wordFormat = Json.format[Word]
implicit val sentenceFormat = Json.format[Sentence]
}
示例7: EmprefBindable
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.models
import play.api.mvc.PathBindable
import uk.gov.hmrc.domain.EmpRef
import scala.util.{Failure, Success, Try}
object EmprefBindable extends PathBindable[EmpRef] {
override def bind(key: String, value: String): Either[String, EmpRef] = Try(EmpRef.fromIdentifiers(value)) match {
case Success(e) => Right(e)
case Failure(t) => Left(t.getMessage)
}
override def unbind(key: String, e: EmpRef): String = s"${e.taxOfficeNumber}/${e.taxOfficeReference}"
}
object PlayBindings {
implicit val emprefBindable = EmprefBindable
}
示例8: loginBinder
//设置package包名称以及导入依赖的类
package commons.controllers
import commons.models.Login
import play.api.mvc.{PathBindable}
import scala.util.Right
package object binders {
implicit def loginBinder(implicit stringBinder: PathBindable[String]) = new PathBindable[Login] {
override def bind(key: String, value: String) : Either[String, Login] = {
stringBinder.bind("login", value) match {
case Right(login) => Right(Login(login))
case _ => Left("Unable to bind login.")
}
}
override def unbind(key: String, login: Login): String = stringBinder.unbind("login", login.value)
}
}
示例9: bind
//设置package包名称以及导入依赖的类
package com.clemble.loveit.payment
import java.time.YearMonth
import play.api.mvc.PathBindable
package object controller {
implicit val stringToYearMonth: PathBindable[YearMonth] = new PathBindable[YearMonth] {
override def bind(key: String, value: String): Either[String, YearMonth] = {
val yom = value.split("/")
if (yom.length == 2) {
Right(YearMonth.of(yom(0).toInt, yom(1).toInt))
} else {
Left(value)
}
}
override def unbind(key: String, value: YearMonth): String = {
s"${value.getYear}/${value.getMonthValue}"
}
}
}
示例10: PathBinders
//设置package包名称以及导入依赖的类
package utils.extension
import play.api.mvc.PathBindable
object PathBinders {
implicit def bindableOption[T: PathBindable] = new PathBindable[Option[T]] {
def bind(key: String, value: String): Either[String, Option[T]] =
implicitly[PathBindable[T]]
.bind(key, value)
.fold(left => Left(left), right => Right(Some(right)))
def unbind(key: String, value: Option[T]): String =
value.map(_.toString).getOrElse("")
}
}
示例11: AppPathBinders
//设置package包名称以及导入依赖的类
package helpers
import models.PK
import play.api.mvc.PathBindable
object AppPathBinders {
implicit def pkPathBindable(implicit _pkBinder: PathBindable[String]) = new PathBindable[PK] {
def bind(key: String, value: String): Either[String, PK] =
for {
pk <- _pkBinder.bind(key, value).right
} yield PK(pk)
def unbind(key: String, pk: PK): String =
_pkBinder.unbind(key, pk.id.toString)
}
}
示例12: BSONObjectIDPathBindable
//设置package包名称以及导入依赖的类
import models._
import play.api.mvc.PathBindable
import reactivemongo.bson.BSONObjectID
import scala.util.{Failure, Success}
package object binders {
implicit object BSONObjectIDPathBindable extends PathBindable[Id] {
val b = implicitly[PathBindable[String]]
def bind(key: String, value: String): Either[String, Id] = {
b.bind(key, value).right.flatMap { v =>
BSONObjectID.parse(v) match {
case Success(bson) => Right(bson)
case Failure(ex) => Left("Error parse id from request.")
}
}
}
def unbind(key: String, value: Id): String =
b.unbind(key, value.stringify)
}
}
示例13: queryStringBinder
//设置package包名称以及导入依赖的类
package com.talenthouse.enum
import play.api.libs.json.{ Json, JsString }
import play.api.mvc.{ JavascriptLiteral, PathBindable, QueryStringBindable }
import com.netaporter.uri.{ PathPart, QueryString }
import com.netaporter.uri.config.UriConfig
trait SealedBindableEnumeration {
self: BaseSealedEnumeration =>
implicit def queryStringBinder = new QueryStringBindable[Value] {
def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, Value]] = {
for {
values <- params.get(key)
value <- values.headOption
} yield {
withName(value)
.toRight(s"Invalid value for $key: $value")
}
}
def unbind(key: String, o: Value): String = {
QueryString(Seq((key, Some(o.value))))
.queryToString(UriConfig.default)
.drop(1) // Drop leading `?'
}
}
implicit def pathBindable = new PathBindable[Value] {
def unbind(key: String, value: Value): String = {
PathPart(value.value)
.partToString(UriConfig.default)
}
def bind(key: String, value: String): Either[String, Value] = {
withName(value)
.toRight(s"Invalid value for $key: $value")
}
}
implicit def jsLiteral: JavascriptLiteral[Value] = new JavascriptLiteral[Value] {
def to(value: Value) = Json.stringify(JsString(value.value))
}
}
示例14: Binders
//设置package包名称以及导入依赖的类
package org.splink.pagelets
import play.api.mvc.PathBindable
object Binders {
implicit object PathBindableSymbol extends PathBindable[Symbol] {
def bind(key: String, value: String) = try {
Right(Symbol(value))
} catch {
case _: Throwable =>
Left(s"Can't create a Symbol from '$key'")
}
def unbind(key: String, value: Symbol): String = value.name
}
}
示例15: Binders
//设置package包名称以及导入依赖的类
package controllers.converters
import models.{CommentId, UserId}
import play.api.mvc.PathBindable
object Binders {
implicit val userId: PathBindable[UserId] = new PathBindable[UserId] {
override def bind(key: String, value: String) = Right(UserId(value.toLong))
override def unbind(key: String, value: UserId) = value.value.toString
}
implicit val commentId: PathBindable[CommentId] = new PathBindable[CommentId] {
override def bind(key: String, value: String) = Right(CommentId(value.toLong))
override def unbind(key: String, value: CommentId) = value.value.toString
}
}