Skip to content

Commit

Permalink
Add implementation for data layer on non gms module
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorNarvaez committed May 15, 2023
1 parent 29627a2 commit 3ccee37
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.omh.android.storage.api.drive.nongms

import android.content.Context
import com.omh.android.storage.api.OmhStorageClient

internal class OmhStorageClientImpl(
context: Context
) : OmhStorageClient {

private val applicationContext: Context

init {
applicationContext = context.applicationContext
}

internal class Builder : OmhStorageClient.Builder {
override fun build(context: Context): OmhStorageClient {
return OmhStorageClientImpl(context)
}
}

override fun setupAccessToken(token: String) {
// Implement THIS
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.omh.android.storage.api.drive.nongms

import android.content.Context
import com.omh.android.storage.api.OmhStorageFactory

class OmhStorageFactoryImpl : OmhStorageFactory {

override fun getStorageClient(
context: Context
) = OmhStorageClientImpl.Builder().build(context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.omh.android.storage.api.drive.nongms.data

import com.omh.android.storage.api.drive.nongms.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory

internal object GoogleRetrofitImpl {

private val okHttpClient = OkHttpClient.Builder()
.addInterceptor(
HttpLoggingInterceptor().apply {
if (BuildConfig.DEBUG) setLevel(HttpLoggingInterceptor.Level.BODY)
}
)
.build()

private val retrofitClient = Retrofit.Builder()
.client(okHttpClient)
.baseUrl(BuildConfig.G_STORAGE_URL)
.addConverterFactory(JacksonConverterFactory.create())
.build()

val googleStorageREST: GoogleStorageREST = retrofitClient.create(GoogleStorageREST::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.omh.android.storage.api.drive.nongms.data

import com.omh.android.storage.api.drive.nongms.data.model.FilesFoldersListResponse
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

internal interface GoogleStorageREST {

@GET("files")
fun getFilesFoldersList(
@Query("q") query: String = "'root' in parents and trashed = false",
@Query("fields") fields: String = "files(id, name, mimeType, modifiedTime)"
): Call<FilesFoldersListResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.omh.android.storage.api.drive.nongms.data.datasource

import com.omh.android.storage.api.data.datasource.network.FilesFoldersNetworkDataSource
import com.omh.android.storage.api.drive.nongms.data.GoogleStorageREST
import com.omh.android.storage.api.drive.nongms.data.mapper.fromFilesFoldersResponseListToData

internal class FilesFoldersRestDataSource(
private val storageService: GoogleStorageREST,
) : FilesFoldersNetworkDataSource {

override fun getAll() = fromFilesFoldersResponseListToData(
storageService.getFilesFoldersList().execute()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.omh.android.storage.api.drive.nongms.data.mapper

import com.omh.android.storage.api.data.model.RemoteFile
import com.omh.android.storage.api.data.model.RemoteFileOrFolder
import com.omh.android.storage.api.data.model.RemoteFolder
import com.omh.android.storage.api.drive.nongms.data.model.FilesFoldersListResponse
import retrofit2.Response
import java.text.SimpleDateFormat

private const val RESPONSE_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

internal fun fromFilesFoldersResponseListToData(
response: Response<FilesFoldersListResponse>
): List<RemoteFileOrFolder> {
val outputList = mutableListOf<RemoteFileOrFolder>()
val filesInBody = response.body()?.files
if (!response.isSuccessful || filesInBody == null) return outputList
filesInBody.map { fileFolderResponse ->
val modifiedTimeAsLong = SimpleDateFormat(RESPONSE_DATE_FORMAT)
.parse(fileFolderResponse.modifiedTime)
.time
outputList.add(
if (fileFolderResponse.mimeType.contains("folder")) {
RemoteFolder(
fileFolderResponse.name,
modifiedTimeAsLong
)
} else {
RemoteFile(
fileFolderResponse.name,
fileFolderResponse.mimeType,
modifiedTimeAsLong
)
}
)
}
return outputList
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.omh.android.storage.api.drive.nongms.data.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty

@JsonIgnoreProperties(ignoreUnknown = true)
internal class FileOrFolderResponse(
@JsonProperty("id")
val id: String,
@JsonProperty("name")
val name: String,
@JsonProperty("mimeType")
val mimeType: String,
@JsonProperty("modifiedTime")
val modifiedTime: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.omh.android.storage.api.drive.nongms.data.model

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty

@JsonIgnoreProperties(ignoreUnknown = true)
internal class FilesFoldersListResponse(
@JsonProperty("files")
val files: List<FileOrFolderResponse>
)

0 comments on commit 3ccee37

Please sign in to comment.