<commit_before>package ecommerce.sales.app

import akka.actor.{Actor, ActorLogging, Props}
import akka.http.Http
import akka.http.server.{Directives, Route}
import akka.stream.scaladsl.ImplicitFlowMaterializer
import akka.util.Timeout
import ecommerce.sales
import ecommerce.sales.{Command => SalesCommand}
import org.json4s.ext.{JodaTimeSerializers, UUIDSerializer}
import org.json4s.{DefaultFormats, Formats}
import pl.newicom.dddd.aggregate.Command
import pl.newicom.dddd.writefront.{CommandDirective, CommandHandler, JsonMarshalling}

import scala.concurrent.duration.FiniteDuration

object HttpService {
  def props(interface: String, port: Int, askTimeout: FiniteDuration): Props =
    Props(new HttpService(interface, port)(askTimeout))
}

class HttpService(interface: String, port: Int)(implicit askTimeout: Timeout)
  extends Actor with SalesFrontConfiguration with CommandHandler
  with CommandDirective with Directives
  with ActorLogging with ImplicitFlowMaterializer with JsonMarshalling {

  import context.dispatcher
  implicit val formats: Formats = DefaultFormats ++ JodaTimeSerializers.all + UUIDSerializer + sales.typeHints

  Http()(context.system).bind(interface, port).startHandlingWith(route)
  log.info(s"Listening on $interface:$port")

  override def receive = Actor.emptyBehavior

  private def route = pathPrefix("ecommerce") {
    path("sales") {
      handleCommand[SalesCommand](sales.officeName)
    }
  }

  private def handleCommand[A <: Command](officeName: String): Route = commandManifest[A] { implicit cm =>
    post {
      entity(as[A]) { command =>
        complete {
          handle(officeName, command)
        }
      }
    }
  }

}<commit_msg>fix #1 write-front should respond with OK or InternalServerError code and proper msg<commit_after>package ecommerce.sales.app

import akka.actor.{Actor, ActorLogging, Props}
import akka.http.Http
import akka.http.marshalling.ToResponseMarshallable
import akka.http.model.StatusCodes
import akka.http.server.{Directives, Route}
import akka.stream.scaladsl.ImplicitFlowMaterializer
import akka.util.Timeout
import ecommerce.sales
import ecommerce.sales.{Command => SalesCommand}
import org.json4s.ext.{JodaTimeSerializers, UUIDSerializer}
import org.json4s.{DefaultFormats, Formats}
import pl.newicom.dddd.aggregate.Command
import pl.newicom.dddd.writefront.{CommandDirective, CommandHandler, JsonMarshalling}

import scala.concurrent.duration.FiniteDuration
import scala.util.{Failure, Success}

object HttpService {
  def props(interface: String, port: Int, askTimeout: FiniteDuration): Props =
    Props(new HttpService(interface, port)(askTimeout))
}

class HttpService(interface: String, port: Int)(implicit askTimeout: Timeout)
  extends Actor with SalesFrontConfiguration with CommandHandler
  with CommandDirective with Directives
  with ActorLogging with ImplicitFlowMaterializer with JsonMarshalling {

  import context.dispatcher
  implicit val formats: Formats = DefaultFormats ++ JodaTimeSerializers.all + UUIDSerializer + sales.typeHints

  Http()(context.system).bind(interface, port).startHandlingWith(route)
  log.info(s"Listening on $interface:$port")

  override def receive = Actor.emptyBehavior

  private def route = pathPrefix("ecommerce") {
    path("sales") {
      handleCommand[SalesCommand](sales.officeName)
    }
  }

  private def handleCommand[A <: Command](officeName: String): Route = commandManifest[A] { implicit cm =>
    post {
      entity(as[A]) { command =>
        complete {
          handle(officeName, command).map[ToResponseMarshallable] {
            case Success(msg) => StatusCodes.OK -> msg
            case Failure(ex)  => StatusCodes.InternalServerError -> ex.getMessage
          }
        }
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.09621535181236673, 'fraction_numerical': 0.0013326226012793177, 'mean_word_length': 4.845794392523365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '830538', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1094, 'n_words': 247}