From 94085922812046606894264be28db05505d1b9c4 Mon Sep 17 00:00:00 2001 From: Danya_Mochalov Date: Wed, 25 Oct 2023 03:20:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B8=20+=20=D0=A7=D0=B5=D1=80=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B5=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 11 ++++++ .../com/example/shawarma/data/dao/UserDao.kt | 4 ++ .../data/models/DiscountProductModel.kt | 36 +++++++++++++++++ .../shawarma/data/models/OrderModel.kt | 39 +++++++++++++++++++ .../shawarma/data/models/OrderProductModel.kt | 16 ++++++++ .../models/OrderProductModelWithProduct.kt | 11 ++++++ .../shawarma/data/models/OrderWithProducts.kt | 11 ++++++ .../shawarma/data/models/ProductModel.kt | 36 +++++++++++++++++ .../shawarma/{ => data}/models/Status.kt | 2 +- .../example/shawarma/data/models/UserModel.kt | 30 ++++++++++++++ .../shawarma/models/DiscountProductModel.kt | 15 ------- .../com/example/shawarma/models/OrderModel.kt | 34 ---------------- .../example/shawarma/models/ProductModel.kt | 19 --------- .../com/example/shawarma/models/UserModel.kt | 8 ---- .../shawarma/screens/cart/CartScreen.kt | 6 +-- .../screens/discount/DiscountScreen.kt | 4 +- .../shawarma/screens/home/HomeScreen.kt | 4 +- .../shawarma/screens/orders/OrdersScreen.kt | 6 +-- 18 files changed, 205 insertions(+), 87 deletions(-) create mode 100644 app/src/main/java/com/example/shawarma/data/dao/UserDao.kt create mode 100644 app/src/main/java/com/example/shawarma/data/models/DiscountProductModel.kt create mode 100644 app/src/main/java/com/example/shawarma/data/models/OrderModel.kt create mode 100644 app/src/main/java/com/example/shawarma/data/models/OrderProductModel.kt create mode 100644 app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt create mode 100644 app/src/main/java/com/example/shawarma/data/models/OrderWithProducts.kt create mode 100644 app/src/main/java/com/example/shawarma/data/models/ProductModel.kt rename app/src/main/java/com/example/shawarma/{ => data}/models/Status.kt (62%) create mode 100644 app/src/main/java/com/example/shawarma/data/models/UserModel.kt delete mode 100644 app/src/main/java/com/example/shawarma/models/DiscountProductModel.kt delete mode 100644 app/src/main/java/com/example/shawarma/models/OrderModel.kt delete mode 100644 app/src/main/java/com/example/shawarma/models/ProductModel.kt delete mode 100644 app/src/main/java/com/example/shawarma/models/UserModel.kt diff --git a/app/build.gradle b/app/build.gradle index 1323574..f86c5cb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/example/shawarma/data/dao/UserDao.kt b/app/src/main/java/com/example/shawarma/data/dao/UserDao.kt new file mode 100644 index 0000000..1fb842a --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/dao/UserDao.kt @@ -0,0 +1,4 @@ +package com.example.shawarma.data.dao + +interface UserDao { +} \ No newline at end of file diff --git a/app/src/main/java/com/example/shawarma/data/models/DiscountProductModel.kt b/app/src/main/java/com/example/shawarma/data/models/DiscountProductModel.kt new file mode 100644 index 0000000..12b60b4 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/DiscountProductModel.kt @@ -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 { + return listOf( + DiscountProductModel(1, "Шаурма", 150, 120), + DiscountProductModel(1, "Шаурма", 150, 120) + ) +} diff --git a/app/src/main/java/com/example/shawarma/data/models/OrderModel.kt b/app/src/main/java/com/example/shawarma/data/models/OrderModel.kt new file mode 100644 index 0000000..a6ef8e1 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/OrderModel.kt @@ -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 { + return listOf( + ) +} + +fun getAllOrders() : List { + return listOf( + ) +} diff --git a/app/src/main/java/com/example/shawarma/data/models/OrderProductModel.kt b/app/src/main/java/com/example/shawarma/data/models/OrderProductModel.kt new file mode 100644 index 0000000..9e4b9c3 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/OrderProductModel.kt @@ -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 +) diff --git a/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt b/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt new file mode 100644 index 0000000..378d6c5 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt @@ -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 +) diff --git a/app/src/main/java/com/example/shawarma/data/models/OrderWithProducts.kt b/app/src/main/java/com/example/shawarma/data/models/OrderWithProducts.kt new file mode 100644 index 0000000..0454fd8 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/OrderWithProducts.kt @@ -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 +) diff --git a/app/src/main/java/com/example/shawarma/data/models/ProductModel.kt b/app/src/main/java/com/example/shawarma/data/models/ProductModel.kt new file mode 100644 index 0000000..5203063 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/ProductModel.kt @@ -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 { + return listOf( + ) + +} diff --git a/app/src/main/java/com/example/shawarma/models/Status.kt b/app/src/main/java/com/example/shawarma/data/models/Status.kt similarity index 62% rename from app/src/main/java/com/example/shawarma/models/Status.kt rename to app/src/main/java/com/example/shawarma/data/models/Status.kt index 6ce4153..9433570 100644 --- a/app/src/main/java/com/example/shawarma/models/Status.kt +++ b/app/src/main/java/com/example/shawarma/data/models/Status.kt @@ -1,4 +1,4 @@ -package com.example.shawarma.models +package com.example.shawarma.data.models enum class OrderStatus { Unpaid, Preparing, Prepared, Processed diff --git a/app/src/main/java/com/example/shawarma/data/models/UserModel.kt b/app/src/main/java/com/example/shawarma/data/models/UserModel.kt new file mode 100644 index 0000000..b1b0ab4 --- /dev/null +++ b/app/src/main/java/com/example/shawarma/data/models/UserModel.kt @@ -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 + } +} diff --git a/app/src/main/java/com/example/shawarma/models/DiscountProductModel.kt b/app/src/main/java/com/example/shawarma/models/DiscountProductModel.kt deleted file mode 100644 index a1e4bdf..0000000 --- a/app/src/main/java/com/example/shawarma/models/DiscountProductModel.kt +++ /dev/null @@ -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 { - return listOf( - DiscountProductModel(1, "Шаурма", 150, 120), - DiscountProductModel(1, "Шаурма", 150, 120) - ) -} diff --git a/app/src/main/java/com/example/shawarma/models/OrderModel.kt b/app/src/main/java/com/example/shawarma/models/OrderModel.kt deleted file mode 100644 index bf09a4c..0000000 --- a/app/src/main/java/com/example/shawarma/models/OrderModel.kt +++ /dev/null @@ -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, - val userId: Int, - val date: Date -) - -fun getOrdersByUserId() : List { - val map1 = HashMap() - map1[1] = 2 - - val map2 = HashMap() - map2[1] = 2 - return listOf( - OrderModel(1, OrderStatus.Unpaid, map1, 1, Date()), - OrderModel(2, OrderStatus.Preparing, map2 , 1, Date()) - ) -} - -fun getAllOrders() : List { - val map1 = HashMap() - 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()) - ) -} diff --git a/app/src/main/java/com/example/shawarma/models/ProductModel.kt b/app/src/main/java/com/example/shawarma/models/ProductModel.kt deleted file mode 100644 index 018a371..0000000 --- a/app/src/main/java/com/example/shawarma/models/ProductModel.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.example.shawarma.models - -data class ProductModel( - val id: Int, - val title: String, - val price: Int -) - -fun getProducts() :List { - return listOf( - ProductModel(1, "Классика", 150), - ProductModel(1, "Классика", 150), - ProductModel(1, "Классика", 150), - ProductModel(1, "Классика", 150), - ProductModel(1, "Классика", 150), - ProductModel(1, "Классика", 150), - ) - -} diff --git a/app/src/main/java/com/example/shawarma/models/UserModel.kt b/app/src/main/java/com/example/shawarma/models/UserModel.kt deleted file mode 100644 index fb24648..0000000 --- a/app/src/main/java/com/example/shawarma/models/UserModel.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.example.shawarma.models - -data class UserModel( - val id: Int, - val login: String, - val password: String, - val role: String -) diff --git a/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt b/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt index 8ea124a..104d95f 100644 --- a/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt @@ -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 diff --git a/app/src/main/java/com/example/shawarma/screens/discount/DiscountScreen.kt b/app/src/main/java/com/example/shawarma/screens/discount/DiscountScreen.kt index f34cab7..10e0978 100644 --- a/app/src/main/java/com/example/shawarma/screens/discount/DiscountScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/discount/DiscountScreen.kt @@ -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 diff --git a/app/src/main/java/com/example/shawarma/screens/home/HomeScreen.kt b/app/src/main/java/com/example/shawarma/screens/home/HomeScreen.kt index 44d3000..8047802 100644 --- a/app/src/main/java/com/example/shawarma/screens/home/HomeScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/home/HomeScreen.kt @@ -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 diff --git a/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt b/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt index c191be3..c1ca7c3 100644 --- a/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt @@ -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