Skip to content

Commit 5bbd2ab

Browse files
authored
Merge pull request #12 from almacken/feature/retrieveSource
Added retrieve endpoint
2 parents be1255f + ea3bd85 commit 5bbd2ab

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package de.upb.cs.swt.delphi.webapi
2+
3+
import com.sksamuel.elastic4s.http.ElasticDsl._
4+
import com.sksamuel.elastic4s.http.HttpClient
5+
6+
object ElasticClient {
7+
8+
val configuration = new Configuration()
9+
val client = HttpClient(configuration.elasticsearchClientUri)
10+
val index = "delphi" / "project"
11+
12+
//Returns an entry with the given ID as an option
13+
def getSource(id: String) =
14+
client.execute{
15+
get(id).from(index)
16+
}.await match {
17+
case Right(res) => res.body
18+
case Left(_) => Option.empty
19+
}
20+
}

src/main/scala/de/upb/cs/swt/delphi/webapi/Server.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ object Server extends HttpApp with JsonSupport {
3434

3535
def retrieve(identifier: String) = {
3636
get {
37-
complete(identifier)
37+
complete(
38+
ElasticClient.getSource(identifier)
39+
)
3840
}
3941
}
4042

0 commit comments

Comments
 (0)