Skip to content

Commit dbbd762

Browse files
committed
add feature to delete all data from the remote database and refactor code
1 parent a4b10cb commit dbbd762

12 files changed

Lines changed: 51 additions & 16 deletions

File tree

src/main/kotlin/com/sakethh/linkora/data/Database.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fun configureDatabase() {
7575
}
7676

7777
private fun createRequiredTables() {
78-
SchemaUtils.create(
79-
FoldersTable, LinksTable, TombstoneTable, PanelsTable, PanelFoldersTable
80-
)
81-
}
78+
SchemaUtils.create(*linkoraTables())
79+
}
80+
81+
fun linkoraTables() = arrayOf(FoldersTable, LinksTable, TombstoneTable, PanelsTable, PanelFoldersTable)

src/main/kotlin/com/sakethh/linkora/data/repository/FoldersImplementation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sakethh.linkora.data.repository
22

3-
import com.sakethh.linkora.domain.Folder
3+
import com.sakethh.linkora.domain.model.Folder
44
import com.sakethh.linkora.domain.dto.IDBasedDTO
55
import com.sakethh.linkora.domain.dto.NewItemResponseDTO
66
import com.sakethh.linkora.domain.dto.TimeStampBasedResponse

src/main/kotlin/com/sakethh/linkora/data/repository/SyncRepoImpl.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package com.sakethh.linkora.data.repository
22

3-
import com.sakethh.linkora.domain.*
3+
import com.sakethh.linkora.data.linkoraTables
4+
import com.sakethh.linkora.domain.LinkType
5+
import com.sakethh.linkora.domain.MediaType
46
import com.sakethh.linkora.domain.dto.AllTablesDTO
57
import com.sakethh.linkora.domain.dto.Tombstone
8+
import com.sakethh.linkora.domain.model.Folder
9+
import com.sakethh.linkora.domain.model.Link
10+
import com.sakethh.linkora.domain.model.Panel
11+
import com.sakethh.linkora.domain.model.PanelFolder
612
import com.sakethh.linkora.domain.repository.SyncRepo
713
import com.sakethh.linkora.domain.tables.*
814
import kotlinx.coroutines.async
915
import kotlinx.coroutines.awaitAll
1016
import kotlinx.coroutines.coroutineScope
1117
import kotlinx.serialization.json.Json
18+
import org.jetbrains.exposed.sql.SchemaUtils
1219
import org.jetbrains.exposed.sql.selectAll
1320
import org.jetbrains.exposed.sql.transactions.transaction
1421

@@ -106,4 +113,16 @@ class SyncRepoImpl : SyncRepo {
106113
panelFolders = updatedPanelFolders.toList()
107114
)
108115
}
116+
117+
override suspend fun deleteEverything(): Result<Unit> {
118+
return try {
119+
transaction {
120+
SchemaUtils.drop(*linkoraTables())
121+
}
122+
Result.success(Unit)
123+
} catch (e: Exception) {
124+
e.printStackTrace()
125+
Result.failure(e)
126+
}
127+
}
109128
}

src/main/kotlin/com/sakethh/linkora/domain/dto/AllTablesDTO.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.sakethh.linkora.domain.dto
22

3-
import com.sakethh.linkora.domain.Folder
4-
import com.sakethh.linkora.domain.Link
5-
import com.sakethh.linkora.domain.Panel
6-
import com.sakethh.linkora.domain.PanelFolder
3+
import com.sakethh.linkora.domain.model.Folder
4+
import com.sakethh.linkora.domain.model.Link
5+
import com.sakethh.linkora.domain.model.Panel
6+
import com.sakethh.linkora.domain.model.PanelFolder
77
import kotlinx.serialization.Serializable
88

99
@Serializable

src/main/kotlin/com/sakethh/linkora/domain/Folder.kt renamed to src/main/kotlin/com/sakethh/linkora/domain/model/Folder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sakethh.linkora.domain
1+
package com.sakethh.linkora.domain.model
22

33
import kotlinx.serialization.Serializable
44

src/main/kotlin/com/sakethh/linkora/domain/Link.kt renamed to src/main/kotlin/com/sakethh/linkora/domain/model/Link.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package com.sakethh.linkora.domain
1+
package com.sakethh.linkora.domain.model
22

3+
import com.sakethh.linkora.domain.LinkType
4+
import com.sakethh.linkora.domain.MediaType
35
import kotlinx.serialization.Serializable
46

57
@Serializable

src/main/kotlin/com/sakethh/linkora/domain/Panel.kt renamed to src/main/kotlin/com/sakethh/linkora/domain/model/Panel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sakethh.linkora.domain
1+
package com.sakethh.linkora.domain.model
22

33
import kotlinx.serialization.Serializable
44

src/main/kotlin/com/sakethh/linkora/domain/PanelFolder.kt renamed to src/main/kotlin/com/sakethh/linkora/domain/model/PanelFolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sakethh.linkora.domain
1+
package com.sakethh.linkora.domain.model
22

33
import kotlinx.serialization.Serializable
44

src/main/kotlin/com/sakethh/linkora/domain/repository/FoldersRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.sakethh.linkora.domain.repository
22

3-
import com.sakethh.linkora.domain.Folder
3+
import com.sakethh.linkora.domain.model.Folder
44
import com.sakethh.linkora.domain.dto.IDBasedDTO
55
import com.sakethh.linkora.domain.dto.NewItemResponseDTO
66
import com.sakethh.linkora.domain.dto.TimeStampBasedResponse

src/main/kotlin/com/sakethh/linkora/domain/repository/SyncRepo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ import com.sakethh.linkora.domain.dto.Tombstone
66
interface SyncRepo {
77
suspend fun getTombstonesAfter(eventTimestamp: Long): List<Tombstone>
88
suspend fun getUpdatesAfter(eventTimestamp: Long): AllTablesDTO
9+
suspend fun deleteEverything(): Result<Unit>
910
}

0 commit comments

Comments
 (0)