-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ConfigUseCase): Supporting shared modules for reading dynamic co…
…nfig (#299) * feat(ConfigUseCase): Supporting shared modules for reading dynamic config * address feedback
- Loading branch information
1 parent
bda4a4b
commit 4ff11a2
Showing
18 changed files
with
348 additions
and
5 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
12 changes: 12 additions & 0 deletions
12
androidApp/src/main/java/com/mbta/tid/mbta_app/android/repositories/AppCheckRepository.kt
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,12 @@ | ||
package com.mbta.tid.mbta_app.android.repositories | ||
|
||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.model.response.ErrorDetails | ||
import com.mbta.tid.mbta_app.repositories.IAppCheckRepository | ||
import com.mbta.tid.mbta_app.repositories.Token | ||
|
||
class AppCheckRepository : IAppCheckRepository { | ||
override suspend fun getToken(): ApiResult<Token> { | ||
return ApiResult.Error(ErrorDetails(message = "TODO: Implement")) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// AppCheckProviderFactory.swift | ||
// iosApp | ||
// | ||
// Created by Brady, Kayla on 7/12/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
import FirebaseAppCheck | ||
import FirebaseCore | ||
import Foundation | ||
|
||
class CustomAppCheckProviderFactory: NSObject, AppCheckProviderFactory { | ||
func createProvider(with app: FirebaseApp) -> AppCheckProvider? { | ||
AppAttestProvider(app: app) | ||
} | ||
} |
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,25 @@ | ||
// | ||
// AppCheckRepository.swift | ||
// iosApp | ||
// | ||
// Created by Brady, Kayla on 7/18/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
// import FirebaseAppCheck | ||
import Foundation | ||
import shared | ||
|
||
class AppCheckRepository: IAppCheckRepository { | ||
// swiftlint:disable:next identifier_name | ||
func __getToken() async -> ApiResult<shared.Token> { | ||
/* do { | ||
let token = try await AppCheck.appCheck().token(forcingRefresh: false) | ||
return ApiResultOk(data: Token(token: token.token)) | ||
} catch { | ||
return ApiResultError(error: ErrorDetails(code: nil, message: "\(error)")) | ||
} | ||
*/ | ||
ApiResultError(error: ErrorDetails(code: nil, message: "TODO")) | ||
} | ||
} |
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
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
2 changes: 2 additions & 0 deletions
2
shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/dependencyInjection/UsecaseDI.kt
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,11 +1,13 @@ | ||
package com.mbta.tid.mbta_app.dependencyInjection | ||
|
||
import com.mbta.tid.mbta_app.usecases.ConfigUseCase | ||
import com.mbta.tid.mbta_app.usecases.GetSettingUsecase | ||
import com.mbta.tid.mbta_app.usecases.TogglePinnedRouteUsecase | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
class UsecaseDI() : KoinComponent { | ||
val configUsecase: ConfigUseCase by inject() | ||
val toggledPinnedRouteUsecase: TogglePinnedRouteUsecase by inject() | ||
val getSettingUsecase: GetSettingUsecase by inject() | ||
} |
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
7 changes: 7 additions & 0 deletions
7
shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/model/response/ConfigResponse.kt
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,7 @@ | ||
package com.mbta.tid.mbta_app.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ConfigResponse(@SerialName("mapbox_public_token") val mapboxPublicToken: String) |
20 changes: 20 additions & 0 deletions
20
shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/repositories/AppCheckRepository.kt
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,20 @@ | ||
package com.mbta.tid.mbta_app.repositories | ||
|
||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable data class Token(var token: String) | ||
|
||
interface IAppCheckRepository { | ||
suspend fun getToken(): ApiResult<Token> | ||
} | ||
|
||
class MockAppCheckRepository(result: ApiResult<Token>) : IAppCheckRepository { | ||
private var result = result | ||
|
||
override suspend fun getToken(): ApiResult<Token> { | ||
return result | ||
} | ||
|
||
constructor() : this(ApiResult.Ok(Token("fake_app_check_token"))) | ||
} |
53 changes: 53 additions & 0 deletions
53
shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/repositories/ConfigRepository.kt
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,53 @@ | ||
package com.mbta.tid.mbta_app.repositories | ||
|
||
import com.mbta.tid.mbta_app.json | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.model.response.ConfigResponse | ||
import com.mbta.tid.mbta_app.model.response.ErrorDetails | ||
import com.mbta.tid.mbta_app.network.MobileBackendClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.header | ||
import io.ktor.client.statement.bodyAsText | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.path | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.inject | ||
|
||
interface IConfigRepository { | ||
|
||
suspend fun getConfig(token: String): ApiResult<ConfigResponse> | ||
} | ||
|
||
class ConfigRepository() : IConfigRepository, KoinComponent { | ||
private val mobileBackendClient: MobileBackendClient by inject() | ||
|
||
override suspend fun getConfig(token: String): ApiResult<ConfigResponse> { | ||
try { | ||
val response = | ||
mobileBackendClient.get { | ||
url { | ||
path("api/protected/config") | ||
header("http_x_firebase_appcheck", token) | ||
} | ||
} | ||
|
||
if (response.status === HttpStatusCode.OK) { | ||
return ApiResult.Ok(data = json.decodeFromString(response.body())) | ||
} else { | ||
return ApiResult.Error(ErrorDetails(response.status.value, response.bodyAsText())) | ||
} | ||
} catch (e: Exception) { | ||
return ApiResult.Error(ErrorDetails(message = e.message ?: e.toString())) | ||
} | ||
} | ||
} | ||
|
||
class MockConfigRepository( | ||
var response: ApiResult<ConfigResponse> = | ||
ApiResult.Ok(ConfigResponse(mapboxPublicToken = "fake_mapbox_token")) | ||
) : IConfigRepository, KoinComponent { | ||
|
||
override suspend fun getConfig(token: String): ApiResult<ConfigResponse> { | ||
return response | ||
} | ||
} |
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
Oops, something went wrong.