diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b2300b8..1cb90e4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -9,20 +9,68 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -46,7 +94,7 @@
@@ -72,12 +120,12 @@
"RunOnceActivity.cidr.known.project.marker": "true",
"ToolWindowLogcat.ShowToolbar": "false",
"cidr.known.project.marker": "true",
- "com.android.tools.idea.devicemanager.tab": "Physical",
- "last_opened_file_path": "C:/Users/Danil/Desktop/Новая папка",
- "project.structure.last.edited": "Modules",
+ "com.google.services.firebase.aqiPopupShown": "true",
+ "last_opened_file_path": "C:/Users/Danil/Desktop/MDP/labs/app/src/main/java/com/example/myapplication/composeui/Orders",
+ "project.structure.last.edited": "Project",
"project.structure.proportion": "0.17",
"project.structure.side.proportion": "0.2",
- "settings.editor.selected.configurable": "emulator"
+ "settings.editor.selected.configurable": "preferences.lookFeel"
},
"keyToStringList": {
"ExportApk.BuildVariants": [
@@ -93,7 +141,7 @@
}
}
-
+
@@ -101,6 +149,10 @@
+
+
+
+
@@ -338,7 +390,14 @@
1703256177985
-
+
+ 1703337054935
+
+
+
+ 1703337054935
+
+
@@ -361,25 +420,16 @@
-
+
+
- file://$PROJECT_DIR$/app/src/main/java/com/example/myapplication/composeui/Navbar/NavController.kt
- 63
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/BasketViewModel.kt
- 131
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/myapplication/api/ServiceRemoteMediator.kt
- 55
-
+ file://$PROJECT_DIR$/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/UserViewModel.kt
+ 49
+
diff --git a/app/src/main/java/com/example/myapplication/MainActivity.kt b/app/src/main/java/com/example/myapplication/MainActivity.kt
index 0e9d8bc..5a86ff0 100644
--- a/app/src/main/java/com/example/myapplication/MainActivity.kt
+++ b/app/src/main/java/com/example/myapplication/MainActivity.kt
@@ -15,10 +15,10 @@ import com.example.myapplication.ui.theme.BlueMain
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ //this.deleteDatabase("my-db")
setContent {
AppTheme (darkTheme = false){
// A surface container using the 'background' color from the theme
-
Surface(
modifier = Modifier
.fillMaxSize()
diff --git a/app/src/main/java/com/example/myapplication/api/ApiStatus.kt b/app/src/main/java/com/example/myapplication/api/ApiStatus.kt
new file mode 100644
index 0000000..fadb629
--- /dev/null
+++ b/app/src/main/java/com/example/myapplication/api/ApiStatus.kt
@@ -0,0 +1,3 @@
+package com.example.myapplication.api
+
+enum class ApiStatus { LOADING, ERROR, DONE }
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/ServerService.kt b/app/src/main/java/com/example/myapplication/api/ServerService.kt
index 42005b1..d4bc768 100644
--- a/app/src/main/java/com/example/myapplication/api/ServerService.kt
+++ b/app/src/main/java/com/example/myapplication/api/ServerService.kt
@@ -3,6 +3,7 @@ package com.example.myapplication.api
import com.example.myapplication.api.model.BasketServiceRemote
import com.example.myapplication.api.model.OrderRemote
import com.example.myapplication.api.model.OrderServiceRemote
+import com.example.myapplication.api.model.ReportRemote
import com.example.myapplication.api.model.ServiceRemote
import com.example.myapplication.api.model.UserRemote
import com.example.myapplication.api.model.UserRemoteSignIn
@@ -10,6 +11,8 @@ import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFact
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
+import okhttp3.logging.HttpLoggingInterceptor
+import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.http.Body
import retrofit2.http.DELETE
@@ -20,7 +23,7 @@ import retrofit2.http.Path
import retrofit2.http.Query
interface ServerService {
- //SNEAKER
+ // Service
@GET("service/get/{id}")
suspend fun getService(
@Path("id") id: Int,
@@ -46,7 +49,7 @@ interface ServerService {
@DELETE("service/delete/{id}")
suspend fun deleteService(
@Path("id") id: Int
- )
+ ): Response
//USER
@POST("user/signup")
@@ -59,6 +62,11 @@ interface ServerService {
@Body user: UserRemoteSignIn
): UserRemote
+ @PUT("user/update")
+ suspend fun updateUser(
+ @Body user: UserRemote
+ ): UserRemote
+
//BASKET
@POST("basket/addServiceToBasket")
suspend fun addServiceToBasket(
@@ -140,6 +148,14 @@ interface ServerService {
suspend fun deleteOrder(
@Path("orderId") orderId: Int
)
+
+ //REPORT
+ @GET("report/getReport/{dateFrom}/{dateTo}")
+ suspend fun getReport(
+ @Path("dateFrom") dateFrom: Long,
+ @Path("dateTo") dateTo: Long
+ ): ReportRemote
+
companion object {
private const val BASE_URL = "https://ftkfjb1l-8080.euw.devtunnels.ms/api/"
@@ -148,7 +164,10 @@ interface ServerService {
fun getInstance(): ServerService {
return INSTANCE ?: synchronized(this) {
+ val logger = HttpLoggingInterceptor()
+ logger.level = HttpLoggingInterceptor.Level.BASIC
val client = OkHttpClient.Builder()
+ .addInterceptor(logger)
.build()
return Retrofit.Builder()
.baseUrl(BASE_URL)
diff --git a/app/src/main/java/com/example/myapplication/api/model/RemoteConverters.kt b/app/src/main/java/com/example/myapplication/api/model/RemoteConverters.kt
new file mode 100644
index 0000000..e7ab687
--- /dev/null
+++ b/app/src/main/java/com/example/myapplication/api/model/RemoteConverters.kt
@@ -0,0 +1,24 @@
+package com.example.myapplication.api.model
+
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.util.Base64
+import java.io.ByteArrayOutputStream
+
+class RemoteConverters {
+ companion object {
+ private const val CHARSET_UTF8 = "UTF-8"
+
+ fun fromBitmap(bitmap: Bitmap): String {
+ val outputStream = ByteArrayOutputStream()
+ bitmap.compress(Bitmap.CompressFormat.PNG, 1, outputStream)
+ val byteArray = outputStream.toByteArray()
+ return Base64.encodeToString(byteArray, Base64.NO_WRAP)
+ }
+
+ fun toBitmap(base64String: String): Bitmap {
+ val byteArray = Base64.decode(base64String, Base64.NO_WRAP)
+ return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/model/ReportRemote.kt b/app/src/main/java/com/example/myapplication/api/model/ReportRemote.kt
new file mode 100644
index 0000000..8a334a3
--- /dev/null
+++ b/app/src/main/java/com/example/myapplication/api/model/ReportRemote.kt
@@ -0,0 +1,11 @@
+package com.example.myapplication.api.model
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class ReportRemote(
+ val countOrder: Int,
+ val totalEarn: Double? = 0.0,
+ val avgCheck: Double? = 0.0,
+ val serviceList: List
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/model/ServiceRemote.kt b/app/src/main/java/com/example/myapplication/api/model/ServiceRemote.kt
index daddb0a..674fcfd 100644
--- a/app/src/main/java/com/example/myapplication/api/model/ServiceRemote.kt
+++ b/app/src/main/java/com/example/myapplication/api/model/ServiceRemote.kt
@@ -8,19 +8,19 @@ data class ServiceRemote (
val id: Int? = 0,
val name: String = "",
val price: Double = 0.0,
- val photo: Int? = 0
+ val photo: String = ""
)
fun ServiceRemote.toService(): Service = Service(
id,
name,
price,
- photo
+ RemoteConverters.toBitmap(photo)
)
fun Service.toServiceRemote():ServiceRemote = ServiceRemote(
serviceId,
name,
price,
- photo
+ RemoteConverters.fromBitmap(photo)
)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/model/ServiceWithCount.kt b/app/src/main/java/com/example/myapplication/api/model/ServiceWithCount.kt
new file mode 100644
index 0000000..6d5d9b5
--- /dev/null
+++ b/app/src/main/java/com/example/myapplication/api/model/ServiceWithCount.kt
@@ -0,0 +1,9 @@
+package com.example.myapplication.api.model
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class ServiceWithCount(
+ val service: ServiceRemote,
+ val quantity: Int
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/model/UserRemote.kt b/app/src/main/java/com/example/myapplication/api/model/UserRemote.kt
index 8ce9804..b33d634 100644
--- a/app/src/main/java/com/example/myapplication/api/model/UserRemote.kt
+++ b/app/src/main/java/com/example/myapplication/api/model/UserRemote.kt
@@ -12,7 +12,7 @@ data class UserRemote (
val email: String = "",
val password: String = "",
val role: RoleEnum = RoleEnum.User,
- val photo: Int? = 0,
+ val photo: String = "",
val basketId: Int? = 0
)
@@ -24,7 +24,7 @@ fun UserRemote.toUser(): User = User(
email,
password,
role,
- photo,
+ RemoteConverters.toBitmap(photo),
basketId
)
@@ -35,6 +35,6 @@ fun User.toUserRemote():UserRemote = UserRemote(
email,
password,
role,
- photo,
+ RemoteConverters.fromBitmap(photo),
basketId
)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/repository/RestReportRepository.kt b/app/src/main/java/com/example/myapplication/api/repository/RestReportRepository.kt
new file mode 100644
index 0000000..231d0d7
--- /dev/null
+++ b/app/src/main/java/com/example/myapplication/api/repository/RestReportRepository.kt
@@ -0,0 +1,11 @@
+package com.example.myapplication.api.repository
+
+import com.example.myapplication.api.ServerService
+import com.example.myapplication.api.model.ReportRemote
+import com.example.myapplication.businessLogic.repository.ReportRepository
+
+class RestReportRepository(private var service: ServerService) : ReportRepository {
+ override suspend fun getReportData(dateFrom: Long, dateTo: Long): ReportRemote {
+ return service.getReport(dateFrom, dateTo)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/repository/RestServiceRepository.kt b/app/src/main/java/com/example/myapplication/api/repository/RestServiceRepository.kt
index abfb2f3..e339f54 100644
--- a/app/src/main/java/com/example/myapplication/api/repository/RestServiceRepository.kt
+++ b/app/src/main/java/com/example/myapplication/api/repository/RestServiceRepository.kt
@@ -60,4 +60,9 @@ class RestServiceRepository(
dbServiceRepository.invalidateService(service.serviceId!!)
}catch (ex: Exception){}
}
+
+ override fun call(str: String): Flow> {
+ return dbServiceRepository.call(str)
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/api/repository/RestUserRepository.kt b/app/src/main/java/com/example/myapplication/api/repository/RestUserRepository.kt
index ae0e08d..b9dd14d 100644
--- a/app/src/main/java/com/example/myapplication/api/repository/RestUserRepository.kt
+++ b/app/src/main/java/com/example/myapplication/api/repository/RestUserRepository.kt
@@ -15,7 +15,7 @@ class RestUserRepository(
}
override suspend fun update(user: User) {
- println()
+ service.updateUser(user.toUserRemote())
}
override suspend fun delete(user: User) {
diff --git a/app/src/main/java/com/example/myapplication/businessLogic/repository/ReportRepository.kt b/app/src/main/java/com/example/myapplication/businessLogic/repository/ReportRepository.kt
new file mode 100644
index 0000000..e2c08c0
--- /dev/null
+++ b/app/src/main/java/com/example/myapplication/businessLogic/repository/ReportRepository.kt
@@ -0,0 +1,7 @@
+package com.example.myapplication.businessLogic.repository
+
+import com.example.myapplication.api.model.ReportRemote
+
+interface ReportRepository {
+ suspend fun getReportData(dateFrom: Long, dateTo: Long): ReportRemote
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/businessLogic/repository/ServiceRepository.kt b/app/src/main/java/com/example/myapplication/businessLogic/repository/ServiceRepository.kt
index 6a8f22e..af7b18a 100644
--- a/app/src/main/java/com/example/myapplication/businessLogic/repository/ServiceRepository.kt
+++ b/app/src/main/java/com/example/myapplication/businessLogic/repository/ServiceRepository.kt
@@ -10,4 +10,5 @@ interface ServiceRepository {
suspend fun delete(service: Service)
suspend fun getServiceById(id: Int): Service
suspend fun getAllServices(): Flow>
+ fun call(str: String): Flow>
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/AppViewModelProvider.kt b/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/AppViewModelProvider.kt
index 131523e..71a9ff7 100644
--- a/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/AppViewModelProvider.kt
+++ b/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/AppViewModelProvider.kt
@@ -12,13 +12,25 @@ object AppViewModelProvider {
ServiceViewModel(app().container.serviceRepo)
}
initializer {
- UserViewModel(app().container.userRepo, app().container.basketRepo)
+ UserViewModel(
+ app().container.userRepo,
+ app().container.basketRepo
+ )
}
initializer {
- OrderViewModel(app().container.orderRepo, app().container.basketRepo)
+ OrderViewModel(
+ app().container.orderRepo,
+ app().container.basketRepo
+ )
}
initializer {
- BasketViewModel(app().container.basketRepo, app().container.orderRepo,)
+ BasketViewModel(
+ app().container.basketRepo,
+ app().container.orderRepo,
+ )
+ }
+ initializer {
+ ReportViewModel(app().container.reportRepo)
}
}
}
diff --git a/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/BasketViewModel.kt b/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/BasketViewModel.kt
index 19393a7..1af0b05 100644
--- a/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/BasketViewModel.kt
+++ b/app/src/main/java/com/example/myapplication/businessLogic/viewmodel/BasketViewModel.kt
@@ -2,7 +2,6 @@ package com.example.myapplication.businessLogic.viewmodel
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableDoubleStateOf
-import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.GlobalUser
import com.example.myapplication.businessLogic.repository.BasketRepository
@@ -17,9 +16,10 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
-data class ServiceWithQuantity(val service: Service, val quantityStateFlow: MutableStateFlow)
-
-class BasketViewModel(private val basketRepository: BasketRepository, private val orderRepository: OrderRepository) : ViewModel() {
+class BasketViewModel(
+ private val basketRepository: BasketRepository,
+ private val orderRepository: OrderRepository
+) : MyViewModel() {
private val _quantityMap = MutableStateFlow