29 lines
874 B
Kotlin
29 lines
874 B
Kotlin
package space.luminic.finance.mappers
|
|
|
|
import space.luminic.finance.dtos.UserDTO
|
|
import space.luminic.finance.dtos.UserDTO.TelegramAuthDTO
|
|
import space.luminic.finance.models.User
|
|
|
|
object UserMapper {
|
|
// UserMapping.kt
|
|
fun User.toDto(): UserDTO = UserDTO(
|
|
id = this.id!!,
|
|
username = this.username,
|
|
firstName = this.firstName,
|
|
tgId = this.tgId,
|
|
tgUserName = this.tgUserName,
|
|
photoUrl = this.photoUrl,
|
|
roles = this.roles
|
|
)
|
|
|
|
fun TelegramAuthDTO.toTelegramMap(): Map<String, String> =
|
|
mapOf(
|
|
"id" to id.toString(),
|
|
"first_name" to (first_name ?: ""),
|
|
"last_name" to (last_name ?: ""),
|
|
"username" to (username ?: ""),
|
|
"photo_url" to (photo_url ?: ""),
|
|
"auth_date" to auth_date.toString(),
|
|
"hash" to hash
|
|
)
|
|
} |