Зависимости + Черновые сущности
This commit is contained in:
parent
57d4d6b0c8
commit
9408592281
@ -1,6 +1,8 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
//lab 3
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
android {
|
||||
@ -18,6 +20,10 @@ android {
|
||||
vectorDrawables {
|
||||
useSupportLibrary true
|
||||
}
|
||||
|
||||
kapt {
|
||||
arguments {arg("room.schemaLocation", "$projectDir/schemas")}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@ -62,4 +68,9 @@ dependencies {
|
||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
|
||||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
|
||||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
|
||||
|
||||
// lab 3
|
||||
implementation 'androidx.room:room-runtime:2.5.0' // Библиотека "Room"
|
||||
kapt "androidx.room:room-compiler:2.5.0" // Кодогенератор
|
||||
implementation 'androidx.room:room-ktx:2.5.0' // Дополнительно для Kotlin Coroutines, Kotlin Flows
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.example.shawarma.data.dao
|
||||
|
||||
interface UserDao {
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "discount_products")
|
||||
data class DiscountProductModel(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val id: Int?,
|
||||
@ColumnInfo(name = "discount_title")
|
||||
val title: String,
|
||||
@ColumnInfo(name = "discount_old_price")
|
||||
val oldPrice: Int,
|
||||
@ColumnInfo(name = "discount_new_price")
|
||||
val newPrice: Int
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as DiscountProductModel
|
||||
if (id != other.id) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return id ?: -1
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllDiscountProducts() : List<DiscountProductModel> {
|
||||
return listOf(
|
||||
DiscountProductModel(1, "Шаурма", 150, 120),
|
||||
DiscountProductModel(1, "Шаурма", 150, 120)
|
||||
)
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.PrimaryKey
|
||||
import java.util.Date
|
||||
|
||||
@Entity(
|
||||
tableName = "orders",
|
||||
foreignKeys = [
|
||||
ForeignKey(
|
||||
entity = UserModel::class,
|
||||
parentColumns = ["id"],
|
||||
childColumns = ["user_id"],
|
||||
)
|
||||
]
|
||||
)
|
||||
data class OrderModel(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
val id: Int,
|
||||
@ColumnInfo(name = "order_status")
|
||||
val status: String,
|
||||
@ColumnInfo(name = "user_id", index = true)
|
||||
val userId: Int?,
|
||||
@ColumnInfo(name = "date")
|
||||
val date: Date
|
||||
)
|
||||
|
||||
fun getOrdersByUserId() : List<OrderModel> {
|
||||
return listOf(
|
||||
)
|
||||
}
|
||||
|
||||
fun getAllOrders() : List<OrderModel> {
|
||||
return listOf(
|
||||
)
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
|
||||
@Entity(tableName = "order_product", primaryKeys = ["order_id", "product_id"])
|
||||
data class OrderProductModel(
|
||||
@ColumnInfo(name = "order_id", index = true)
|
||||
var orderId: Int,
|
||||
@ColumnInfo(name = "product_id", index = true)
|
||||
var productId: Int,
|
||||
@ColumnInfo(name = "quantity")
|
||||
val quantity: Int,
|
||||
@ColumnInfo(name = "total_price")
|
||||
val totalPrice: Int
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class OrderProductModelWithProduct(
|
||||
@Embedded
|
||||
val orderProductModel: OrderProductModel,
|
||||
@Relation(entity = ProductModel::class, parentColumn = "product_id", entityColumn = "id")
|
||||
val productList: List<ProductModel>
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Relation
|
||||
|
||||
data class OrderWithProducts(
|
||||
@Embedded
|
||||
val order: OrderModel,
|
||||
@Relation(entity = OrderProductModel::class, parentColumn = "id", entityColumn = "order_id")
|
||||
val orderWithProducts: List<OrderProductModelWithProduct>
|
||||
)
|
@ -0,0 +1,36 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "products")
|
||||
data class ProductModel(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
val id: Int?,
|
||||
@ColumnInfo(name = "product_title")
|
||||
val title: String,
|
||||
@ColumnInfo(name = "product_price")
|
||||
val price: Int,
|
||||
@ColumnInfo(name = "product_old_price")
|
||||
val oldPrice: Int?,
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as ProductModel
|
||||
if (id != other.id) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return id ?: -1
|
||||
}
|
||||
}
|
||||
|
||||
fun getProducts() :List<ProductModel> {
|
||||
return listOf(
|
||||
)
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.shawarma.models
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
enum class OrderStatus {
|
||||
Unpaid, Preparing, Prepared, Processed
|
@ -0,0 +1,30 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "users")
|
||||
data class UserModel(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
val id: Int?,
|
||||
@ColumnInfo(name = "user_login")
|
||||
val login: String,
|
||||
@ColumnInfo(name = "user_password")
|
||||
val password: String,
|
||||
@ColumnInfo(name = "user_role")
|
||||
val role: String
|
||||
) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
other as UserModel
|
||||
if (id != other.id) return false
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return id ?: -1
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.example.shawarma.models
|
||||
|
||||
data class DiscountProductModel(
|
||||
val id: Int,
|
||||
val title: String,
|
||||
val oldPrice: Int,
|
||||
val newPrice: Int
|
||||
)
|
||||
|
||||
fun getAllDiscountProducts() : List<DiscountProductModel> {
|
||||
return listOf(
|
||||
DiscountProductModel(1, "Шаурма", 150, 120),
|
||||
DiscountProductModel(1, "Шаурма", 150, 120)
|
||||
)
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.example.shawarma.models
|
||||
|
||||
import java.util.Date
|
||||
|
||||
|
||||
data class OrderModel(
|
||||
val id: Int,
|
||||
val status: OrderStatus,
|
||||
val productsId: HashMap<Int, Int>,
|
||||
val userId: Int,
|
||||
val date: Date
|
||||
)
|
||||
|
||||
fun getOrdersByUserId() : List<OrderModel> {
|
||||
val map1 = HashMap<Int, Int>()
|
||||
map1[1] = 2
|
||||
|
||||
val map2 = HashMap<Int, Int>()
|
||||
map2[1] = 2
|
||||
return listOf(
|
||||
OrderModel(1, OrderStatus.Unpaid, map1, 1, Date()),
|
||||
OrderModel(2, OrderStatus.Preparing, map2 , 1, Date())
|
||||
)
|
||||
}
|
||||
|
||||
fun getAllOrders() : List<OrderModel> {
|
||||
val map1 = HashMap<Int, Int>()
|
||||
map1[1] = 2
|
||||
return listOf(
|
||||
OrderModel(1, OrderStatus.Prepared, map1, 1, Date()),
|
||||
OrderModel(2, OrderStatus.Preparing, map1 , 1, Date()),
|
||||
OrderModel(3, OrderStatus.Processed, map1 , 1, Date())
|
||||
)
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.shawarma.models
|
||||
|
||||
data class ProductModel(
|
||||
val id: Int,
|
||||
val title: String,
|
||||
val price: Int
|
||||
)
|
||||
|
||||
fun getProducts() :List<ProductModel> {
|
||||
return listOf(
|
||||
ProductModel(1, "Классика", 150),
|
||||
ProductModel(1, "Классика", 150),
|
||||
ProductModel(1, "Классика", 150),
|
||||
ProductModel(1, "Классика", 150),
|
||||
ProductModel(1, "Классика", 150),
|
||||
ProductModel(1, "Классика", 150),
|
||||
)
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.example.shawarma.models
|
||||
|
||||
data class UserModel(
|
||||
val id: Int,
|
||||
val login: String,
|
||||
val password: String,
|
||||
val role: String
|
||||
)
|
@ -38,9 +38,9 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.example.shawarma.R
|
||||
import com.example.shawarma.models.OrderModel
|
||||
import com.example.shawarma.models.OrderStatus
|
||||
import com.example.shawarma.models.getOrdersByUserId
|
||||
import com.example.shawarma.data.models.OrderModel
|
||||
import com.example.shawarma.data.models.OrderStatus
|
||||
import com.example.shawarma.data.models.getOrdersByUserId
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightRed
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
|
@ -31,8 +31,8 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.example.shawarma.R
|
||||
import com.example.shawarma.models.DiscountProductModel
|
||||
import com.example.shawarma.models.getAllDiscountProducts
|
||||
import com.example.shawarma.data.models.DiscountProductModel
|
||||
import com.example.shawarma.data.models.getAllDiscountProducts
|
||||
import com.example.shawarma.screens.home.HomeList
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
|
@ -31,8 +31,8 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.example.shawarma.R
|
||||
import com.example.shawarma.models.ProductModel
|
||||
import com.example.shawarma.models.getProducts
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import com.example.shawarma.data.models.getProducts
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
|
@ -30,9 +30,9 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.example.shawarma.models.OrderModel
|
||||
import com.example.shawarma.models.OrderStatus
|
||||
import com.example.shawarma.models.getAllOrders
|
||||
import com.example.shawarma.data.models.OrderModel
|
||||
import com.example.shawarma.data.models.OrderStatus
|
||||
import com.example.shawarma.data.models.getAllOrders
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
|
Loading…
Reference in New Issue
Block a user