Skip to content

Commit

Permalink
Provide user token to the channel group routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Nov 2, 2023
1 parent b0a34c9 commit 001f0fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MinchatRestClient(
* For the caching approach, try `cache.channelgroupCache.values`
*/
suspend fun getAllChannelGroups() =
channelGroupService.getAllGroups()
channelGroupService.getAllGroups(account?.token)
.onEach(cache::set)
.map { it.withClient(this) }

Expand Down Expand Up @@ -229,7 +229,7 @@ class MinchatRestClient(
* For the caching version of this method, see [cache].
*/
suspend fun getChannelGroup(id: Long) =
channelGroupService.getGroup(id)
channelGroupService.getGroup(id, account?.token)
.also(cache::set)
.withClient(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import io.minchat.common.entity.ChannelGroup
import io.minchat.common.request.*

class ChannelGroupService(baseUrl: String, client: HttpClient) : AbstractRestService(baseUrl, client) {
suspend fun getGroup(id: Long) = run {
client.get(makeRouteUrl(Route.ChannelGroup.fetch, id))
.body<ChannelGroup>()
suspend fun getGroup(id: Long, token: String? = null) = run {
client.get(makeRouteUrl(Route.ChannelGroup.fetch, id)) {
token?.let { authorizeBearer(it) }
}.body<ChannelGroup>()
}

/**
* Fetches all groups registered on the server.
*/
suspend fun getAllGroups() = run {
client.get(makeRouteUrl(Route.ChannelGroup.all))
.body<List<ChannelGroup>>()
suspend fun getAllGroups(token: String? = null) = run {
client.get(makeRouteUrl(Route.ChannelGroup.all)) {
token?.let { authorizeBearer(it) }
}.body<List<ChannelGroup>>()
}

suspend fun createGroup(
Expand Down

0 comments on commit 001f0fa

Please sign in to comment.