Skip to content

Commit

Permalink
Process version decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkp96 committed Sep 23, 2024
1 parent 6812e96 commit 1e5168e
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package pl.touk.nussknacker.engine.api

import io.circe.generic.JsonCodec
import io.circe.{Decoder, Encoder}
import pl.touk.nussknacker.engine.api.process.{ProcessId, ProcessName, VersionId}

// We should split this class - see TODO in ScenarioAction
@JsonCodec case class ProcessVersion(
case class ProcessVersion(
versionId: VersionId,
processName: ProcessName,
processId: ProcessId,
Expand All @@ -25,4 +25,26 @@ object ProcessVersion {
modelVersion = None
)

implicit val encoder: Encoder[ProcessVersion] = io.circe.generic.semiauto.deriveEncoder

implicit val decoder: Decoder[ProcessVersion] = {
Decoder.instance { c =>
for {
versionId <- c.downField("versionId").as[VersionId]
processName <- c.downField("processName").as[ProcessName]
processId <- c.downField("processId").as[ProcessId]
labels <- c.downField("labels").as[Option[List[String]]]
user <- c.downField("user").as[String]
modelVersion <- c.downField("modelVersion").as[Option[Int]]
} yield ProcessVersion(
versionId,
processName,
processId,
labels.getOrElse(List.empty),
user,
modelVersion
)
}
}

}

0 comments on commit 1e5168e

Please sign in to comment.