mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 15:17:05 +05:30
feat(database): add support for marking posts as read
This commit is contained in:
parent
1394bc74c4
commit
9c32d6721b
4 changed files with 58 additions and 0 deletions
|
@ -12,6 +12,7 @@ import dagger.Module
|
|||
import dagger.Provides
|
||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||
import dev.msfjarvis.claw.database.local.PostCommentsQueries
|
||||
import dev.msfjarvis.claw.database.local.ReadPostsQueries
|
||||
import dev.msfjarvis.claw.database.local.SavedPostQueries
|
||||
|
||||
@Module
|
||||
|
@ -29,4 +30,11 @@ object QueriesModule {
|
|||
): PostCommentsQueries {
|
||||
return database.postCommentsQueries
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideReadPostsQueries(
|
||||
@InternalDatabaseApi database: LobstersDatabase,
|
||||
): ReadPostsQueries {
|
||||
return database.readPostsQueries
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
CREATE TABLE ReadPosts(
|
||||
id TEXT NOT NULL PRIMARY KEY
|
||||
);
|
||||
|
||||
markRead:
|
||||
INSERT OR REPLACE
|
||||
INTO ReadPosts(id)
|
||||
VALUES (?);
|
||||
|
||||
markUnread:
|
||||
DELETE FROM ReadPosts
|
||||
WHERE id = ?;
|
||||
|
||||
isRead:
|
||||
SELECT *
|
||||
FROM ReadPosts
|
||||
WHERE id = ?;
|
3
database/src/main/sqldelight/migrations/5.sqm
Normal file
3
database/src/main/sqldelight/migrations/5.sqm
Normal file
|
@ -0,0 +1,3 @@
|
|||
CREATE TABLE ReadPosts(
|
||||
id TEXT NOT NULL PRIMARY KEY
|
||||
);
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.database.local
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import java.util.UUID
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ReadPostsQueriesTest {
|
||||
private lateinit var postQueries: ReadPostsQueries
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
postQueries = setupDatabase().readPostsQueries
|
||||
}
|
||||
|
||||
@Test
|
||||
fun markPostAsRead() {
|
||||
val id = UUID.randomUUID().toString()
|
||||
postQueries.markRead(id)
|
||||
assertThat(postQueries.isRead(id).executeAsOne()).isNotNull()
|
||||
postQueries.markUnread(id)
|
||||
assertThat(postQueries.isRead(id).executeAsOneOrNull()).isNull()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue