Skip to content

Commit

Permalink
feat(pollux): PR review feedback #2
Browse files Browse the repository at this point in the history
  • Loading branch information
yshyn-iohk committed Nov 11, 2022
1 parent e095d61 commit 2df610f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import io.iohk.atala.pollux.schema.SchemaRegistryServerEndpoints
object ZHttpServer {
val log = LoggerFactory.getLogger(ZioHttpInterpreter.getClass.getName)

val defaultPort = sys.env.get("http.port").map(_.toInt).getOrElse(8085)

val defaultServerOptions: ZioHttpServerOptions[Any] =
ZioHttpServerOptions.customiseInterceptors
.serverLog(
Expand All @@ -32,7 +30,7 @@ object ZHttpServer {

def start(
endpoints: List[ZServerEndpoint[Any, Any]],
port: Int = defaultPort,
port: Int,
serverOptions: ZioHttpServerOptions[Any] = defaultServerOptions
): ZIO[Scope, Throwable, Any] =
val app: HttpApp[Any, Throwable] = ZioHttpInterpreter(serverOptions).toHttp(endpoints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,27 @@ import io.iohk.atala.pollux.schema.{VerifiableCredentialsSchemaInput, Verifiable
import java.util.UUID
import scala.collection.mutable

class SchemaRegistryServiceInMemory(
uioRef: UIO[Ref[Map[UUID, VerifiableCredentialsSchema]]] = Ref.make(Map.empty[UUID, VerifiableCredentialsSchema])
) extends SchemaRegistryService {

// val storage = new mutable.Map[UUID, VerifiableCredentialsSchema]()
class SchemaRegistryServiceInMemory(ref: Ref[Map[UUID, VerifiableCredentialsSchema]]) extends SchemaRegistryService {

// TODO: Figure out what is the logic for trying to overwrite the schema with the same id (409 Conflict)
// TODO: Other validations (same [schema_name, version], list of the attributes is not empty, etc)
override def createSchema(in: VerifiableCredentialsSchemaInput): Task[VerifiableCredentialsSchema] = {
val schema = VerifiableCredentialsSchema(in)
for {
ref <- uioRef
_ <- ref.update(s => s + (schema.id -> schema))
} yield schema
}

override def getSchemaById(id: UUID): Task[Option[VerifiableCredentialsSchema]] = {
for {
ref <- uioRef
storage <- ref.get
schema = storage.get(id)
} yield schema
}
}

object SchemaRegistryServiceInMemory {
val layer = ZLayer.succeed[SchemaRegistryService](new SchemaRegistryServiceInMemory)
val layer = ZLayer.fromZIO(
Ref.make(Map.empty[UUID, VerifiableCredentialsSchema]).map(SchemaRegistryServiceInMemory(_))
)
}

0 comments on commit 2df610f

Please sign in to comment.