Skip to content

Commit 322e0d1

Browse files
URL generating and listing implemented
ktlint format api key removed
1 parent 9fff250 commit 322e0d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+841
-214
lines changed

app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,9 @@ dependencies {
108108
implementation 'androidx.documentfile:documentfile:1.0.1'
109109

110110
testImplementation "com.google.truth:truth:$versions.truth"
111+
112+
dependencies {
113+
debugImplementation "com.github.chuckerteam.chucker:library:3.4.0"
114+
releaseImplementation "com.github.chuckerteam.chucker:library-no-op:3.4.0"
115+
}
111116
}

app/src/main/java/com/github/code/gambit/backgroundtask/FileUploadWorker.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.github.code.gambit.data.remote.services.file.FileService
2525
import com.github.code.gambit.data.remote.services.file.FileServiceImpl
2626
import com.github.code.gambit.ui.activity.main.MainActivity
2727
import com.github.code.gambit.utility.AppConstant
28+
import com.github.code.gambit.utility.sharedpreference.LastEvaluatedKeyManager
2829
import com.github.code.gambit.utility.sharedpreference.UserManager
2930
import com.google.gson.GsonBuilder
3031
import io.ipfs.kotlin.defaults.InfuraIPFS
@@ -89,7 +90,7 @@ class FileUploadWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker
8990
}
9091

9192
private fun getFileService(): FileService {
92-
return FileServiceImpl(getApiService(), UserManager(applicationContext))
93+
return FileServiceImpl(getApiService(), UserManager(applicationContext), LastEvaluatedKeyManager(applicationContext))
9394
}
9495

