Ну вроде лаба 3 есть. Цена вопроса - 3 энергетика и упаковка хотстеров от горячей штучки. Хочу ли я жить после такого? Думайте сами
This commit is contained in:
parent
39499b30ad
commit
761d76d4aa
@ -20,7 +20,7 @@ interface OrderDao {
|
||||
@Delete
|
||||
suspend fun delete(order: OrderModel)
|
||||
|
||||
@Query("select * from orders")
|
||||
@Query("select * from orders where orders.user_id is not null")
|
||||
fun getAll() : Flow<List<OrderWithProducts>>
|
||||
@Query("select * from orders where orders.id =:id")
|
||||
fun getById(id: Int): Flow<List<OrderWithProducts>>
|
||||
|
@ -12,9 +12,7 @@ import com.example.shawarma.data.dao.ProductDao
|
||||
import com.example.shawarma.data.dao.UserDao
|
||||
import com.example.shawarma.data.models.OrderModel
|
||||
import com.example.shawarma.data.models.OrderProductModel
|
||||
import com.example.shawarma.data.models.OrderProductModelWithProduct
|
||||
import com.example.shawarma.data.models.OrderStatus
|
||||
import com.example.shawarma.data.models.OrderWithProducts
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import com.example.shawarma.data.models.UserModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -48,12 +46,6 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
private suspend fun populateDatabase() {
|
||||
INSTANCE?.let { database ->
|
||||
// // Groups
|
||||
// val groupDao = database.groupDao()
|
||||
// val group1 = Group(1, "Группа 1")
|
||||
// groupDao.insert(group1)
|
||||
// // Students
|
||||
//
|
||||
// Users
|
||||
val userDao = database.userDao()
|
||||
val user1 = UserModel(1, "danya", "password", "ADMIN")
|
||||
@ -70,12 +62,24 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
productDao.insert(discount2)
|
||||
// Orders
|
||||
val orderDao = database.orderDao()
|
||||
val order1 = OrderModel(1, OrderStatus.Preparing.toString(), 1, Date())
|
||||
val order1 = OrderModel(1, OrderStatus.Готовится.toString(), 1, Date())
|
||||
val order2 = OrderModel(2, OrderStatus.Неоплачено.toString(), 1, Date())
|
||||
val order3 = OrderModel(3, OrderStatus.Готово.toString(), 1, Date())
|
||||
val order4 = OrderModel(4, OrderStatus.Выдано.toString(), 1, Date())
|
||||
orderDao.insert(order1)
|
||||
orderDao.insert(order2)
|
||||
orderDao.insert(order3)
|
||||
orderDao.insert(order4)
|
||||
// OrderProducts
|
||||
val orderProductDao = database.orderProductDao()
|
||||
val op1 = OrderProductModel(1, 1, 2, 200)
|
||||
val op2 = OrderProductModel(2, 4, 3, 150)
|
||||
val op3 = OrderProductModel(3, 3, 1, 80)
|
||||
val op4 = OrderProductModel(4, 2, 1, 120)
|
||||
orderProductDao.insert(op1)
|
||||
orderProductDao.insert(op2)
|
||||
orderProductDao.insert(op3)
|
||||
orderProductDao.insert(op4)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
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)
|
||||
)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package com.example.shawarma.data.models
|
||||
|
||||
enum class OrderStatus {
|
||||
Unpaid, Preparing, Prepared, Processed
|
||||
Неоплачено, Готовится, Готово, Выдано
|
||||
}
|
@ -2,14 +2,11 @@ package com.example.shawarma.screens.cart
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.Orientation
|
||||
import androidx.compose.foundation.gestures.scrollable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
@ -35,19 +32,14 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
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.R
|
||||
import com.example.shawarma.data.db.AppDatabase
|
||||
import com.example.shawarma.data.models.OrderModel
|
||||
import com.example.shawarma.data.models.OrderStatus
|
||||
import com.example.shawarma.data.models.OrderWithProducts
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
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
|
||||
@ -85,10 +77,10 @@ fun CartWidget(){
|
||||
val preparingOrders = mutableListOf<OrderWithProducts>()
|
||||
|
||||
for(order in orders) {
|
||||
if (order.order.status == OrderStatus.Unpaid.toString()) {
|
||||
if (order.order.status == OrderStatus.Неоплачено.toString()) {
|
||||
unpaidOrders.add(order)
|
||||
}
|
||||
if (order.order.status == OrderStatus.Preparing.toString()) {
|
||||
if (order.order.status == OrderStatus.Готовится.toString() || order.order.status == OrderStatus.Готово.toString()) {
|
||||
preparingOrders.add(order)
|
||||
}
|
||||
}
|
||||
@ -146,7 +138,7 @@ fun CartWidget(){
|
||||
.height(200.dp)
|
||||
) {
|
||||
items(unpaidOrders.size) {index ->
|
||||
PaidItem(unpaidOrders[index])
|
||||
CartItem(unpaidOrders[index])
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +198,7 @@ fun PaidItem(order : OrderWithProducts) {
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString(),
|
||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
@ -229,7 +221,7 @@ fun PaidItem(order : OrderWithProducts) {
|
||||
color = Color.Gray
|
||||
)
|
||||
Text(
|
||||
text = "Готовится",
|
||||
text = order.order.status,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
@ -277,7 +269,7 @@ fun CartItem(order : OrderWithProducts) {
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString(),
|
||||
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
|
@ -35,10 +35,8 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.example.shawarma.data.db.AppDatabase
|
||||
import com.example.shawarma.data.models.OrderModel
|
||||
import com.example.shawarma.data.models.OrderStatus
|
||||
import com.example.shawarma.data.models.OrderWithProducts
|
||||
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
|
||||
@ -77,13 +75,13 @@ fun OrdersList(){
|
||||
val processedOrders = mutableListOf<OrderWithProducts>()
|
||||
|
||||
for (order in allOrders){
|
||||
if (order.order.status == OrderStatus.Preparing.toString()) {
|
||||
if (order.order.status == OrderStatus.Готовится.toString()) {
|
||||
preparingOrders.add(order)
|
||||
}
|
||||
if (order.order.status == OrderStatus.Prepared.toString()) {
|
||||
if (order.order.status == OrderStatus.Готово.toString()) {
|
||||
preparedOrders.add(order)
|
||||
}
|
||||
if (order.order.status == OrderStatus.Processed.toString()) {
|
||||
if (order.order.status == OrderStatus.Выдано.toString()) {
|
||||
processedOrders.add(order)
|
||||
}
|
||||
}
|
||||
@ -125,9 +123,11 @@ fun OrdersList(){
|
||||
.width(340.dp)
|
||||
.height(250.dp)
|
||||
) {
|
||||
if (preparingOrders.size != 0) {
|
||||
items(preparingOrders.size) {
|
||||
index ->
|
||||
PreparingItem(preparedOrders[index])
|
||||
PreparingItem(preparingOrders[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(
|
||||
@ -142,11 +142,13 @@ fun OrdersList(){
|
||||
.width(340.dp)
|
||||
.height(250.dp)
|
||||
) {
|
||||
if (preparedOrders.size != 0) {
|
||||
items(preparedOrders.size) {
|
||||
index ->
|
||||
PreparedItem(preparedOrders[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = "Выдано:",
|
||||
fontFamily = NunitoFamily,
|
||||
@ -159,10 +161,12 @@ fun OrdersList(){
|
||||
.width(340.dp)
|
||||
.height(250.dp)
|
||||
) {
|
||||
if (processedOrders.size != 0) {
|
||||
items(processedOrders.size) {index ->
|
||||
ProcessedItem(processedOrders[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(70.dp))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user