/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/nicolai-moraru/joglog-api/0.0.1-dev/play_2_x_standalone_json */ package nm.joglog.api.v0.models { /** * Time entry * * @param id Unique time id * @param distance Distance in meters * @param time Time in seconds * @param createdAt Creation date-time * @param updatedAt Last update date-time */ final case class Time( id: Int, distance: Int, time: Int, createdAt: _root_.org.joda.time.DateTime, updatedAt: _root_.org.joda.time.DateTime ) /** * Time entry * * @param distance Distance in meters * @param time Time in seconds */ final case class TimeMinimal( distance: Int, time: Int ) /** * Time patch entry */ final case class TimePatchEntry( op: .models.Operation, path: time.models.Path, value: Int ) /** * User * * @param id Unique user id * @param username Username * @param role User Role * @param createdAt Creation date-time * @param updatedAt Last update date-time */ final case class User( id: Int, username: String, role: .models.Role, createdAt: _root_.org.joda.time.DateTime, updatedAt: _root_.org.joda.time.DateTime ) /** * User * * @param username Username * @param password Password */ final case class UserMinimal( username: String, password: String ) /** * User patch entry */ final case class UserPatchEntry( op: .models.Operation, path: user.models.Path, value: nm.joglog.api.v0.models.StringOrInteger ) /** * Patch operation */ sealed trait PatchOperation extends _root_.scala.Product with _root_.scala.Serializable object PatchOperation { case object Test extends PatchOperation { override def toString = "test" } case object Replace extends PatchOperation { override def toString = "replace" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends PatchOperation /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[PatchOperation] = scala.List(Test, Replace) private val byName: Map[String, PatchOperation] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): PatchOperation = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[PatchOperation] = byName.get(value.toLowerCase) } /** * Integer for ID or string for any other */ sealed trait StringOrInteger extends _root_.scala.Product with _root_.scala.Serializable object StringOrInteger { case object String extends StringOrInteger { override def toString = "string" } case object Integer extends StringOrInteger { override def toString = "integer" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends StringOrInteger /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[StringOrInteger] = scala.List(String, Integer) private val byName: Map[String, StringOrInteger] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): StringOrInteger = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[StringOrInteger] = byName.get(value.toLowerCase) } /** * Time patch field path (id only for test) */ sealed trait TimePatchPath extends _root_.scala.Product with _root_.scala.Serializable object TimePatchPath { case object Distance extends TimePatchPath { override def toString = "distance" } case object Time extends TimePatchPath { override def toString = "time" } case object Id extends TimePatchPath { override def toString = "id" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends TimePatchPath /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[TimePatchPath] = scala.List(Distance, Time, Id) private val byName: Map[String, TimePatchPath] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): TimePatchPath = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[TimePatchPath] = byName.get(value.toLowerCase) } /** * User patch field path (id only for test) */ sealed trait UserPatchPath extends _root_.scala.Product with _root_.scala.Serializable object UserPatchPath { case object Username extends UserPatchPath { override def toString = "username" } case object Password extends UserPatchPath { override def toString = "password" } case object Role extends UserPatchPath { override def toString = "role" } case object Id extends UserPatchPath { override def toString = "id" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends UserPatchPath /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[UserPatchPath] = scala.List(Username, Password, Role, Id) private val byName: Map[String, UserPatchPath] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): UserPatchPath = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[UserPatchPath] = byName.get(value.toLowerCase) } /** * User Role */ sealed trait UserRole extends _root_.scala.Product with _root_.scala.Serializable object UserRole { /** * Regular user */ case object User extends UserRole { override def toString = "user" } /** * User manager */ case object Manager extends UserRole { override def toString = "manager" } /** * The God himself */ case object Admin extends UserRole { override def toString = "admin" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends UserRole /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[UserRole] = scala.List(User, Manager, Admin) private val byName: Map[String, UserRole] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): UserRole = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[UserRole] = byName.get(value.toLowerCase) } } package nm.joglog.api.v0.models { package object json { import play.api.libs.json.__ import play.api.libs.json.JsString import play.api.libs.json.Writes import play.api.libs.functional.syntax._ import nm.joglog.api.v0.models.json._ private[v0] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v0] implicit val jsonWritesUUID: play.api.libs.json.Writes[_root_.java.util.UUID] = (x: _root_.java.util.UUID) => play.api.libs.json.JsString(x.toString) private[v0] implicit val jsonReadsJodaDateTime: play.api.libs.json.Reads[_root_.org.joda.time.DateTime] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(str) } private[v0] implicit val jsonWritesJodaDateTime: play.api.libs.json.Writes[_root_.org.joda.time.DateTime] = (x: _root_.org.joda.time.DateTime) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(x)) } private[v0] implicit val jsonReadsJodaLocalDate: play.api.libs.json.Reads[_root_.org.joda.time.LocalDate] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(str) } private[v0] implicit val jsonWritesJodaLocalDate: play.api.libs.json.Writes[_root_.org.joda.time.LocalDate] = (x: _root_.org.joda.time.LocalDate) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.date.print(x)) } implicit val jsonReadsJoglogApiPatchOperation: play.api.libs.json.Reads[nm.joglog.api.v0.models.PatchOperation] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.PatchOperation] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.PatchOperation] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.PatchOperation(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.PatchOperation(v)) case _: play.api.libs.json.JsError => (js \ "patch.operation").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.PatchOperation(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiPatchOperation(obj: nm.joglog.api.v0.models.PatchOperation) = { play.api.libs.json.JsString(obj.toString) } def jsObjectPatchOperation(obj: nm.joglog.api.v0.models.PatchOperation) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiPatchOperation: play.api.libs.json.Writes[PatchOperation] = { (obj: nm.joglog.api.v0.models.PatchOperation) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiPatchOperation(obj) } } implicit val jsonReadsJoglogApiStringOrInteger: play.api.libs.json.Reads[nm.joglog.api.v0.models.StringOrInteger] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.StringOrInteger] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.StringOrInteger] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.StringOrInteger(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.StringOrInteger(v)) case _: play.api.libs.json.JsError => (js \ "stringOrInteger").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.StringOrInteger(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiStringOrInteger(obj: nm.joglog.api.v0.models.StringOrInteger) = { play.api.libs.json.JsString(obj.toString) } def jsObjectStringOrInteger(obj: nm.joglog.api.v0.models.StringOrInteger) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiStringOrInteger: play.api.libs.json.Writes[StringOrInteger] = { (obj: nm.joglog.api.v0.models.StringOrInteger) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiStringOrInteger(obj) } } implicit val jsonReadsJoglogApiTimePatchPath: play.api.libs.json.Reads[nm.joglog.api.v0.models.TimePatchPath] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.TimePatchPath] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.TimePatchPath] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.TimePatchPath(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.TimePatchPath(v)) case _: play.api.libs.json.JsError => (js \ "time.patch.path").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.TimePatchPath(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiTimePatchPath(obj: nm.joglog.api.v0.models.TimePatchPath) = { play.api.libs.json.JsString(obj.toString) } def jsObjectTimePatchPath(obj: nm.joglog.api.v0.models.TimePatchPath) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiTimePatchPath: play.api.libs.json.Writes[TimePatchPath] = { (obj: nm.joglog.api.v0.models.TimePatchPath) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiTimePatchPath(obj) } } implicit val jsonReadsJoglogApiUserPatchPath: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserPatchPath] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.UserPatchPath] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.UserPatchPath] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserPatchPath(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserPatchPath(v)) case _: play.api.libs.json.JsError => (js \ "user.patch.path").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserPatchPath(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiUserPatchPath(obj: nm.joglog.api.v0.models.UserPatchPath) = { play.api.libs.json.JsString(obj.toString) } def jsObjectUserPatchPath(obj: nm.joglog.api.v0.models.UserPatchPath) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiUserPatchPath: play.api.libs.json.Writes[UserPatchPath] = { (obj: nm.joglog.api.v0.models.UserPatchPath) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiUserPatchPath(obj) } } implicit val jsonReadsJoglogApiUserRole: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserRole] = new play.api.libs.json.Reads[nm.joglog.api.v0.models.UserRole] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[nm.joglog.api.v0.models.UserRole] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserRole(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserRole(v)) case _: play.api.libs.json.JsError => (js \ "user.role").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(nm.joglog.api.v0.models.UserRole(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesJoglogApiUserRole(obj: nm.joglog.api.v0.models.UserRole) = { play.api.libs.json.JsString(obj.toString) } def jsObjectUserRole(obj: nm.joglog.api.v0.models.UserRole) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesJoglogApiUserRole: play.api.libs.json.Writes[UserRole] = { (obj: nm.joglog.api.v0.models.UserRole) => { nm.joglog.api.v0.models.json.jsonWritesJoglogApiUserRole(obj) } } implicit def jsonReadsJoglogApiTime: play.api.libs.json.Reads[nm.joglog.api.v0.models.Time] = { for { id <- (__ \ "id").read[Int] distance <- (__ \ "distance").read[Int] time <- (__ \ "time").read[Int] createdAt <- (__ \ "createdAt").read[_root_.org.joda.time.DateTime] updatedAt <- (__ \ "updatedAt").read[_root_.org.joda.time.DateTime] } yield Time(id, distance, time, createdAt, updatedAt) } def jsObjectTime(obj: nm.joglog.api.v0.models.Time): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "id" -> play.api.libs.json.JsNumber(obj.id), "distance" -> play.api.libs.json.JsNumber(obj.distance), "time" -> play.api.libs.json.JsNumber(obj.time), "createdAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.createdAt)), "updatedAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.updatedAt)) ) } implicit def jsonWritesJoglogApiTime: play.api.libs.json.Writes[Time] = { (obj: nm.joglog.api.v0.models.Time) => { nm.joglog.api.v0.models.json.jsObjectTime(obj) } } implicit def jsonReadsJoglogApiTimeMinimal: play.api.libs.json.Reads[nm.joglog.api.v0.models.TimeMinimal] = { for { distance <- (__ \ "distance").read[Int] time <- (__ \ "time").read[Int] } yield TimeMinimal(distance, time) } def jsObjectTimeMinimal(obj: nm.joglog.api.v0.models.TimeMinimal): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "distance" -> play.api.libs.json.JsNumber(obj.distance), "time" -> play.api.libs.json.JsNumber(obj.time) ) } implicit def jsonWritesJoglogApiTimeMinimal: play.api.libs.json.Writes[TimeMinimal] = { (obj: nm.joglog.api.v0.models.TimeMinimal) => { nm.joglog.api.v0.models.json.jsObjectTimeMinimal(obj) } } implicit def jsonReadsJoglogApiTimePatchEntry: play.api.libs.json.Reads[nm.joglog.api.v0.models.TimePatchEntry] = { for { op <- (__ \ "op").read[.models.Operation] path <- (__ \ "path").read[time.models.Path] value <- (__ \ "value").read[Int] } yield TimePatchEntry(op, path, value) } def jsObjectTimePatchEntry(obj: nm.joglog.api.v0.models.TimePatchEntry): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "op" -> play.api.libs.json.JsString(obj.op.toString), "path" -> play.api.libs.json.JsString(obj.path.toString), "value" -> play.api.libs.json.JsNumber(obj.value) ) } implicit def jsonWritesJoglogApiTimePatchEntry: play.api.libs.json.Writes[TimePatchEntry] = { (obj: nm.joglog.api.v0.models.TimePatchEntry) => { nm.joglog.api.v0.models.json.jsObjectTimePatchEntry(obj) } } implicit def jsonReadsJoglogApiUser: play.api.libs.json.Reads[nm.joglog.api.v0.models.User] = { for { id <- (__ \ "id").read[Int] username <- (__ \ "username").read[String] role <- (__ \ "role").read[.models.Role] createdAt <- (__ \ "createdAt").read[_root_.org.joda.time.DateTime] updatedAt <- (__ \ "updatedAt").read[_root_.org.joda.time.DateTime] } yield User(id, username, role, createdAt, updatedAt) } def jsObjectUser(obj: nm.joglog.api.v0.models.User): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "id" -> play.api.libs.json.JsNumber(obj.id), "username" -> play.api.libs.json.JsString(obj.username), "role" -> play.api.libs.json.JsString(obj.role.toString), "createdAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.createdAt)), "updatedAt" -> play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(obj.updatedAt)) ) } implicit def jsonWritesJoglogApiUser: play.api.libs.json.Writes[User] = { (obj: nm.joglog.api.v0.models.User) => { nm.joglog.api.v0.models.json.jsObjectUser(obj) } } implicit def jsonReadsJoglogApiUserMinimal: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserMinimal] = { for { username <- (__ \ "username").read[String] password <- (__ \ "password").read[String] } yield UserMinimal(username, password) } def jsObjectUserMinimal(obj: nm.joglog.api.v0.models.UserMinimal): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "username" -> play.api.libs.json.JsString(obj.username), "password" -> play.api.libs.json.JsString(obj.password) ) } implicit def jsonWritesJoglogApiUserMinimal: play.api.libs.json.Writes[UserMinimal] = { (obj: nm.joglog.api.v0.models.UserMinimal) => { nm.joglog.api.v0.models.json.jsObjectUserMinimal(obj) } } implicit def jsonReadsJoglogApiUserPatchEntry: play.api.libs.json.Reads[nm.joglog.api.v0.models.UserPatchEntry] = { for { op <- (__ \ "op").read[.models.Operation] path <- (__ \ "path").read[user.models.Path] value <- (__ \ "value").read[nm.joglog.api.v0.models.StringOrInteger] } yield UserPatchEntry(op, path, value) } def jsObjectUserPatchEntry(obj: nm.joglog.api.v0.models.UserPatchEntry): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "op" -> play.api.libs.json.JsString(obj.op.toString), "path" -> play.api.libs.json.JsString(obj.path.toString), "value" -> play.api.libs.json.JsString(obj.value.toString) ) } implicit def jsonWritesJoglogApiUserPatchEntry: play.api.libs.json.Writes[UserPatchEntry] = { (obj: nm.joglog.api.v0.models.UserPatchEntry) => { nm.joglog.api.v0.models.json.jsObjectUserPatchEntry(obj) } } } }