diff options
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuidomain/services/rest')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala | 4 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala index bf42f40..8e75c76 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHelper.scala @@ -59,9 +59,9 @@ trait RestHelper { def exprToQuery(expr: SearchFilterExpr): Seq[(String, String)] = expr match { case SearchFilterExpr.Empty => Seq.empty case SearchFilterExpr.Atom.Binary(dimension, op, value) => - Seq("filters" -> s"${dimension.name} ${opToString(op)} $value") + Seq("filters" -> s"${dimension.tableName.fold("")(t => s"$t.") + dimension.name} ${opToString(op)} $value") case SearchFilterExpr.Atom.NAry(dimension, SearchFilterNAryOperation.In, values) => - Seq("filters" -> s"${dimension.name} in ${values.mkString(",")}") + Seq("filters" -> s"${dimension.tableName.fold("")(t => s"$t.") + dimension.name} in ${values.mkString(",")}") case SearchFilterExpr.Intersection(ops) => ops.flatMap(op => exprToQuery(op)) case expr => sys.error(s"No parser available for filter expression $expr.") diff --git a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala index a352053..73abb0e 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/services/rest/RestHypothesisService.scala @@ -1,11 +1,14 @@ package xyz.driver.pdsuidomain.services.rest +import akka.http.scaladsl.marshalling.Marshal + import scala.concurrent.{ExecutionContext, Future} import akka.http.scaladsl.model._ import akka.stream.Materializer import xyz.driver.core.rest._ import xyz.driver.pdsuicommon.auth._ import xyz.driver.pdsuicommon.db._ +import xyz.driver.pdsuicommon.domain.UuidId import xyz.driver.pdsuidomain.ListResponse import xyz.driver.pdsuidomain.entities.Hypothesis import xyz.driver.pdsuidomain.services.HypothesisService @@ -31,4 +34,25 @@ class RestHypothesisService(transport: ServiceTransport, baseUri: Uri)( } } + def create(draftHypothesis: Hypothesis)(implicit requestContext: AuthenticatedRequestContext): Future[CreateReply] = { + for { + entity <- Marshal(draftHypothesis).to[RequestEntity] + request = HttpRequest(HttpMethods.POST, endpointUri(baseUri, "/v1/hypothesis")).withEntity(entity) + response <- transport.sendRequestGetResponse(requestContext)(request) + reply <- apiResponse[Hypothesis](response) + } yield { + CreateReply.Created(reply) + } + } + + def delete(id: UuidId[Hypothesis])(implicit requestContext: AuthenticatedRequestContext): Future[DeleteReply] = { + val request = HttpRequest(HttpMethods.DELETE, endpointUri(baseUri, s"/v1/hypothesis/$id")) + for { + response <- transport.sendRequestGetResponse(requestContext)(request) + _ <- apiResponse[HttpEntity](response) + } yield { + DeleteReply.Deleted + } + } + } |