diff --git a/app/src/main/java/com/example/myapplication/api/MyServerService.kt b/app/src/main/java/com/example/myapplication/api/MyServerService.kt index 310ce2e..5830d50 100644 --- a/app/src/main/java/com/example/myapplication/api/MyServerService.kt +++ b/app/src/main/java/com/example/myapplication/api/MyServerService.kt @@ -157,7 +157,7 @@ interface MyServerService { suspend fun getReport( @Query("startDate") startDate: Date, @Query("endDate") endDate: Date - ): List + ): ReportRemote companion object { //private const val BASE_URL = "http://192.168.154.166:8080/" diff --git a/app/src/main/java/com/example/myapplication/api/session/ReportRemote.kt b/app/src/main/java/com/example/myapplication/api/session/ReportRemote.kt index 3a6003c..43952fb 100644 --- a/app/src/main/java/com/example/myapplication/api/session/ReportRemote.kt +++ b/app/src/main/java/com/example/myapplication/api/session/ReportRemote.kt @@ -1,21 +1,14 @@ package com.example.myapplication.api.session -import kotlinx.serialization.Contextual import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class ReportRemote( - @SerialName("cinema_name") - val cinemaName: String = "", - @Contextual - @SerialName("current_ticket_date_time") - val ticketDateTime: org.threeten.bp.LocalDateTime, - @SerialName("current_ticket_price") - val ticketPrice: Double = 0.0, - @SerialName("max_ticket_quantity") - val ticketQuantity: Int = 0, - @SerialName("purchased_tickets") - val ticketsPurchased: Int = 0, - val revenue: Double = 0.0 + @SerialName("report_data") + val reportData: List, + @SerialName("total_revenue") + val totalRevenue: Double = 0.0, + @SerialName("total_purchased_tickets") + val totalPurchasedTickets: Int = 0 ) diff --git a/app/src/main/java/com/example/myapplication/api/session/RestSessionRepository.kt b/app/src/main/java/com/example/myapplication/api/session/RestSessionRepository.kt index bedc477..233f3eb 100644 --- a/app/src/main/java/com/example/myapplication/api/session/RestSessionRepository.kt +++ b/app/src/main/java/com/example/myapplication/api/session/RestSessionRepository.kt @@ -51,7 +51,7 @@ class RestSessionRepository( dbSessionRepository.deleteSession(session) } - suspend fun getReport(startDate: Date, endDate: Date): List { + suspend fun getReport(startDate: Date, endDate: Date): ReportRemote { return service.getReport(startDate, endDate) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/api/session/SessionFromReportRemote.kt b/app/src/main/java/com/example/myapplication/api/session/SessionFromReportRemote.kt new file mode 100644 index 0000000..6b84f8a --- /dev/null +++ b/app/src/main/java/com/example/myapplication/api/session/SessionFromReportRemote.kt @@ -0,0 +1,21 @@ +package com.example.myapplication.api.session + +import kotlinx.serialization.Contextual +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SessionFromReportRemote( + @SerialName("cinema_name") + val cinemaName: String = "", + @Contextual + @SerialName("current_ticket_date_time") + val ticketDateTime: org.threeten.bp.LocalDateTime, + @SerialName("current_ticket_price") + val ticketPrice: Double = 0.0, + @SerialName("max_ticket_quantity") + val ticketQuantity: Int = 0, + @SerialName("purchased_tickets") + val ticketsPurchased: Int = 0, + val revenue: Double = 0.0 +) \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/composeui/Cart.kt b/app/src/main/java/com/example/myapplication/composeui/Cart.kt index c21d62c..561d0b4 100644 --- a/app/src/main/java/com/example/myapplication/composeui/Cart.kt +++ b/app/src/main/java/com/example/myapplication/composeui/Cart.kt @@ -101,7 +101,7 @@ fun Cart( ApiStatus.LOADING -> LoadingPlaceholder() else -> ErrorPlaceholder( message = viewModel.apiError, - onBack = { navController.navigate(Screen.Report.route) } + onBack = { navController.navigate(Screen.Cart.route) } ) } } diff --git a/app/src/main/java/com/example/myapplication/composeui/Report.kt b/app/src/main/java/com/example/myapplication/composeui/Report.kt index 6fb4bfc..b96288f 100644 --- a/app/src/main/java/com/example/myapplication/composeui/Report.kt +++ b/app/src/main/java/com/example/myapplication/composeui/Report.kt @@ -95,7 +95,7 @@ fun Report( Text(text = "Получить отчет") } Spacer(modifier = Modifier.height(16.dp)) - CardScreen(reportData = viewModel.reportResultUiState.report) + CardScreen(report = viewModel.reportResultUiState.report) } } @@ -108,14 +108,15 @@ fun Report( } @Composable -fun CardScreen(reportData: List) { +fun CardScreen(report: ReportRemote?) { + if (report == null) return val dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm") - reportData.forEach { + report.reportData.forEach { val (cinemaName, ticketDateTime, ticketPrice, ticketQuantity, ticketsPurchased, revenue) = it Row( modifier = Modifier .fillMaxWidth() - .border(width = 1.dp, color = Color.White, shape = MaterialTheme.shapes.small) + .border(width = 1.dp, color = MaterialTheme.colorScheme.onBackground, shape = MaterialTheme.shapes.small) ) { Column( Modifier @@ -132,4 +133,20 @@ fun CardScreen(reportData: List) { } Spacer(modifier = Modifier.height(16.dp)) } + Text(text = "Итого: ") + Row( + modifier = Modifier + .fillMaxWidth() + .border(width = 1.dp, color = MaterialTheme.colorScheme.onBackground, shape = MaterialTheme.shapes.small) + ) { + Column( + Modifier + .padding(16.dp) + .background(color = Color.Transparent) + ) { + Text(text = "Купили: ${report.totalPurchasedTickets}") + Text(text = "Выручка: ${report.totalRevenue}") + } + } + Spacer(modifier = Modifier.height(16.dp)) } diff --git a/app/src/main/java/com/example/myapplication/composeui/ReportViewModel.kt b/app/src/main/java/com/example/myapplication/composeui/ReportViewModel.kt index 0c253ea..f78d26b 100644 --- a/app/src/main/java/com/example/myapplication/composeui/ReportViewModel.kt +++ b/app/src/main/java/com/example/myapplication/composeui/ReportViewModel.kt @@ -57,5 +57,5 @@ data class ReportUiState( ) data class ReportResultUiState( - val report: List = emptyList() + val report: ReportRemote? = null ) \ No newline at end of file diff --git a/server/reportRouter.js b/server/reportRouter.js index 1229dd6..1fea4b3 100644 --- a/server/reportRouter.js +++ b/server/reportRouter.js @@ -54,8 +54,10 @@ module.exports = (req, res, next) => { }); const sortedReportData = reportData.sort((a, b) => b.revenue - a.revenue); - - res.json(sortedReportData); + const report = { "sortedReportData": sortedReportData, + "total_revenue": sortedReportData.reduce((a, b) => a + b.revenue, 0), + "total_purchased_tickets": sortedReportData.reduce((a, b) => a + b.purchased_tickets, 0) } + res.json(report); } catch (error) { console.error('Error processing report: ', error); res.status(500).json({ message: 'Internal Server Error' });