Рефакторинг DAO

This commit is contained in:
Данила Мочалов 2023-12-28 05:53:47 +04:00
parent 28bd9e35c8
commit 4bc562c7f2
3 changed files with 0 additions and 17 deletions

View File

@ -18,16 +18,10 @@ interface OrderDao {
suspend fun update(order: OrderModel)
@Delete
suspend fun delete(order: OrderModel)
@Query("select * from orders")
fun getAll(): Flow<List<OrderWithProducts>>
@Query("select * from orders where orders.id =:id")
fun getById(id: Int): Flow<OrderWithProducts?>
@Query("select * from orders where orders.user_id =:userId")
fun getByUserId(userId: Int): Flow<List<OrderWithProducts>>
@Query("select * from orders where orders.user_id =:userId and orders.order_status = 'Неоплачено'")
fun getUnpaidByUser(userId: Int) : Flow<OrderWithProducts>
@Query("select * from orders where orders.user_id =:userId and (orders.order_status = 'Готовится' or orders.order_status = 'Готово')")
fun getPaidByUser(userId: Int) : Flow<List<OrderWithProducts>>
suspend fun insertAll(orders: List<OrderModel>) {
for (order in orders) {

View File

@ -13,8 +13,6 @@ interface OrderProductDao {
suspend fun insert(order: OrderProductModel)
@Update
suspend fun update(order: OrderProductModel)
@Query("delete from order_product WHERE product_id = :productId")
suspend fun deleteByProductId(productId: Int);
@Query("delete from order_product WHERE order_id = :orderId")
suspend fun deleteByOrderId(orderId: Int);
@Delete

View File

@ -27,15 +27,6 @@ interface ProductDao {
@Delete()
suspend fun delete(product: ProductModel)
@Query("select * from products where products.product_old_price is null")
fun getAll() : Flow<List<ProductModel>>
@Query("select * from products where products.product_old_price is not null")
fun getDiscounts() : Flow<List<ProductModel>>
@Query("select * from products")
fun getItems() : Flow<List<ProductModel>>
@Query("select * from products where products.id = :id")
fun getById(id: Int): Flow<ProductModel>