wip: Room list
This commit is contained in:
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Created by sweetbread on 22.02.2025, 15:45
|
||||
* Copyright (c) 2025. All rights reserved.
|
||||
* Last modified 22.02.2025, 15:45
|
||||
*/
|
||||
|
||||
package ru.risdeveau.pixeldragon.db
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Database
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Junction
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.Query
|
||||
import androidx.room.Relation
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Entity
|
||||
data class Room(
|
||||
@PrimaryKey val roomId: String,
|
||||
val name: String?,
|
||||
val creatorId: String?,
|
||||
val createTime: Long?,
|
||||
val avatarUrl: String?,
|
||||
val members: Int?,
|
||||
val joined: Boolean
|
||||
)
|
||||
|
||||
@Dao
|
||||
interface RoomDao {
|
||||
// @Query("SELECT * FROM room")
|
||||
// fun getAll(): List<User>
|
||||
|
||||
// @Query("SELECT * FROM user WHERE uid IN (:userIds)")
|
||||
// fun loadAllByIds(userIds: IntArray): List<User>
|
||||
|
||||
// @Query("SELECT * FROM user WHERE first_name LIKE :first AND " +
|
||||
// "last_name LIKE :last LIMIT 1")
|
||||
// fun findByName(first: String, last: String): User
|
||||
|
||||
@Query("SELECT * FROM room WHERE roomId LIKE :rid LIMIT 1")
|
||||
fun getById(rid: String): Room?
|
||||
|
||||
// @Transaction
|
||||
// @Query("SELECT * FROM room WHERE ")
|
||||
// fun getSpace(rid: String): Space
|
||||
|
||||
@Query("SELECT * FROM room WHERE joined = 1 AND roomId NOT IN (SELECT roomId FROM SpaceToRoom)")
|
||||
fun getAllJoined(): List<Room>
|
||||
|
||||
@Insert
|
||||
fun insert(vararg rooms: Room)
|
||||
|
||||
@Delete
|
||||
fun delete(room: Room)
|
||||
}
|
||||
|
||||
@Entity(primaryKeys = ["spaceId", "roomId"])
|
||||
data class SpaceToRoom(
|
||||
val spaceId: String,
|
||||
val roomId: String
|
||||
)
|
||||
|
||||
data class Space(
|
||||
@Embedded val space: Room,
|
||||
@Relation(
|
||||
parentColumn = "spaceId",
|
||||
entityColumn = "roomId",
|
||||
associateBy = Junction(SpaceToRoom::class)
|
||||
)
|
||||
val children: List<Room>
|
||||
)
|
||||
|
||||
@Database(entities = [Room::class, SpaceToRoom::class, User::class], version = 1)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun roomDoa(): RoomDao
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Created by sweetbread on 22.02.2025, 15:45
|
||||
* Copyright (c) 2025. All rights reserved.
|
||||
* Last modified 21.02.2025, 13:38
|
||||
*/
|
||||
|
||||
package ru.risdeveau.pixeldragon.db
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class User(
|
||||
@PrimaryKey val uid: String,
|
||||
@ColumnInfo(name = "name") val name: String?,
|
||||
@ColumnInfo(name = "avatar") val avatar: String?
|
||||
)
|
||||
Reference in New Issue
Block a user