9596
/**

app/src/main/java/com/github/code/gambit/data/entity/chache/UrlCacheEntity.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ class UrlCacheEntity(
1010
@ColumnInfo(name = "id")
1111
var id: String,
1212

13-
@ColumnInfo(name = "file")
14-
var file: String,
13+
@ColumnInfo(name = "fileId")
14+
var fileId: String,
15+
16+
@ColumnInfo(name = "hash")
17+
var hash: String,
1518

1619
@PrimaryKey(autoGenerate = false)
1720
@ColumnInfo(name = "timestamp")
1821
var timestamp: String,
1922

2023
@ColumnInfo(name = "visible")
21-
var visible: Boolean
24+
var visible: Boolean,
25+
26+
@ColumnInfo(name = "clicks_left")
27+
val clicksLeft: Int
2228

2329
)

app/src/main/java/com/github/code/gambit/data/entity/network/FileNetworkEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ class FileNetworkEntity(
77

88
@SerializedName("PK")
99
@Expose
10-
var pk: String,
10+
var pk: String = "",
1111

1212
@SerializedName("SK")
1313
@Expose
14-
var sk: String,
14+
var sk: String = "",
1515

1616
@SerializedName("hash")
1717
@Expose

app/src/main/java/com/github/code/gambit/data/entity/network/UrlNetworkEntity.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@ import com.google.gson.annotations.SerializedName
66
class UrlNetworkEntity(
77

88
@SerializedName("PK")
9-
var pk: String,
9+
@Expose
10+
var pk: String = "",
1011

1112
@SerializedName("SK")
1213
@Expose
13-
var sk: String,
14+
var sk: String = "",
1415

1516
@SerializedName("GS1_PK")
1617
@Expose
17-
var gs1_pk: String,
18+
var gs1_pk: String = "",
19+
20+
@SerializedName("hash")
21+
@Expose
22+
var hash: String,
1823

1924
@SerializedName("visible")
2025
@Expose
21-
var visible: Boolean
26+
var visible: String,
27+
28+
@SerializedName("clicks_left")
29+
@Expose
30+
var clicks_left: Int
2231
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.github.code.gambit.data.local
22

33
import com.github.code.gambit.data.model.File
4+
import com.github.code.gambit.data.model.Url
45

56
interface CacheDataSource {
67

78
suspend fun insertFiles(files: List<File>): Long
89
suspend fun getFiles(): List<File>
10+
suspend fun insertUrls(urls: List<Url>): Long
11+
suspend fun getUrls(fileId: String): List<Url>
912
}

app/src/main/java/com/github/code/gambit/data/local/CacheDataSourceImpl.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.github.code.gambit.data.local
22

33
import com.github.code.gambit.data.mapper.cache.FileCacheMapper
4+
import com.github.code.gambit.data.mapper.cache.UrlCacheMapper
45
import com.github.code.gambit.data.model.File
6+
import com.github.code.gambit.data.model.Url
57

68
class CacheDataSourceImpl
79
constructor(
810
val fileCacheMapper: FileCacheMapper,
9-
val fileDao: FileDao
11+
val urlCacheMapper: UrlCacheMapper,
12+
val fileDao: FileDao,
13+
val urlDao: UrlDao
1014
) : CacheDataSource {
1115

1216
override suspend fun getFiles(): List<File> {
@@ -21,4 +25,14 @@ constructor(
2125
}
2226
return c
2327
}
28+
29+
override suspend fun insertUrls(urls: List<Url>): Long {
30+
val res = urlDao.insertUrls(urlCacheMapper.mapToEntityList(urls))
31+
return res.size.toLong()
32+
}
33+
34+
override suspend fun getUrls(fileId: String): List<Url> {
35+
val urls = urlDao.getUrls(fileId)
36+
return urlCacheMapper.mapFromEntityList(urls)
37+
}
2438
}

app/src/main/java/com/github/code/gambit/data/local/Database.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package com.github.code.gambit.data.local
33
import androidx.room.Database
44
import androidx.room.RoomDatabase
55
import com.github.code.gambit.data.entity.chache.FileCacheEntity
6+
import com.github.code.gambit.data.entity.chache.UrlCacheEntity
67

7-
@Database(entities = [FileCacheEntity::class], version = 1)
8+
@Database(entities = [FileCacheEntity::class, UrlCacheEntity::class], version = 1)
89
abstract class Database : RoomDatabase() {
910

1011
abstract fun fileDao(): FileDao
12+
abstract fun urlDao(): UrlDao
1113
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.code.gambit.data.local
2+
3+
import androidx.room.Dao
4+
import androidx.room.Insert
5+
import androidx.room.OnConflictStrategy
6+
import androidx.room.Query
7+
import com.github.code.gambit.data.entity.chache.UrlCacheEntity
8+
9+
@Dao
10+
interface UrlDao {
11+
12+
@Insert(onConflict = OnConflictStrategy.REPLACE)
13+
suspend fun insertUrl(urlCacheEntity: UrlCacheEntity): Long
14+
15+
@Insert(onConflict = OnConflictStrategy.REPLACE)
16+
suspend fun insertUrls(urlCacheEntities: List<UrlCacheEntity>): List<Long>
17+
18+
@Query("SELECT * FROM urls WHERE fileId = :fileId ORDER BY timestamp DESC")
19+
suspend fun getUrls(fileId: String): List<UrlCacheEntity>
20+
}

app/src/main/java/com/github/code/gambit/data/mapper/cache/UrlCacheMapper.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,30 @@ constructor() : EntityMapper<UrlCacheEntity, Url> {
1212
override fun mapFromEntity(entity: UrlCacheEntity): Url {
1313
return Url(
1414
id = entity.id,
15-
file = entity.file,
15+
fileId = entity.fileId,
16+
hash = entity.hash,
1617
timestamp = entity.timestamp,
17-
visible = entity.visible
18+
visible = entity.visible,
19+
clicksLeft = entity.clicksLeft
1820
)
1921
}
2022

2123
override fun mapToEntity(domainModel: Url): UrlCacheEntity {
2224
return UrlCacheEntity(
2325
id = domainModel.id,
24-
file = domainModel.file,
26+
fileId = domainModel.fileId,
27+
hash = domainModel.hash,
2528
timestamp = domainModel.timestamp,
26-
visible = domainModel.visible
29+
visible = domainModel.visible,
30+
clicksLeft = domainModel.clicksLeft
2731
)
2832
}
2933

3034
override fun mapFromEntityList(entities: List<UrlCacheEntity>): List<Url> {
3135
return entities.map { mapFromEntity(it) }
3236
}
37+
38+
fun mapToEntityList(domainModels: List<Url>): List<UrlCacheEntity> {
39+
return domainModels.map { mapToEntity(it) }
40+
}
3341
}

0 commit comments

Comments
 (0)