diff --git a/android/app/src/main/java/by/eapp/musicroom/data/login/repo/RefreshTokenServiceImpl.kt b/android/app/src/main/java/by/eapp/musicroom/data/login/repo/RefreshTokenServiceImpl.kt new file mode 100644 index 0000000..ddecd69 --- /dev/null +++ b/android/app/src/main/java/by/eapp/musicroom/data/login/repo/RefreshTokenServiceImpl.kt @@ -0,0 +1,29 @@ +package by.eapp.musicroom.data.login.repo + +import by.eapp.musicroom.data.toDto +import by.eapp.musicroom.domain.model.RefreshToken +import by.eapp.musicroom.domain.model.Tokens +import by.eapp.musicroom.domain.repo.RefreshTokenService +import by.eapp.musicroom.network.RefreshTokenApiService +import javax.inject.Inject + +class RefreshTokenServiceImpl @Inject constructor( + private val apiService: RefreshTokenApiService, +) : RefreshTokenService { + override suspend fun refreshToken(refreshToken: String): Tokens { + val response = apiService.refreshToken(RefreshToken(refreshToken).toDto()) + if (response.isSuccessful) { + val result = response.body() + if (result != null) { + return Tokens( + accessToken = result.accessToken, + refreshToken = result.refreshToken + ) + } else { + throw Exception("Response body is null") + } + } else { + throw Exception("Failed to refresh token: ${response.errorBody()?.string()}") + } + } +} \ No newline at end of file diff --git a/android/app/src/main/java/by/eapp/musicroom/domain/repo/RefreshTokenService.kt b/android/app/src/main/java/by/eapp/musicroom/domain/repo/RefreshTokenService.kt new file mode 100644 index 0000000..c3f676f --- /dev/null +++ b/android/app/src/main/java/by/eapp/musicroom/domain/repo/RefreshTokenService.kt @@ -0,0 +1,8 @@ +package by.eapp.musicroom.domain.repo + +import by.eapp.musicroom.domain.model.Tokens + +interface RefreshTokenService { + suspend fun refreshToken(refreshToken: String): Tokens + +} \ No newline at end of file diff --git a/android/app/src/main/java/by/eapp/musicroom/network/RefreshTokenApiService.kt b/android/app/src/main/java/by/eapp/musicroom/network/RefreshTokenApiService.kt new file mode 100644 index 0000000..ee9e302 --- /dev/null +++ b/android/app/src/main/java/by/eapp/musicroom/network/RefreshTokenApiService.kt @@ -0,0 +1,13 @@ +package by.eapp.musicroom.network + +import by.eapp.musicroom.network.model.RefreshTokenDto +import by.eapp.musicroom.network.model.TokensDto +import retrofit2.Response +import retrofit2.http.Body +import retrofit2.http.POST + +interface RefreshTokenApiService { + + @POST(Endpoint.REFRESH_TOKEN) + suspend fun refreshToken(@Body refreshToken: RefreshTokenDto): Response +} \ No newline at end of file