Skip to content

Commit

Permalink
Implement refresh endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed May 10, 2024
1 parent 4cca4bd commit 39eb2f3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/api/src/main/smithy/search.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use smithy.api#default
@simpleRestJson
service SearchService {
version: "3.0.0"
operations: [Search, Count, DeleteById, DeleteByIds, Mapping]
operations: [Search, Count, DeleteById, DeleteByIds, Mapping, Refresh]
}

@readonly
Expand Down Expand Up @@ -46,6 +46,12 @@ operation Mapping {
errors: [InternalServerError]
}

@http(method: "POST", uri: "/refresh/{index}", code: 200)
operation Refresh {
input: RefreshInput
errors: [InternalServerError]
}

structure SearchInput {

@required
Expand Down Expand Up @@ -90,6 +96,12 @@ structure MappingInput {
index: Index
}

structure RefreshInput {
@required
@httpLabel
index: Index
}

structure Forum {
@required
text: String
Expand Down
7 changes: 7 additions & 0 deletions modules/app/src/main/scala/service.search.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class SearchServiceImpl(esClient: ESClient[IO])(using Logger[IO]) extends Search

import SearchServiceImpl.{ given, * }

override def refresh(index: Index): IO[Unit] =
esClient
.refreshIndex(index.transform)
.handleErrorWith: e =>
error"Error in refresh: index=$index" *>
IO.raiseError(InternalServerError("Internal server error"))

override def mapping(index: Index): IO[Unit] =
esClient
.putMapping(index.transform, index.mapping)
Expand Down
6 changes: 6 additions & 0 deletions modules/client/src/main/scala/PlayClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class PlayClient(client: StandaloneWSClient, baseUrl: String)(using ExecutionCon

import implicits.given

override def refresh(index: Index): Future[Unit] =
client
.url(s"$baseUrl/refresh/${index.name}")
.execute("POST")
.map(_ => ())

override def mapping(index: Index): Future[Unit] =
client
.url(s"$baseUrl/mapping/${index.name}")
Expand Down
3 changes: 3 additions & 0 deletions modules/e2e/src/test/scala/CompatSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ object CompatSuite extends weaver.IOSuite:
test("mapping endpoint"): client =>
IO.fromFuture(IO(client.mapping(SpecIndex.Study))).map(expect.same(_, ()))

test("refresh endpoint"): client =>
IO.fromFuture(IO(client.refresh(SpecIndex.Forum))).map(expect.same(_, ()))

def testAppConfig = AppConfig(
server = HttpServerConfig(ip"0.0.0.0", port"9999", shutdownTimeout = 1),
elastic = ElasticConfig("http://0.0.0.0:9200")
Expand Down

0 comments on commit 39eb2f3

Please sign in to comment.