вся лаб 5

This commit is contained in:
VictoriaPresnyakova 2023-12-19 21:52:09 +04:00
parent 7af968a96a
commit bdebaee485
6 changed files with 9 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application <application
android:name=".App" android:name=".App"
android:allowBackup="true" android:allowBackup="true"

View File

@ -19,7 +19,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
// TODO // TODO
@Database(entities = [Hotel::class, User::class, Order::class, RemoteKeys::class], version = 5) @Database(entities = [Hotel::class, User::class, Order::class, RemoteKeys::class], version = 6)
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun hotelDao(): HotelDao abstract fun hotelDao(): HotelDao
abstract fun userDao(): UserDao abstract fun userDao(): UserDao
@ -43,7 +43,7 @@ abstract class AppDatabase : RoomDatabase() {
userDao.createUser(user1) userDao.createUser(user1)
userDao.createUser(user2) userDao.createUser(user2)
userDao.createUser(user3) userDao.createUser(user3)
// Sneaker // Hotel
val hotelDao = database.hotelDao() val hotelDao = database.hotelDao()
val hotel1 = Hotel(null, "Hotel1", 1000.0, R.drawable.img, 1, "location1", "info1") val hotel1 = Hotel(null, "Hotel1", 1000.0, R.drawable.img, 1, "location1", "info1")
val hotel2 = Hotel(null, "Hotel2", 2000.0, R.drawable.img_2, 2, "location2", "info2") val hotel2 = Hotel(null, "Hotel2", 2000.0, R.drawable.img_2, 2, "location2", "info2")

View File

@ -43,7 +43,7 @@ interface BackendService {
@Body hotel: HotelRemote @Body hotel: HotelRemote
): HotelRemote ): HotelRemote
@DELETE("sneaker/delete/{id}") @DELETE("hotel/delete/{id}")
suspend fun deleteHotel( suspend fun deleteHotel(
@Path("id") id: Int @Path("id") id: Int
) )
@ -80,7 +80,7 @@ interface BackendService {
) )
companion object { companion object {
private const val BASE_URL = "https://59k4pfj3-8080.euw.devtunnels.ms/api/" private const val BASE_URL = "https://7w06qshk-8080.euw.devtunnels.ms/api/"
@Volatile @Volatile
private var INSTANCE: BackendService? = null private var INSTANCE: BackendService? = null

View File

@ -1,8 +1,5 @@
package com.example.androidlabs.api.model package com.example.androidlabs.api.model
import androidx.room.ColumnInfo
import androidx.room.PrimaryKey
import com.example.androidlabs.DB.models.Hotel
import com.example.androidlabs.DB.models.Order import com.example.androidlabs.DB.models.Order
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -15,7 +12,7 @@ data class OrderRemote(
val rooms: Int = 0, val rooms: Int = 0,
val total: Double = 0.0, val total: Double = 0.0,
val userId: Int = 0, val userId: Int = 0,
val bookedHotelId: Int = 0 val hotelId: Int = 0
) )
fun OrderRemote.toOrder(): Order = Order( fun OrderRemote.toOrder(): Order = Order(
@ -25,7 +22,7 @@ fun OrderRemote.toOrder(): Order = Order(
rooms, rooms,
total, total,
userId, userId,
bookedHotelId, hotelId,
) )
fun Order.toOrderRemote():OrderRemote = OrderRemote( fun Order.toOrderRemote():OrderRemote = OrderRemote(

View File

@ -37,7 +37,6 @@ import com.example.androidlabs.homeScreen.SearchField.SearchField
@Composable @Composable
fun HomeScreen(navController: NavHostController, hotelViewModel: HotelViewModel = viewModel(factory = AppViewModelProvider.Factory)) { fun HomeScreen(navController: NavHostController, hotelViewModel: HotelViewModel = viewModel(factory = AppViewModelProvider.Factory)) {
val list = hotelViewModel.HotelList.collectAsLazyPagingItems() val list = hotelViewModel.HotelList.collectAsLazyPagingItems()
//Log.d("MyLog", list.toString())
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()

View File

@ -84,7 +84,7 @@ fun HotelInfo(hotel: Hotel, navController: NavHostController) {
horizontalArrangement = Arrangement.SpaceEvenly horizontalArrangement = Arrangement.SpaceEvenly
){ ){
Text(text = "1 room | 1 Night") Text(text = "1 room | 1 Night")
Text(text = "Rs. 4000") Text(text = "Rs. " + hotel.price)
} }
} }
Divider(color = Color.Black, thickness = 1.dp) Divider(color = Color.Black, thickness = 1.dp)
@ -133,7 +133,7 @@ fun HotelInfo(hotel: Hotel, navController: NavHostController) {
verticalArrangement = Arrangement.SpaceEvenly verticalArrangement = Arrangement.SpaceEvenly
){ ){
Text(text = "Info") Text(text = "Info")
Text(text = "inf") Text(text = hotel.info)
} }
} }
Row( Row(