Newer
Older
support / domain / proof / command / client / src / ProofCommandApi.scala
Michal Prihoda on 10 Mar 2022 835 bytes Working journal.
package mdr.pdb.proof.command
package client

import endpoints.Endpoints

import zio.*
import fiftyforms.tapir.CustomTapir
import fiftyforms.tapir.BaseUri

trait ProofCommandApi:
  def submitCommand(command: Command): Task[Unit]

object ProofCommandApi:
  def submitCommand(command: Command): RIO[ProofCommandApi, Unit] =
    ZIO.serviceWithZIO(_.submitCommand(command))

object ProofCommandApiLive:
  val layer: URLayer[BaseUri & CustomTapir.Backend, ProofCommandApi] =
    (ProofCommandApiLive(using _, _)).toLayer

class ProofCommandApiLive(using baseUri: BaseUri, backend: CustomTapir.Backend)
    extends ProofCommandApi
    with CustomTapir:
  private val submitCommandClient = makeClient(Endpoints.submitCommand)
  override def submitCommand(command: Command): Task[Unit] =
    ZIO.fromFuture(_ => submitCommandClient(command))