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
dependencies { | |
classpath libraries.appengineGradle | |
classpath libraries.kotlinGradle | |
} |
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
apply plugin: 'war' | |
apply plugin: 'kotlin' | |
apply plugin: 'com.google.cloud.tools.appengine' | |
dependencies { | |
implementation libraries.kotlin | |
implementation libraries.javaxServlet | |
} |
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
@Provides | |
@Singleton | |
fun providesSyncTrades(@Named("remote") getTradesRepositoryRemote: GetTradesRepository, | |
@Named("local") getTradesRepositoryLocal: GetTradesRepository): SyncTrades { | |
return SyncTradesImpl(getTradesRepositoryRemote, getTradesRepositoryLocal) | |
} | |
@Provides | |
@Singleton | |
fun providesGetTrades(@Named("remote") getTradesRepositoryRemote: GetTradesRepository, |
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
class SyncTradesImpl @Inject constructor(@Named("remote") private val remoteRepository: GetTradesRepository, | |
@Named("local") private val localRepository: GetTradesRepository) | |
: SyncTrades { | |
override fun syncTrades(id: Long) { | |
remoteRepository.getTrades(id).trades | |
.map { TradeDb(it.trade_id, it.rate, it.amount, it.trade_date, it.trade_type) } | |
.map { localRepository.save(it) } | |
} | |
} |
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
Server | Client | ||
---|---|---|---|
Main Entity Domain Model | Trade | Trade | |
Entity Local Storage | TradeObjectify | TradeRoom | |
UseCase 1 | GetTrades | GetTrades | |
UseCase 2 | SyncTrades | SyncTrades |
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
class CallWrapper(private val request: Request, private var executed: Boolean = false, | |
private var cancelled: Boolean = false) : Call { | |
override fun enqueue(responseCallback: Callback?) {} | |
override fun isExecuted() = executed | |
override fun clone() = CallWrapper(request) | |
override fun isCanceled() = cancelled |
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
@Provides | |
fun providesGetTrades( | |
@Named("local") localRepository: GetTradesRepository, | |
@Named("remote") remoteRepository: GetTradesRepository): GetTrades = | |
GetTradesImpl(localRepository, remoteRepository) | |
@Provides | |
fun providesSyncTrades( | |
@Named("local") localRepository: GetTradesRepository, | |
@Named("remote") remoteRepository: GetTradesRepository): SyncTrades = |
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
class GetTradesRemoteRepository @Inject constructor(private val api: Api) : GetTradesRepository { | |
override fun getTrades(id: Long): Trades { | |
return api.getTrades(id) | |
} |
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
@Api(name = "api", version = "v1") | |
class ApiServer { | |
@ApiMethod(name = "sync", | |
httpMethod = ApiMethod.HttpMethod.GET, | |
path = "sync/{pair}") | |
fun sync(@Named("pair") id: String) = syncService.sync(id) | |
@ApiMethod(name = "trades", | |
httpMethod = ApiMethod.HttpMethod.GET, | |
path = "trades/{pair}") |
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
testImplementation 'com.android.support.test:rules:1.0.2' | |
testImplementation 'com.android.support.test:runner:1.0.2' | |
testImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |
testImplementation "org.robolectric:robolectric:4.0-alpha-1" |