-
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.
Updated ServiceTokensRepository to implement new MutableRepository ab…
…straction
- Loading branch information
Showing
3 changed files
with
130 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
50 changes: 8 additions & 42 deletions
50
...src/commonMain/kotlin/com/mooncloak/vpn/app/shared/api/service/ServiceTokensRepository.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,61 +1,27 @@ | ||
package com.mooncloak.vpn.app.shared.api.service | ||
|
||
import com.mooncloak.vpn.api.shared.service.ServiceTokens | ||
import kotlinx.coroutines.CancellationException | ||
import com.mooncloak.vpn.data.shared.repository.MutableRepository | ||
|
||
/** | ||
* An storage abstraction for accessing [ServiceTokens]. | ||
*/ | ||
public interface ServiceTokensRepository { | ||
public interface ServiceTokensRepository : MutableRepository<ServiceTokens> { | ||
|
||
/** | ||
* Retrieves the latest [ServiceTokens] instance. | ||
*/ | ||
public suspend fun getLatest(): ServiceTokens? | ||
|
||
/** | ||
* Retrieves the [ServiceTokens] with the provided [id], or throws a [NoSuchElementException] if there is no | ||
* [ServiceTokens] with the provided [id]. | ||
* | ||
* @param [id] The [ServiceTokens.id] value of the [ServiceTokens] to retrieve. | ||
* | ||
* @throws [NoSuchElementException] if no [ServiceTokens] exists in the underlying storage with the provided [id]. | ||
* | ||
* @return The [ServiceTokens] instance that has the provided [id] value. | ||
*/ | ||
@Throws(NoSuchElementException::class, CancellationException::class) | ||
public suspend fun get(id: String): ServiceTokens | ||
|
||
/** | ||
* Adds the provided [ServiceTokens] instance to the underlying storage. | ||
*/ | ||
public suspend fun add(tokens: ServiceTokens) | ||
|
||
/** | ||
* Removes the [ServiceTokens] containing the provided [id] from the underlying storage if it exists. | ||
*/ | ||
public suspend fun remove(id: String) | ||
|
||
/** | ||
* Clears all the [ServiceTokens] in the underlying storage. | ||
*/ | ||
public suspend fun clear() | ||
public suspend fun add(tokens: ServiceTokens) { | ||
this.insert( | ||
id = tokens.id, | ||
value = { tokens } | ||
) | ||
} | ||
|
||
public companion object | ||
} | ||
|
||
/** | ||
* Retrieves the [ServiceTokens] with the provided [id], or `null` if there is no [ServiceTokens] with the provided | ||
* [id]. | ||
* | ||
* @param [id] The [ServiceTokens.id] value of the [ServiceTokens] to retrieve. | ||
* | ||
* @return The [ServiceTokens] instance that has the provided [id] value, or `null` if no [ServiceTokens] exists in the | ||
* underlying storage with the provided [id]. | ||
*/ | ||
public suspend fun ServiceTokensRepository.getOrNull(id: String): ServiceTokens? = | ||
try { | ||
get(id = id) | ||
} catch (_: NoSuchElementException) { | ||
null | ||
} |
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