mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 02:46:54 -04:00
migrate to multidatabase structure and clean up code
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
package com.hako.base.domain.database
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.hako.base.domain.database.dao.AlbumDao
|
||||
import com.hako.base.domain.database.dao.PhotoDao
|
||||
import com.hako.base.domain.database.dao.UserDao
|
||||
import com.hako.base.domain.database.entities.AlbumEntity
|
||||
import com.hako.base.domain.database.entities.PhotoEntity
|
||||
import com.hako.base.domain.database.entities.UserEntity
|
||||
|
||||
@Database(entities = [UserEntity::class, AlbumEntity::class, PhotoEntity::class], version = 1, exportSchema = false)
|
||||
abstract class DatabaseClient : RoomDatabase() {
|
||||
abstract fun userDao(): UserDao
|
||||
abstract fun albumDao(): AlbumDao
|
||||
abstract fun photoDao(): PhotoDao
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.hako.base.domain.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.hako.base.domain.database.entities.AlbumEntity
|
||||
|
||||
@Dao
|
||||
interface AlbumDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun save(entity: AlbumEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun saveAll(entities: List<AlbumEntity>)
|
||||
|
||||
@Query("SELECT * FROM ${AlbumEntity.TABLE_NAME} WHERE userId = :userId ORDER BY id ASC")
|
||||
fun getAlbums(userId: Int): List<AlbumEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${AlbumEntity.TABLE_NAME}")
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${AlbumEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.hako.base.domain.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.hako.base.domain.database.entities.PhotoEntity
|
||||
|
||||
@Dao
|
||||
interface PhotoDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun save(entity: PhotoEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun saveAll(entities: List<PhotoEntity>)
|
||||
|
||||
@Query("SELECT * FROM ${PhotoEntity.TABLE_NAME} WHERE albumId = :albumId ORDER BY id ASC")
|
||||
fun getPhotos(albumId: Int): List<PhotoEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${PhotoEntity.TABLE_NAME}")
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${PhotoEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.hako.base.domain.database.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.hako.base.domain.database.entities.UserEntity
|
||||
|
||||
@Dao
|
||||
interface UserDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun save(entity: UserEntity)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun saveAll(entities: List<UserEntity>)
|
||||
|
||||
@Query("UPDATE ${UserEntity.TABLE_NAME} SET isFavorite = :favorite WHERE id = :id")
|
||||
fun saveFavorite(id: Int, favorite: Boolean): Int
|
||||
|
||||
@Query("SELECT * FROM ${UserEntity.TABLE_NAME} ORDER BY id ASC")
|
||||
fun getAllUsers(): List<UserEntity>
|
||||
|
||||
@Query("SELECT * FROM ${UserEntity.TABLE_NAME} WHERE isFavorite = 1 ORDER BY id ASC")
|
||||
fun getFavoriteUsers(): List<UserEntity>
|
||||
|
||||
@Query("SELECT COUNT(*) FROM ${UserEntity.TABLE_NAME}")
|
||||
fun count(): Int
|
||||
|
||||
@Query("DELETE FROM ${UserEntity.TABLE_NAME}")
|
||||
fun nukeDatabase()
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.hako.base.domain.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = AlbumEntity.TABLE_NAME, indices = [Index(value = ["id"], unique = true)])
|
||||
data class AlbumEntity(
|
||||
@PrimaryKey
|
||||
val id: Int,
|
||||
val userId: Int,
|
||||
val title: String
|
||||
) {
|
||||
companion object {
|
||||
const val TABLE_NAME = "albums"
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.hako.base.domain.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = PhotoEntity.TABLE_NAME, indices = [Index(value = ["id"], unique = true)])
|
||||
data class PhotoEntity(
|
||||
@PrimaryKey
|
||||
val id: Int,
|
||||
val albumId: Int,
|
||||
val title: String,
|
||||
val photoUrl: String,
|
||||
val thumbnailUrl: String
|
||||
) {
|
||||
companion object {
|
||||
const val TABLE_NAME = "photos"
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.hako.base.domain.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = UserEntity.TABLE_NAME, indices = [Index(value = ["id"], unique = true)])
|
||||
data class UserEntity(
|
||||
@PrimaryKey
|
||||
val id: Int,
|
||||
val realName: String,
|
||||
val userName: String,
|
||||
val email: String,
|
||||
val phone: String,
|
||||
val website: String,
|
||||
val isFavorite: Boolean = false
|
||||
) {
|
||||
companion object {
|
||||
const val TABLE_NAME = "users"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user