/** * 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/http4s_0_22 */ 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_.java.time.Instant, updatedAt: _root_.java.time.Instant ) /** * 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_.java.time.Instant, updatedAt: _root_.java.time.Instant ) /** * 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 io.circe.Decoder._ import io.circe.Encoder._ import scala.language.implicitConversions // See below - Make Scala 2.11 Either monadic import scala.util.Try import io.circe.{Json, JsonObject, Encoder, Decoder, DecodingFailure} import io.circe.syntax._ import nm.joglog.api.v0.models.json._ // Make Scala 2.11 Either monadic private[v0] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[v0] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[v0] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[v0] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[v0] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[v0] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[v0] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit val jsonDecoderJoglogApiPatchOperation: Decoder[nm.joglog.api.v0.models.PatchOperation] = Decoder.decodeString.map(nm.joglog.api.v0.models.PatchOperation(_)) implicit val jsonEncoderJoglogApiPatchOperation: Encoder[nm.joglog.api.v0.models.PatchOperation] = Encoder.encodeString.contramap[nm.joglog.api.v0.models.PatchOperation](_.toString) implicit val jsonDecoderJoglogApiStringOrInteger: Decoder[nm.joglog.api.v0.models.StringOrInteger] = Decoder.decodeString.map(nm.joglog.api.v0.models.StringOrInteger(_)) implicit val jsonEncoderJoglogApiStringOrInteger: Encoder[nm.joglog.api.v0.models.StringOrInteger] = Encoder.encodeString.contramap[nm.joglog.api.v0.models.StringOrInteger](_.toString) implicit val jsonDecoderJoglogApiTimePatchPath: Decoder[nm.joglog.api.v0.models.TimePatchPath] = Decoder.decodeString.map(nm.joglog.api.v0.models.TimePatchPath(_)) implicit val jsonEncoderJoglogApiTimePatchPath: Encoder[nm.joglog.api.v0.models.TimePatchPath] = Encoder.encodeString.contramap[nm.joglog.api.v0.models.TimePatchPath](_.toString) implicit val jsonDecoderJoglogApiUserPatchPath: Decoder[nm.joglog.api.v0.models.UserPatchPath] = Decoder.decodeString.map(nm.joglog.api.v0.models.UserPatchPath(_)) implicit val jsonEncoderJoglogApiUserPatchPath: Encoder[nm.joglog.api.v0.models.UserPatchPath] = Encoder.encodeString.contramap[nm.joglog.api.v0.models.UserPatchPath](_.toString) implicit val jsonDecoderJoglogApiUserRole: Decoder[nm.joglog.api.v0.models.UserRole] = Decoder.decodeString.map(nm.joglog.api.v0.models.UserRole(_)) implicit val jsonEncoderJoglogApiUserRole: Encoder[nm.joglog.api.v0.models.UserRole] = Encoder.encodeString.contramap[nm.joglog.api.v0.models.UserRole](_.toString) implicit def decodeJoglogApiTime: Decoder[Time] = Decoder.instance { c => for { id <- c.downField("id").as[Int] distance <- c.downField("distance").as[Int] time <- c.downField("time").as[Int] createdAt <- c.downField("createdAt").as[_root_.java.time.Instant] updatedAt <- c.downField("updatedAt").as[_root_.java.time.Instant] } yield { Time( id = id, distance = distance, time = time, createdAt = createdAt, updatedAt = updatedAt ) } } implicit def encodeJoglogApiTime: Encoder[Time] = Encoder.instance { t => Json.fromFields(Seq( Some("id" -> t.id.asJson), Some("distance" -> t.distance.asJson), Some("time" -> t.time.asJson), Some("createdAt" -> t.createdAt.asJson), Some("updatedAt" -> t.updatedAt.asJson) ).flatten) } implicit def decodeJoglogApiTimeMinimal: Decoder[TimeMinimal] = Decoder.instance { c => for { distance <- c.downField("distance").as[Int] time <- c.downField("time").as[Int] } yield { TimeMinimal( distance = distance, time = time ) } } implicit def encodeJoglogApiTimeMinimal: Encoder[TimeMinimal] = Encoder.instance { t => Json.fromFields(Seq( Some("distance" -> t.distance.asJson), Some("time" -> t.time.asJson) ).flatten) } implicit def decodeJoglogApiTimePatchEntry: Decoder[TimePatchEntry] = Decoder.instance { c => for { op <- c.downField("op").as[.models.Operation] path <- c.downField("path").as[time.models.Path] value <- c.downField("value").as[Int] } yield { TimePatchEntry( op = op, path = path, value = value ) } } implicit def encodeJoglogApiTimePatchEntry: Encoder[TimePatchEntry] = Encoder.instance { t => Json.fromFields(Seq( Some("op" -> t.op.asJson), Some("path" -> t.path.asJson), Some("value" -> t.value.asJson) ).flatten) } implicit def decodeJoglogApiUser: Decoder[User] = Decoder.instance { c => for { id <- c.downField("id").as[Int] username <- c.downField("username").as[String] role <- c.downField("role").as[.models.Role] createdAt <- c.downField("createdAt").as[_root_.java.time.Instant] updatedAt <- c.downField("updatedAt").as[_root_.java.time.Instant] } yield { User( id = id, username = username, role = role, createdAt = createdAt, updatedAt = updatedAt ) } } implicit def encodeJoglogApiUser: Encoder[User] = Encoder.instance { t => Json.fromFields(Seq( Some("id" -> t.id.asJson), Some("username" -> t.username.asJson), Some("role" -> t.role.asJson), Some("createdAt" -> t.createdAt.asJson), Some("updatedAt" -> t.updatedAt.asJson) ).flatten) } implicit def decodeJoglogApiUserMinimal: Decoder[UserMinimal] = Decoder.instance { c => for { username <- c.downField("username").as[String] password <- c.downField("password").as[String] } yield { UserMinimal( username = username, password = password ) } } implicit def encodeJoglogApiUserMinimal: Encoder[UserMinimal] = Encoder.instance { t => Json.fromFields(Seq( Some("username" -> t.username.asJson), Some("password" -> t.password.asJson) ).flatten) } implicit def decodeJoglogApiUserPatchEntry: Decoder[UserPatchEntry] = Decoder.instance { c => for { op <- c.downField("op").as[.models.Operation] path <- c.downField("path").as[user.models.Path] value <- c.downField("value").as[nm.joglog.api.v0.models.StringOrInteger] } yield { UserPatchEntry( op = op, path = path, value = value ) } } implicit def encodeJoglogApiUserPatchEntry: Encoder[UserPatchEntry] = Encoder.instance { t => Json.fromFields(Seq( Some("op" -> t.op.asJson), Some("path" -> t.path.asJson), Some("value" -> t.value.asJson) ).flatten) } } }