Alexis Hernandez
7 years ago
4 changed files with 72 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||
package com.xsn.explorer.data.async |
|||
|
|||
import javax.inject.Inject |
|||
|
|||
import com.alexitc.playsonify.core.FutureApplicationResult |
|||
import com.xsn.explorer.data.{BalanceBlockingDataHandler, BalanceDataHandler} |
|||
import com.xsn.explorer.executors.DatabaseExecutionContext |
|||
import com.xsn.explorer.models.Balance |
|||
import com.xsn.explorer.models.base.{PaginatedQuery, PaginatedResult} |
|||
|
|||
import scala.concurrent.Future |
|||
|
|||
class BalanceFutureDataHandler @Inject() ( |
|||
blockingDataHandler: BalanceBlockingDataHandler)( |
|||
implicit ec: DatabaseExecutionContext) |
|||
extends BalanceDataHandler[FutureApplicationResult] { |
|||
|
|||
override def upsert(balance: Balance): FutureApplicationResult[Balance] = Future { |
|||
blockingDataHandler.upsert(balance) |
|||
} |
|||
|
|||
override def getRichest(query: PaginatedQuery): FutureApplicationResult[PaginatedResult[Balance]] = Future { |
|||
blockingDataHandler.getRichest(query) |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
package com.xsn.explorer.services |
|||
|
|||
import javax.inject.Inject |
|||
|
|||
import com.alexitc.playsonify.core.FutureApplicationResult |
|||
import com.alexitc.playsonify.core.FutureOr.Implicits.{FutureOps, OrOps} |
|||
import com.xsn.explorer.data.async.BalanceFutureDataHandler |
|||
import com.xsn.explorer.models.Balance |
|||
import com.xsn.explorer.models.base.{PaginatedQuery, PaginatedResult} |
|||
import com.xsn.explorer.services.validators.PaginatedQueryValidator |
|||
|
|||
import scala.concurrent.ExecutionContext |
|||
|
|||
class BalanceService @Inject() ( |
|||
paginatedQueryValidator: PaginatedQueryValidator, |
|||
balanceFutureDataHandler: BalanceFutureDataHandler)( |
|||
implicit ec: ExecutionContext) { |
|||
|
|||
def getRichest(query: PaginatedQuery): FutureApplicationResult[PaginatedResult[Balance]] = { |
|||
val result = for { |
|||
validatedQuery <- paginatedQueryValidator.validate(query).toFutureOr |
|||
balances <- balanceFutureDataHandler.getRichest(validatedQuery).toFutureOr |
|||
} yield balances |
|||
|
|||
result.toFuture |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package controllers |
|||
|
|||
import javax.inject.Inject |
|||
|
|||
import com.xsn.explorer.models.base.{Limit, Offset, PaginatedQuery} |
|||
import com.xsn.explorer.services.BalanceService |
|||
import controllers.common.{MyJsonController, MyJsonControllerComponents} |
|||
|
|||
class BalancesController @Inject() ( |
|||
balanceService: BalanceService, |
|||
cc: MyJsonControllerComponents) |
|||
extends MyJsonController(cc) { |
|||
|
|||
def getRichest(offset: Int, limit: Int) = publicNoInput { _ => |
|||
val query = PaginatedQuery(Offset(offset), Limit(limit)) |
|||
balanceService.getRichest(query) |
|||
} |
|||
} |
Loading…
Reference in new issue