<commit_before>package justin.db.client

import java.util.UUID

import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.stream.Materializer

import scala.concurrent.ExecutionContext

class StorageNodeRouter(client: HttpStorageNodeClient)(implicit ec: ExecutionContext, mat: Materializer) {

  def routes: Route = {
    // TODO: id should be mapped to real UUID type
    (get & path("get") & pathEndOrSingleSlash & parameters('id.as[String], 'r.as[Int])) { (id, r) =>
      complete {
        client.get(UUID.fromString(id), ReadFactor(r)).map[ToResponseMarshallable] {
          case GetValueResponse.Found(value)  => ???
          case GetValueResponse.NotFound      => ???
          case GetValueResponse.Failure(err)  => ???
        }
      }
    }
  }
}<commit_msg>storage-node-router: handle /get route json support<commit_after>package justin.db.client

import java.util.UUID

import akka.http.scaladsl.marshalling.ToResponseMarshallable
import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.stream.Materializer

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import spray.json.DefaultJsonProtocol._

import scala.concurrent.ExecutionContext

object StorageNodeRouter {
  case class Result(value: String)
  implicit val valueFormat = jsonFormat1(Result)
}

class StorageNodeRouter(client: HttpStorageNodeClient)(implicit ec: ExecutionContext, mat: Materializer) {
  import StorageNodeRouter._

  def routes: Route = {
    // TODO: id should be mapped to real UUID type
    (get & path("get") & pathEndOrSingleSlash & parameters('id.as[String], 'r.as[Int])) { (id, r) =>
      complete {
        client.get(UUID.fromString(id), ReadFactor(r)).map[ToResponseMarshallable] {
          case GetValueResponse.Found(value)  => OK         -> Result(value)
          case GetValueResponse.NotFound      => NotFound   -> Result(s"Not found value with id $id")
          case GetValueResponse.Failure(err)  => BadRequest -> Result(err)
        }
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.1127141568981064, 'fraction_numerical': 0.0004508566275924256, 'mean_word_length': 3.8449781659388647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3636237', 'n_tokens_mistral': 681, 'n_tokens_neox': 684, 'n_words': 134}