Заготовка
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package chats.data.local.mappers
|
||||
|
||||
import chats.data.local.database.ChatEntity
|
||||
import chats.domain.model.Chat
|
||||
|
||||
/**
|
||||
* Преобразует Domain Chat в Entity
|
||||
*/
|
||||
fun Chat.toEntity(): ChatEntity {
|
||||
return ChatEntity(
|
||||
localId = this.id.takeIf { it.isNotBlank() } ?: java.util.UUID.randomUUID().toString(),
|
||||
remoteId = this.id,
|
||||
type = this.type,
|
||||
name = this.name,
|
||||
avatar = this.avatar,
|
||||
unreadCount = this.unreadCount,
|
||||
lastMessageText = this.lastMessage?.content,
|
||||
lastMessageTimestamp = this.lastMessage?.createdAt
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Преобразует Entity в Domain Chat
|
||||
*/
|
||||
fun ChatEntity.toDomain(): Chat {
|
||||
return Chat(
|
||||
id = this.remoteId ?: this.localId,
|
||||
type = this.type,
|
||||
name = this.name,
|
||||
avatar = this.avatar,
|
||||
unreadCount = this.unreadCount,
|
||||
lastMessage = null // lastMessage загружается отдельно
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user