Skip to content

Commit

Permalink
Fix routing parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dbulaja98 committed Dec 26, 2022
1 parent 56e8d82 commit f7efdab
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sealed trait ElasticRequest[+A, RequestType <: ElasticRequestType] { self =>
final def refresh(implicit addRefresh: AddRefresh[RequestType]): ElasticRequest[A, RequestType] =
addRefresh.addRefresh(self)

final def routing(value: String)(implicit addRouting: AddRouting[RequestType]): ElasticRequest[A, RequestType] =
final def routing(value: Routing)(implicit addRouting: AddRouting[RequestType]): ElasticRequest[A, RequestType] =
addRouting.addRouting(self, value)
}

Expand Down Expand Up @@ -124,52 +124,55 @@ object ElasticRequest {
mapper: A => B
) extends ElasticRequest[B, T]

private trait AddRouting[T <: ElasticRequestType] {
def addRouting[A](req: ElasticRequest[A, T], routing: String): ElasticRequest[A, T]
trait AddRouting[T <: ElasticRequestType] {
def addRouting[A](req: ElasticRequest[A, T], routing: Routing): ElasticRequest[A, T]
}

object AddRouting {
implicit val addRoutingToCreate: AddRouting[CreateType] = new AddRouting[CreateType] {
override def addRouting[A](req: ElasticRequest[A, CreateType], routing: String): ElasticRequest[A, CreateType] =
override def addRouting[A](req: ElasticRequest[A, CreateType], routing: Routing): ElasticRequest[A, CreateType] =
req match {
case Map(r, mapper) => Map(addRouting(r, routing), mapper)
case r: Create => r.copy(routing = Some(Routing(routing)))
case r: Create => r.copy(routing = Some(routing))
}
}
implicit val addRoutingToDeleteById: AddRouting[DeleteByIdType] = new AddRouting[DeleteByIdType] {
override def addRouting[A](
req: ElasticRequest[A, DeleteByIdType],
routing: String
routing: Routing
): ElasticRequest[A, DeleteByIdType] =
req match {
case Map(r, mapper) => Map(addRouting(r, routing), mapper)
case r: DeleteById => r.copy(routing = Some(Routing(routing)))
case r: DeleteById => r.copy(routing = Some(routing))
}
}
implicit val addRoutingToExists: AddRouting[ExistsType] = new AddRouting[ExistsType] {
override def addRouting[A](req: ElasticRequest[A, ExistsType], routing: String): ElasticRequest[A, ExistsType] =
override def addRouting[A](req: ElasticRequest[A, ExistsType], routing: Routing): ElasticRequest[A, ExistsType] =
req match {
case Map(r, mapper) => Map(addRouting(r, routing), mapper)
case r: Exists => r.copy(routing = Some(Routing(routing)))
case r: Exists => r.copy(routing = Some(routing))
}
}
implicit val addRoutingToGetById: AddRouting[GetByIdType] = new AddRouting[GetByIdType] {
override def addRouting[A](req: ElasticRequest[A, GetByIdType], routing: String): ElasticRequest[A, GetByIdType] =
override def addRouting[A](
req: ElasticRequest[A, GetByIdType],
routing: Routing
): ElasticRequest[A, GetByIdType] =
req match {
case Map(r, mapper) => Map(addRouting(r, routing), mapper)
case r: GetById => r.copy(routing = Some(Routing(routing)))
case r: GetById => r.copy(routing = Some(routing))
}
}
implicit val addRoutingToUpsert: AddRouting[UpsertType] = new AddRouting[UpsertType] {
override def addRouting[A](req: ElasticRequest[A, UpsertType], routing: String): ElasticRequest[A, UpsertType] =
override def addRouting[A](req: ElasticRequest[A, UpsertType], routing: Routing): ElasticRequest[A, UpsertType] =
req match {
case Map(r, mapper) => Map(addRouting(r, routing), mapper)
case r: CreateOrUpdate => r.copy(routing = Some(Routing(routing)))
case r: CreateOrUpdate => r.copy(routing = Some(routing))
}
}
}

private trait AddRefresh[T <: ElasticRequestType] {
trait AddRefresh[T <: ElasticRequestType] {
def addRefresh[A](req: ElasticRequest[A, T]): ElasticRequest[A, T]
}

Expand Down

0 comments on commit f7efdab

Please sign in to comment.