From 01bc335c4fcc2cd1c277f3b5237577477252c4e3 Mon Sep 17 00:00:00 2001 From: dasha Date: Thu, 21 Dec 2023 14:39:16 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0?= =?UTF-8?q?.=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D1=82=D1=8C=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myapplication/api/MyServerService.kt | 2 +- .../myapplication/api/session/ReportRemote.kt | 19 +++++--------- .../api/session/RestSessionRepository.kt | 2 +- .../api/session/SessionFromReportRemote.kt | 21 ++++++++++++++++ .../example/myapplication/composeui/Cart.kt | 2 +- .../example/myapplication/composeui/Report.kt | 25 ++++++++++++++++--- .../composeui/ReportViewModel.kt | 2 +- server/reportRouter.js | 6 +++-- 8 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/com/example/myapplication/api/session/SessionFromReportRemote.kt 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' });