forked from ergoplatform/explorer-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version = "2.6.3" | ||
version = "2.7.5" | ||
style = defaultWithAlign | ||
|
||
align.openParenCallSite = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...es/explorer-api/src/main/scala/org/ergoplatform/explorer/http/api/v0/modules/Search.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.ergoplatform.explorer.http.api.v0.modules | ||
|
||
import cats.Monad | ||
import org.ergoplatform.explorer.http.api.v0.models.SearchResult | ||
import org.ergoplatform.explorer.http.api.v0.services.{ | ||
AddressesService, | ||
AssetsService, | ||
BlockChainService, | ||
TransactionsService | ||
} | ||
import tofu.Start | ||
import tofu.syntax.monadic._ | ||
import tofu.syntax.start._ | ||
|
||
trait Search[F[_]] { | ||
|
||
def search(query: String): F[SearchResult] | ||
} | ||
|
||
object Search { | ||
|
||
def apply[F[_]: Monad: Start]( | ||
blocks: BlockChainService[F], | ||
transactions: TransactionsService[F], | ||
addresses: AddressesService[F, fs2.Stream], | ||
assets: AssetsService[F, fs2.Stream] | ||
): Search[F] = | ||
new Search[F] { | ||
|
||
def search(query: String): F[SearchResult] = | ||
for { | ||
blocksF <- blocks.getBlocksByIdLike(query).start | ||
txsF <- transactions.getIdsLike(query).start | ||
addressesF <- addresses.getAllLike(query).start | ||
assetsF <- assets.getAllLike(query).start | ||
blocks <- blocksF.join | ||
txs <- txsF.join | ||
addresses <- addressesF.join | ||
assets <- assetsF.join | ||
} yield SearchResult(blocks, txs, addresses, assets) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 8 additions & 21 deletions
29
...plorer-api/src/main/scala/org/ergoplatform/explorer/http/api/v0/routes/SearchRoutes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
package org.ergoplatform.explorer.http.api.v0.routes | ||
|
||
import cats.effect.{Concurrent, ContextShift, Sync, Timer} | ||
import cats.syntax.flatMap._ | ||
import cats.syntax.functor._ | ||
import cats.effect.{Concurrent, ContextShift, Timer} | ||
import io.chrisdavenport.log4cats.Logger | ||
import org.ergoplatform.explorer.http.api.ApiErr | ||
import org.ergoplatform.explorer.http.api.algebra.AdaptThrowable.AdaptThrowableEitherT | ||
import org.ergoplatform.explorer.http.api.syntax.adaptThrowable._ | ||
import org.ergoplatform.explorer.http.api.v0.models.SearchResult | ||
import org.ergoplatform.explorer.http.api.v0.services.{AddressesService, BlockChainService, TransactionsService} | ||
import org.ergoplatform.explorer.http.api.v0.modules.Search | ||
import org.http4s.HttpRoutes | ||
import sttp.tapir.server.http4s._ | ||
|
||
final class SearchRoutes[ | ||
F[_]: Concurrent: ContextShift: Timer: AdaptThrowableEitherT[*[_], ApiErr] | ||
]( | ||
blocksService: BlockChainService[F], | ||
txsService: TransactionsService[F], | ||
addressesService: AddressesService[F, fs2.Stream] | ||
)(implicit opts: Http4sServerOptions[F]) { | ||
](search: Search[F])(implicit opts: Http4sServerOptions[F]) { | ||
|
||
import org.ergoplatform.explorer.http.api.v0.defs.SearchEndpointDefs._ | ||
|
||
val routes: HttpRoutes[F] = searchR | ||
|
||
private def searchR: HttpRoutes[F] = | ||
searchDef.toRoutes { q => | ||
(for { | ||
blocks <- blocksService.getBlocksByIdLike(q) | ||
txs <- txsService.getIdsLike(q) | ||
addresses <- addressesService.getAllLike(q) | ||
} yield SearchResult(blocks, txs, addresses)).adaptThrowable.value | ||
search.search(q).adaptThrowable.value | ||
} | ||
} | ||
|
||
object SearchRoutes { | ||
|
||
def apply[F[_]: Concurrent: ContextShift: Timer: Logger]( | ||
blocksService: BlockChainService[F], | ||
txsService: TransactionsService[F], | ||
addressesService: AddressesService[F, fs2.Stream] | ||
)(implicit opts: Http4sServerOptions[F]): HttpRoutes[F] = | ||
new SearchRoutes(blocksService, txsService, addressesService).routes | ||
def apply[F[_]: Concurrent: ContextShift: Timer: Logger](search: Search[F])(implicit | ||
opts: Http4sServerOptions[F] | ||
): HttpRoutes[F] = | ||
new SearchRoutes(search).routes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters