generated from JetBrains/compose-multiplatform-template
-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/model/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/model/local/Tag.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2024 Sasikanth Miriyampalli | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.sasikanth.rss.reader.core.model.local | ||
|
||
import com.benasher44.uuid.Uuid | ||
import kotlinx.datetime.Instant | ||
|
||
data class Tag( | ||
val id: Uuid, | ||
val label: String, | ||
val createdAt: Instant, | ||
val updatedAt: Instant, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/database/UuidAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2024 Sasikanth Miriyampalli | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.sasikanth.rss.reader.database | ||
|
||
import app.cash.sqldelight.ColumnAdapter | ||
import com.benasher44.uuid.Uuid | ||
import com.benasher44.uuid.uuidFrom | ||
|
||
internal object UuidAdapter : ColumnAdapter<Uuid, String> { | ||
|
||
override fun decode(databaseValue: String): Uuid { | ||
return uuidFrom(databaseValue) | ||
} | ||
|
||
override fun encode(value: Uuid): String { | ||
return value.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/repository/TagRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2024 Sasikanth Miriyampalli | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.sasikanth.rss.reader.repository | ||
|
||
import app.cash.sqldelight.coroutines.asFlow | ||
import app.cash.sqldelight.coroutines.mapToList | ||
import com.benasher44.uuid.Uuid | ||
import com.benasher44.uuid.uuid4 | ||
import dev.sasikanth.rss.reader.core.model.local.Tag | ||
import dev.sasikanth.rss.reader.database.TagQueries | ||
import dev.sasikanth.rss.reader.di.scopes.AppScope | ||
import dev.sasikanth.rss.reader.util.DispatchersProvider | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.datetime.Clock | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
@AppScope | ||
class TagRepository( | ||
private val dispatchersProvider: DispatchersProvider, | ||
private val tagQueries: TagQueries, | ||
) { | ||
|
||
suspend fun createTag(label: String) { | ||
withContext(dispatchersProvider.io) { | ||
val currentInstant = Clock.System.now() | ||
|
||
tagQueries.saveTag( | ||
id = uuid4(), | ||
label = label, | ||
createdAt = currentInstant, | ||
updatedAt = currentInstant | ||
) | ||
} | ||
} | ||
|
||
suspend fun deleteTag(id: Uuid) = withContext(dispatchersProvider.io) { tagQueries.deleteTag(id) } | ||
|
||
suspend fun updatedTag(label: String, id: Uuid) { | ||
withContext(dispatchersProvider.io) { tagQueries.updateTag(label = label, id = id) } | ||
} | ||
|
||
fun tags(label: String? = null): Flow<List<Tag>> { | ||
return tagQueries.tags(label.orEmpty(), ::Tag).asFlow().mapToList(dispatchersProvider.io) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
shared/src/commonMain/sqldelight/dev/sasikanth/rss/reader/database/Tag.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import com.benasher44.uuid.Uuid; | ||
import kotlinx.datetime.Instant; | ||
|
||
CREATE TABLE tag ( | ||
id TEXT AS Uuid NOT NULL PRIMARY KEY, | ||
label TEXT NOT NULL, | ||
createdAt INTEGER AS Instant NOT NULL, | ||
updatedAt INTEGER AS Instant NOT NULL | ||
); | ||
|
||
tags: | ||
SELECT * FROM tag WHERE label LIKE :label OR label IS NULL OR label = ''; | ||
|
||
updateTag: | ||
UPDATE tag SET label = :label WHERE id = :id; | ||
|
||
deleteTag: | ||
DELETE FROM tag WHERE id = :id; | ||
|
||
saveTag: | ||
INSERT OR IGNORE INTO tag(id, label, createdAt, updatedAt) | ||
VALUES (:id, :label, :createdAt, :updatedAt); |