Skip to content

Instantly share code, notes, and snippets.

@ubourdon
Created October 25, 2022 12:58
Show Gist options
  • Save ubourdon/8c432be9fc9e32ba31c729eb80daed0e to your computer and use it in GitHub Desktop.
Save ubourdon/8c432be9fc9e32ba31c729eb80daed0e to your computer and use it in GitHub Desktop.
Transco
sealed trait ExternalSystemIds
object ExternalSystemIds {
/**
* Les informations qui permettent d'identifier le Client dans la base Harvest
* @param uid
* @param cabinet
*/
case class HarvestSync(uid: HarvestContactId, cabinet: HarvestCabinetId) extends ExternalSystemIds
}
import pi.app.infrastructure.harvest.service.models.{HarvestCabinetId, HarvestContactId}
import pi.app.infrastructure.transco.Transco.Sens.{FromExterne, FromInterne}
import pi.app.infrastructure.transco.extrernalsystem.ExternalSystemIds
import pi.app.infrastructure.transco.extrernalsystem.ExternalSystemIds.HarvestSync
import pi.prelude.safeuuid.SafeUUID
object Transco {
def retrieve[A <: TranscoReq](req: Sens[A]): Transco[A] = req match {
case FromInterne(uid) => ???
case FromExterne(x) => x.req; ???
}
sealed trait Sens[+A]
object Sens {
case class FromInterne(uid: SafeUUID) extends Sens[Nothing]
case class FromExterne[A](x: A) extends Sens[A]
}
case class Transco[A](typee: String, interne: SafeUUID, externe: A) {
def map[B](f: A => B): Transco[B] = this.copy(externe = f(externe))
}
sealed trait TranscoReq {
def req: String
}
case class TranscoReq1(id1: String, id2: String) extends TranscoReq {
override val req: String = s"where id1=$id1"
}
case class TranscoReq2(id1: String, id2: String) extends TranscoReq {
override val req: String = s"where id1=$id1 and id2=$id2"
}
val h = HarvestSync(HarvestContactId("dslkds"), HarvestCabinetId("dslkdsmlk"))
val t = TranscoReq2(h.cabinet, h.uid)
val toto: Transco[TranscoReq2] = retrieve(FromExterne(t))
val i: SafeUUID = toto.interne
val titi: Transco[ExternalSystemIds] = retrieve[TranscoReq2](FromInterne(SafeUUID.generate))
.map { x => HarvestSync(HarvestContactId(x.id1), HarvestCabinetId(x.id2)) }
val e: ExternalSystemIds = titi.externe
}
/**
=> Evt 02S id cab, id contact
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment