diff --git a/core/shared/src/main/scala/works/iterative/core/service/Repository.scala b/core/shared/src/main/scala/works/iterative/core/service/Repository.scala index c945947..326af94 100644 --- a/core/shared/src/main/scala/works/iterative/core/service/Repository.scala +++ b/core/shared/src/main/scala/works/iterative/core/service/Repository.scala @@ -2,13 +2,23 @@ import zio.* -trait GenericReadRepository[Eff[+_], Coll[+_], -Key, +Value, -FilterArg]: +trait GenericLoadService[Eff[+_], -Key, +Value]: type Op[A] = Eff[A] - def load(id: Key): Op[Option[Value]] + +trait GenericLoadAllService[Eff[+_], Coll[+_], -Key, +Value]: + type Op[A] = Eff[A] def loadAll(ids: Seq[Key]): Op[Coll[Value]] + +trait GenericFindService[Eff[+_], Coll[+_], -Key, +Value, -FilterArg]: + type Op[A] = Eff[A] def find(filter: FilterArg): Op[Coll[Value]] +trait GenericReadRepository[Eff[+_], Coll[+_], -Key, +Value, -FilterArg] + extends GenericLoadService[Eff, Key, Value] + with GenericLoadAllService[Eff, Coll, Key, Value] + with GenericFindService[Eff, Coll, Key, Value, FilterArg] + trait GenericWriteRepository[Eff[_], -Key, -Value]: type Op[A] = Eff[A] def save(key: Key, value: Value): Op[Unit] @@ -17,6 +27,10 @@ extends GenericReadRepository[Eff, List, Key, Value, Unit] with GenericWriteRepository[Eff, Key, Value] +type LoadRepository[-Key, +Value] = GenericLoadService[UIO, Key, Value] +type LoadAllRepository[-Key, +Value] = + GenericLoadAllService[UIO, List, Key, Value] + trait ReadRepository[-Key, +Value, -FilterArg] extends GenericReadRepository[UIO, List, Key, Value, FilterArg]: override def loadAll(ids: Seq[Key]): UIO[List[Value]] = diff --git a/core/shared/src/main/scala/works/iterative/core/service/Repository.scala b/core/shared/src/main/scala/works/iterative/core/service/Repository.scala index c945947..326af94 100644 --- a/core/shared/src/main/scala/works/iterative/core/service/Repository.scala +++ b/core/shared/src/main/scala/works/iterative/core/service/Repository.scala @@ -2,13 +2,23 @@ import zio.* -trait GenericReadRepository[Eff[+_], Coll[+_], -Key, +Value, -FilterArg]: +trait GenericLoadService[Eff[+_], -Key, +Value]: type Op[A] = Eff[A] - def load(id: Key): Op[Option[Value]] + +trait GenericLoadAllService[Eff[+_], Coll[+_], -Key, +Value]: + type Op[A] = Eff[A] def loadAll(ids: Seq[Key]): Op[Coll[Value]] + +trait GenericFindService[Eff[+_], Coll[+_], -Key, +Value, -FilterArg]: + type Op[A] = Eff[A] def find(filter: FilterArg): Op[Coll[Value]] +trait GenericReadRepository[Eff[+_], Coll[+_], -Key, +Value, -FilterArg] + extends GenericLoadService[Eff, Key, Value] + with GenericLoadAllService[Eff, Coll, Key, Value] + with GenericFindService[Eff, Coll, Key, Value, FilterArg] + trait GenericWriteRepository[Eff[_], -Key, -Value]: type Op[A] = Eff[A] def save(key: Key, value: Value): Op[Unit] @@ -17,6 +27,10 @@ extends GenericReadRepository[Eff, List, Key, Value, Unit] with GenericWriteRepository[Eff, Key, Value] +type LoadRepository[-Key, +Value] = GenericLoadService[UIO, Key, Value] +type LoadAllRepository[-Key, +Value] = + GenericLoadAllService[UIO, List, Key, Value] + trait ReadRepository[-Key, +Value, -FilterArg] extends GenericReadRepository[UIO, List, Key, Value, FilterArg]: override def loadAll(ids: Seq[Key]): UIO[List[Value]] = diff --git a/core/shared/src/main/scala/works/iterative/entity/EntityService.scala b/core/shared/src/main/scala/works/iterative/entity/EntityService.scala new file mode 100644 index 0000000..d5d1ad0 --- /dev/null +++ b/core/shared/src/main/scala/works/iterative/entity/EntityService.scala @@ -0,0 +1,18 @@ +package works.iterative.entity + +import zio.* +import works.iterative.core.auth.CurrentUser + +trait EntityUpdateService[Id, Command, Error <: AggregateError]: + type Op[A] = ZIO[CurrentUser, Error, A] + + def update(id: Id, command: Command): Op[Unit] + +trait EntityCreateService[Id, Init, Error <: AggregateError]: + type Op[A] = ZIO[CurrentUser, Error, A] + + def create(initData: Init): Op[Id] + +trait EntityService[Id, Command, Error <: AggregateError, Init <: Command] + extends EntityCreateService[Id, Init, Error] + with EntityUpdateService[Id, Command, Error]