Заготовка
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package chats.data.local.dao
|
||||
|
||||
import androidx.room.*
|
||||
import chats.data.local.database.ChatEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* DAO для операций с чатами в Room Database
|
||||
*/
|
||||
@Dao
|
||||
interface ChatDao {
|
||||
|
||||
@Query("SELECT * FROM chats ORDER BY updatedAtMillis DESC")
|
||||
fun getAllChats(): Flow<List<ChatEntity>>
|
||||
|
||||
@Query("SELECT * FROM chats WHERE remoteId = :remoteId LIMIT 1")
|
||||
suspend fun getChatByRemoteId(remoteId: String): ChatEntity?
|
||||
|
||||
@Query("SELECT * FROM chats WHERE localId = :localId LIMIT 1")
|
||||
suspend fun getChatByLocalId(localId: String): ChatEntity?
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertChat(chat: ChatEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertChats(chats: List<ChatEntity>)
|
||||
|
||||
@Update
|
||||
suspend fun updateChat(chat: ChatEntity)
|
||||
|
||||
@Query("UPDATE chats SET lastMessageText = :lastMessageText, lastMessageTimestamp = :timestamp WHERE remoteId = :chatId")
|
||||
suspend fun updateLastMessage(chatId: String, lastMessageText: String?, timestamp: String?)
|
||||
|
||||
@Query("UPDATE chats SET unreadCount = :count WHERE remoteId = :chatId")
|
||||
suspend fun updateUnreadCount(chatId: String, count: Int)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteChat(chat: ChatEntity)
|
||||
|
||||
@Query("DELETE FROM chats WHERE remoteId = :remoteId")
|
||||
suspend fun deleteChatByRemoteId(remoteId: String)
|
||||
|
||||
@Query("DELETE FROM chats")
|
||||
suspend fun deleteAllChats()
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package chats.data.local.dao
|
||||
|
||||
import androidx.room.*
|
||||
import chats.data.local.database.MessageEntity
|
||||
import chats.domain.model.MessageStatus
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* DAO для операций с сообщениями в Room Database
|
||||
*/
|
||||
@Dao
|
||||
interface MessageDao {
|
||||
|
||||
@Query("SELECT * FROM messages WHERE chatId = :chatId ORDER BY sequenceId ASC")
|
||||
fun getMessagesByChatId(chatId: String): Flow<List<MessageEntity>>
|
||||
|
||||
@Query("SELECT * FROM messages WHERE chatId = :chatId AND sequenceId > :afterSequenceId ORDER BY sequenceId ASC LIMIT :limit")
|
||||
suspend fun getMessagesAfter(chatId: String, afterSequenceId: Long, limit: Int): List<MessageEntity>
|
||||
|
||||
@Query("SELECT * FROM messages WHERE chatId = :chatId AND sequenceId < :beforeSequenceId ORDER BY sequenceId DESC LIMIT :limit")
|
||||
suspend fun getMessagesBefore(chatId: String, beforeSequenceId: Long, limit: Int): List<MessageEntity>
|
||||
|
||||
@Query("SELECT * FROM messages WHERE localId = :localId")
|
||||
suspend fun getMessageByLocalId(localId: String): MessageEntity?
|
||||
|
||||
@Query("SELECT * FROM messages WHERE serverId = :serverId")
|
||||
suspend fun getMessageByServerId(serverId: String): MessageEntity?
|
||||
|
||||
@Query("SELECT * FROM messages WHERE status IN (:statuses) AND chatId = :chatId")
|
||||
suspend fun getMessagesByStatus(chatId: String, statuses: List<MessageStatus>): List<MessageEntity>
|
||||
|
||||
@Query("SELECT * FROM messages WHERE status = :status")
|
||||
fun getMessagesByStatusFlow(status: MessageStatus): Flow<List<MessageEntity>>
|
||||
|
||||
@Query("SELECT * FROM messages WHERE status IN (:statuses)")
|
||||
suspend fun getPendingMessages(statuses: List<MessageStatus>): List<MessageEntity>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertMessage(message: MessageEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertMessages(messages: List<MessageEntity>)
|
||||
|
||||
@Update
|
||||
suspend fun updateMessage(message: MessageEntity)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteMessage(message: MessageEntity)
|
||||
|
||||
@Query("DELETE FROM messages WHERE localId = :localId")
|
||||
suspend fun deleteMessageByLocalId(localId: String)
|
||||
|
||||
@Query("DELETE FROM messages WHERE chatId = :chatId")
|
||||
suspend fun deleteMessagesByChatId(chatId: String)
|
||||
|
||||
@Query("UPDATE messages SET status = :status, updatedAtMillis = :updatedAtMillis WHERE localId = :localId")
|
||||
suspend fun updateMessageStatus(localId: String, status: MessageStatus, updatedAtMillis: Long)
|
||||
|
||||
@Query("UPDATE messages SET serverId = :serverId, status = :status, updatedAtMillis = :updatedAtMillis WHERE localId = :localId")
|
||||
suspend fun updateMessageWithServerId(localId: String, serverId: String, status: MessageStatus, updatedAtMillis: Long)
|
||||
|
||||
@Query("UPDATE messages SET status = :status, errorMessage = :errorMessage, retryCount = retryCount + 1, updatedAtMillis = :updatedAtMillis WHERE localId = :localId")
|
||||
suspend fun updateMessageError(localId: String, status: MessageStatus, errorMessage: String, updatedAtMillis: Long)
|
||||
|
||||
@Query("SELECT COUNT(*) FROM messages WHERE chatId = :chatId AND status IN (:statuses)")
|
||||
suspend fun getUnsentCount(chatId: String, statuses: List<MessageStatus>): Int
|
||||
|
||||
@Query("SELECT * FROM messages WHERE chatId = :chatId AND status = :status LIMIT 1")
|
||||
suspend fun getFirstMessageByStatus(chatId: String, status: MessageStatus): MessageEntity?
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package chats.data.local.dao
|
||||
|
||||
import androidx.room.*
|
||||
import chats.data.local.database.UserProfileEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* DAO для операций с профилями пользователей в Room Database
|
||||
*/
|
||||
@Dao
|
||||
interface UserProfileDao {
|
||||
|
||||
@Query("SELECT * FROM user_profile WHERE userId = :userId LIMIT 1")
|
||||
suspend fun getUserById(userId: String): UserProfileEntity?
|
||||
|
||||
@Query("SELECT * FROM user_profile WHERE userId = :userId")
|
||||
fun getUserByIdFlow(userId: String): Flow<UserProfileEntity?>
|
||||
|
||||
@Query("SELECT * FROM user_profile")
|
||||
fun getAllUsers(): Flow<List<UserProfileEntity>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertUser(user: UserProfileEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertUsers(users: List<UserProfileEntity>)
|
||||
|
||||
@Update
|
||||
suspend fun updateUser(user: UserProfileEntity)
|
||||
|
||||
@Delete
|
||||
suspend fun deleteUser(user: UserProfileEntity)
|
||||
|
||||
@Query("DELETE FROM user_profile WHERE userId = :userId")
|
||||
suspend fun deleteUserById(userId: String)
|
||||
}
|
||||
Reference in New Issue
Block a user