Skip to content

Feature/endpoint content type #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/main/scala/de/upb/cs/swt/delphi/webapi/DelphiRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class DelphiRoutes(requestLimiter: RequestLimitScheduler) extends JsonSupport wi
get {
parameter(Symbol("pretty").?) { (pretty) =>
complete(
//TODO: Introduce failure concept for feature extractor
prettyPrint(pretty, featureExtractor.featureList.toJson)
)
HttpResponse(StatusCodes.OK,
List(headers.`Content-Type`(ContentTypes.`application/json`)),
prettyPrint(pretty, featureExtractor.featureList.toJson)))
}
}
}
Expand All @@ -89,7 +89,9 @@ class DelphiRoutes(requestLimiter: RequestLimitScheduler) extends JsonSupport wi
val result = new StatisticsQuery(configuration).retrieveStandardStatistics
result match {
case Some(stats) => {
prettyPrint(pretty, stats.toJson)
HttpResponse(StatusCodes.OK,
List(headers.`Content-Type`(ContentTypes.`application/json`)),
prettyPrint(pretty, stats.toJson))
}
case _ => HttpResponse(StatusCodes.InternalServerError)
}
Expand All @@ -103,7 +105,9 @@ class DelphiRoutes(requestLimiter: RequestLimitScheduler) extends JsonSupport wi
parameter(Symbol("pretty").?) { (pretty) =>
complete(
RetrieveQuery.retrieve(identifier) match {
case Some(result) => prettyPrint(pretty, result.toJson)
case Some(result) => HttpResponse(StatusCodes.OK,
List(headers.`Content-Type`(ContentTypes.`application/json`)),
prettyPrint(pretty, result.toJson))
case None => HttpResponse(StatusCodes.NotFound)
}
)
Expand All @@ -118,14 +122,17 @@ class DelphiRoutes(requestLimiter: RequestLimitScheduler) extends JsonSupport wi
log.info(s"Received search query: ${input.query}")
complete(
new SearchQuery(configuration, featureExtractor).search(input) match {
case Success(result) => prettyPrint(pretty, result.toJson)
case Success(result) =>
HttpResponse(StatusCodes.OK,
List(headers.`Content-Type`(ContentTypes.`application/json`)),
prettyPrint(pretty, result.toJson))
case Failure(e) => {
e match {
case se: SearchError => {
se.toJson
HttpResponse(StatusCodes.ServerError(StatusCodes.InternalServerError.intValue)(se.toJson.toString(), ""))
}
case _ => {
new SearchError("Search query failed").toJson
HttpResponse(StatusCodes.ServerError(StatusCodes.InternalServerError.intValue)("Search query failed", ""))
}
}
}
Expand Down