Skip to content

Commit

Permalink
- refactor: renaming to remove REST prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rodvar committed Dec 10, 2024
1 parent 14a736c commit d7e3a7e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import network.bisq.mobile.client.offerbook.ClientOfferbookServiceFacade
import network.bisq.mobile.client.offerbook.offer.OfferbookApiGateway
import network.bisq.mobile.client.shared.BuildConfig
import network.bisq.mobile.client.websocket.WebSocketClient
import network.bisq.mobile.client.websocket.rest_api_proxy.WebSocketRestApiClient
import network.bisq.mobile.client.websocket.api_proxy.WebSocketApiClient
import network.bisq.mobile.client.websocket.messages.SubscriptionRequest
import network.bisq.mobile.client.websocket.messages.SubscriptionResponse
import network.bisq.mobile.client.websocket.messages.WebSocketEvent
import network.bisq.mobile.client.websocket.messages.WebSocketMessage
import network.bisq.mobile.client.websocket.messages.WebSocketRequest
import network.bisq.mobile.client.websocket.messages.WebSocketResponse
import network.bisq.mobile.client.websocket.messages.WebSocketRestApiRequest
import network.bisq.mobile.client.websocket.messages.WebSocketRestApiResponse
import network.bisq.mobile.client.websocket.messages.WebSocketApiRequest
import network.bisq.mobile.client.websocket.messages.WebSocketApiResponse
import network.bisq.mobile.client.user_profile.ClientUserProfileServiceFacade
import network.bisq.mobile.client.user_profile.UserProfileApiGateway
import network.bisq.mobile.domain.data.repository.main.bootstrap.ApplicationBootstrapFacade
Expand All @@ -43,11 +43,11 @@ val clientModule = module {
polymorphic(WebSocketMessage::class) {
subclass(WebSocketEvent::class, WebSocketEvent.serializer())
polymorphic(WebSocketRequest::class) {
subclass(WebSocketRestApiRequest::class, WebSocketRestApiRequest.serializer())
subclass(WebSocketApiRequest::class, WebSocketApiRequest.serializer())
subclass(SubscriptionRequest::class, SubscriptionRequest.serializer())
}
polymorphic(WebSocketResponse::class) {
subclass(WebSocketRestApiResponse::class, WebSocketRestApiResponse.serializer())
subclass(WebSocketApiResponse::class, WebSocketApiResponse.serializer())
subclass(SubscriptionResponse::class, SubscriptionResponse.serializer())
}
}
Expand All @@ -69,8 +69,8 @@ val clientModule = module {

single<ApplicationBootstrapFacade> { ClientApplicationBootstrapFacade() }

single(named("RestApiHost")) { provideRestApiHost() }
single(named("RestApiPort")) { (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt() }
single(named("ApiHost")) { provideApiHost() }
single(named("ApiPort")) { (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt() }
single(named("WebsocketApiHost")) { provideWebsocketHost() }
single(named("WebsocketApiPort")) { (BuildConfig.WS_PORT.takeIf { it.isNotEmpty() } ?: "8090").toInt() }

Expand All @@ -84,7 +84,7 @@ val clientModule = module {
}
// single { WebSocketHttpClient(get()) }
single {
WebSocketRestApiClient(
WebSocketApiClient(
get(),
get(),
get(),
Expand All @@ -103,7 +103,7 @@ val clientModule = module {
single<OfferbookServiceFacade> { ClientOfferbookServiceFacade(get(), get(), get(), get()) }
}

fun provideRestApiHost(): String {
fun provideApiHost(): String {
return BuildConfig.WS_ANDROID_HOST.takeIf { it.isNotEmpty() } ?: "10.0.2.2"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package network.bisq.mobile.client.market

import kotlinx.serialization.Serializable
import network.bisq.mobile.client.websocket.WebSocketClient
import network.bisq.mobile.client.websocket.rest_api_proxy.WebSocketRestApiClient
import network.bisq.mobile.client.websocket.api_proxy.WebSocketApiClient
import network.bisq.mobile.client.websocket.subscription.WebSocketEventObserver
import network.bisq.mobile.client.websocket.subscription.Topic
import network.bisq.mobile.utils.Logging

class MarketPriceApiGateway(
private val webSocketRestApiClient: WebSocketRestApiClient,
private val webSocketApiClient: WebSocketApiClient,
private val webSocketClient: WebSocketClient,
) : Logging {
private val basePath = "market-price"

suspend fun getQuotes(): MarketPriceResponse {
return webSocketRestApiClient.get("$basePath/quotes")
return webSocketApiClient.get("$basePath/quotes")
}

suspend fun subscribeMarketPrice(): WebSocketEventObserver? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ package network.bisq.mobile.client.offerbook.offer

import network.bisq.mobile.client.replicated_model.common.currency.Market
import network.bisq.mobile.client.websocket.WebSocketClient
import network.bisq.mobile.client.websocket.rest_api_proxy.WebSocketRestApiClient
import network.bisq.mobile.client.websocket.api_proxy.WebSocketApiClient
import network.bisq.mobile.client.websocket.subscription.WebSocketEventObserver
import network.bisq.mobile.client.websocket.subscription.Topic
import network.bisq.mobile.domain.data.model.OfferListItem
import network.bisq.mobile.utils.Logging

class OfferbookApiGateway(
private val webSocketRestApiClient: WebSocketRestApiClient,
private val webSocketApiClient: WebSocketApiClient,
private val webSocketClient: WebSocketClient,
) : Logging {
private val basePath = "offerbook"

// Requests
suspend fun getMarkets(): List<Market> {
return webSocketRestApiClient.get("$basePath/markets")
return webSocketApiClient.get("$basePath/markets")
}

suspend fun getNumOffersByMarketCode(): Map<String, Int> {
return webSocketRestApiClient.get("$basePath/markets/offers/count")
return webSocketApiClient.get("$basePath/markets/offers/count")
}

suspend fun getOffers(code: String): List<OfferListItem> {
return webSocketRestApiClient.get("$basePath/markets/$code/offers")
return webSocketApiClient.get("$basePath/markets/$code/offers")
}

// Subscriptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package network.bisq.mobile.client.user_profile

import network.bisq.mobile.client.replicated_model.user.identity.PreparedData
import network.bisq.mobile.client.replicated_model.user.profile.UserProfile
import network.bisq.mobile.client.websocket.rest_api_proxy.WebSocketRestApiClient
import network.bisq.mobile.client.websocket.api_proxy.WebSocketApiClient

class UserProfileApiGateway(
private val webSocketRestApiClient: WebSocketRestApiClient
private val webSocketApiClient: WebSocketApiClient
) {
private val basePath = "user-identities"
suspend fun requestPreparedData(): PreparedData {
return webSocketRestApiClient.get("$basePath/prepared-data")
return webSocketApiClient.get("$basePath/prepared-data")
}

suspend fun createAndPublishNewUserProfile(
Expand All @@ -22,14 +22,14 @@ class UserProfileApiGateway(
"",
preparedData
)
return webSocketRestApiClient.post(basePath, createUserIdentityRequest)
return webSocketApiClient.post(basePath, createUserIdentityRequest)
}

suspend fun getUserIdentityIds(): List<String> {
return webSocketRestApiClient.get("$basePath/ids")
return webSocketApiClient.get("$basePath/ids")
}

suspend fun getSelectedUserProfile(): UserProfile {
return webSocketRestApiClient.get("$basePath/selected/user-profile")
return webSocketApiClient.get("$basePath/selected/user-profile")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network.bisq.mobile.client.websocket.rest_api_proxy
package network.bisq.mobile.client.websocket.api_proxy

import io.ktor.client.HttpClient
import io.ktor.client.call.body
Expand All @@ -9,21 +9,21 @@ import io.ktor.http.contentType
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import network.bisq.mobile.client.websocket.WebSocketClient
import network.bisq.mobile.client.websocket.messages.WebSocketRestApiRequest
import network.bisq.mobile.client.websocket.messages.WebSocketRestApiResponse
import network.bisq.mobile.client.websocket.messages.WebSocketApiRequest
import network.bisq.mobile.client.websocket.messages.WebSocketApiResponse
import network.bisq.mobile.utils.Logging
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid

class WebSocketRestApiClient(
class WebSocketApiClient(
val httpClient: HttpClient,
val webSocketClient: WebSocketClient,
val json: Json,
host: String,
port: Int
) : Logging {
val apiPath = "/api/v1/"
var restApiUrl = "http://$host:$port$apiPath"
var apiUrl = "http://$host:$port$apiPath"

// POST request still not working, but issue is likely on the bisq2 side.
// So we use httpClient instead.
Expand All @@ -35,7 +35,7 @@ class WebSocketRestApiClient(

suspend inline fun <reified T, reified R> post(path: String, requestBody: R): T {
if (useHttpClientForPost) {
return httpClient.post(restApiUrl + path) {
return httpClient.post(apiUrl + path) {
contentType(ContentType.Application.Json)
setBody(requestBody)
}.body<T>()
Expand All @@ -55,16 +55,16 @@ class WebSocketRestApiClient(
): T {
val requestId = Uuid.random().toString()
val fullPath = apiPath + path
val responseClassName = WebSocketRestApiResponse::class.qualifiedName!!
val webSocketRestApiRequest = WebSocketRestApiRequest(
val responseClassName = WebSocketApiResponse::class.qualifiedName!!
val webSocketApiRequest = WebSocketApiRequest(
responseClassName,
requestId,
method,
fullPath,
bodyAsJson
)
val response = webSocketClient.sendRequestAndAwaitResponse(webSocketRestApiRequest)
require(response is WebSocketRestApiResponse) { "Response not of expected type. response=$response" }
val response = webSocketClient.sendRequestAndAwaitResponse(webSocketApiRequest)
require(response is WebSocketApiResponse) { "Response not of expected type. response=$response" }
val body = response.body
val decodeFromString = json.decodeFromString<T>(body)
return decodeFromString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package network.bisq.mobile.client.websocket.messages
import kotlinx.serialization.Serializable

@Serializable
data class WebSocketRestApiRequest(
data class WebSocketApiRequest(
val responseClassName: String,
override val requestId: String,
val method: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package network.bisq.mobile.client.websocket.messages
import kotlinx.serialization.Serializable

@Serializable
data class WebSocketRestApiResponse(
data class WebSocketApiResponse(
override val requestId: String,
val statusCode: Int,
val body: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module

val iosClientModule = module {
single(named("RestApiHost")) { provideRestApiHost() }
single(named("ApiHost")) { provideApiHost() }
single(named("WebsocketApiHost")) { provideWebsocketHost() }

single<NotificationServiceController> {
Expand All @@ -16,7 +16,7 @@ val iosClientModule = module {
}
}

fun provideRestApiHost(): String {
fun provideApiHost(): String {
return BuildConfig.WS_IOS_HOST.takeIf { it.isNotEmpty() } ?: "localhost"
}
fun provideWebsocketHost(): String {
Expand Down

0 comments on commit d7e3a7e

Please sign in to comment.