6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit ac91e2e7
Changed files
.../components/booking_details_bottom_sheet.dart | 2 +- .../components/housekeeping_button.dart | 7 +++-- .../lib/housekeeping/cubit/housekeeping_cubit.dart | 8 +++-- .../lib/housekeeping/housekeeping_page.dart | 7 +++-- .../lib/housekeeping/housekeeping_repository.dart | 10 ++++-- .../lib/housekeeping/models/housekeeping.dart | 36 ++++++++++++++++++++++ comwell_key_app/lib/routing/app_router.dart | 4 +-- comwell_key_app/lib/services/api.dart | 16 ++++++++++ .../lib/services/utils/api_endpoints.dart | 3 ++ 9 files changed, 80 insertions(+), 13 deletions(-)
Diff
diff --git a/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart b/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart
index 34d46a72..74b27e80 100644
--- a/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart
+++ b/comwell_key_app/lib/booking_details/components/booking_details_bottom_sheet.dart
@@ -22,7 +22,7 @@ class BookingDetailsBottomSheet extends StatelessWidget {
cubit.booking.reservationStatus == ReservationStatus.checkedin
? HousekeepingButton(
key: ValueKey(state.isHouseKeepingOrdered),
- roomNumber: cubit.booking.roomNumber)
+ booking: cubit.booking)
: const SizedBox(),
const SizedBox(height: 20),
const CheckOutButton(),
diff --git a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
index b14e1594..3894fdb8 100644
--- a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
+++ b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
@@ -1,3 +1,4 @@
+import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
@@ -9,8 +10,8 @@ import '../../routing/app_routes.dart';
import '../bloc/booking_details_bloc.dart';
class HousekeepingButton extends StatelessWidget {
- final String roomNumber;
- const HousekeepingButton({super.key, required this.roomNumber});
+ final Booking booking;
+ const HousekeepingButton({super.key, required this.booking});
@override
Widget build(BuildContext context) {
@@ -28,7 +29,7 @@ class HousekeepingButton extends StatelessWidget {
borderRadius: BorderRadius.circular(10),
onTap: () async {
if (bloc.state.isHouseKeepingOrdered) return;
- await context.pushNamed(AppRoutes.houseKeeping.name);
+ await context.pushNamed(AppRoutes.houseKeeping.name, extra: booking);
if(!bloc.isClosed) bloc.add(CheckIfHouseKeepingOrdered());
},
child: Padding(
diff --git a/comwell_key_app/lib/housekeeping/cubit/housekeeping_cubit.dart b/comwell_key_app/lib/housekeeping/cubit/housekeeping_cubit.dart
index 427074f9..8ec10f58 100644
--- a/comwell_key_app/lib/housekeeping/cubit/housekeeping_cubit.dart
+++ b/comwell_key_app/lib/housekeeping/cubit/housekeeping_cubit.dart
@@ -1,5 +1,7 @@
import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/housekeeping/cubit/housekeeping_state.dart';
+import 'package:comwell_key_app/housekeeping/models/housekeeping.dart';
+import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/tracking/comwell_tracking.dart';
import 'package:comwell_key_app/tracking/models/analytics_event_item.dart';
import 'package:comwell_key_app/utils/locator.dart';
@@ -39,8 +41,10 @@ class HouseKeepingCubit extends Cubit<HouseKeepingState> {
}
}
- Future<void> onOrderHousekeepingClicked(String roomNumber) async {
- await houseKeepingRepository.saveHouseKeepingOrdered(roomNumber);
+ Future<void> onOrderHousekeepingClicked(Booking booking) async {
+ print("service list: ${state.selectedServices}");
+ final housekeeping = Housekeeping.toJson(booking.hotelCode, booking.roomNumber, state.selectedServices.map((e) => HouseKeepingService.values.firstWhere((element) => element.name == e)).toList());
+ await houseKeepingRepository.saveHouseKeepingOrdered(housekeeping);
final analyticsEventItem = AnalyticsEventItem(
hotelName: "Comwell",
currency: "DKK",
diff --git a/comwell_key_app/lib/housekeeping/housekeeping_page.dart b/comwell_key_app/lib/housekeeping/housekeeping_page.dart
index 0674cd3e..bec88d04 100644
--- a/comwell_key_app/lib/housekeeping/housekeeping_page.dart
+++ b/comwell_key_app/lib/housekeeping/housekeeping_page.dart
@@ -2,6 +2,7 @@ import 'package:comwell_key_app/housekeeping/components/housekeeping_service.dar
import 'package:comwell_key_app/housekeeping/components/selectable_service.dart';
import 'package:comwell_key_app/housekeeping/cubit/housekeeping_cubit.dart';
import 'package:comwell_key_app/housekeeping/cubit/housekeeping_state.dart';
+import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -10,8 +11,8 @@ import 'package:go_router/go_router.dart';
import '../common/components/comwell_app_bar.dart';
class HousekeepingPage extends StatefulWidget {
- final String roomNumber;
- const HousekeepingPage({super.key, required this.roomNumber});
+ final Booking booking;
+ const HousekeepingPage({super.key, required this.booking});
@override
State<HousekeepingPage> createState() => _HousekeepingPageState();
@@ -45,7 +46,7 @@ class _HousekeepingPageState extends State<HousekeepingPage> {
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: () async {
- await cubit.onOrderHousekeepingClicked(widget.roomNumber);
+ await cubit.onOrderHousekeepingClicked(widget.booking);
if (context.mounted) {
context.pop();
}
diff --git a/comwell_key_app/lib/housekeeping/housekeeping_repository.dart b/comwell_key_app/lib/housekeeping/housekeeping_repository.dart
index 90be737f..56a6dcb9 100644
--- a/comwell_key_app/lib/housekeeping/housekeeping_repository.dart
+++ b/comwell_key_app/lib/housekeeping/housekeeping_repository.dart
@@ -1,11 +1,17 @@
+import 'package:comwell_key_app/housekeeping/models/housekeeping.dart';
+import 'package:comwell_key_app/services/api.dart';
+
import '../utils/secure_storage.dart';
class HouseKeepingRepository {
final secureStorage = SecureStorage();
+ final api = Api();
- Future<void> saveHouseKeepingOrdered(String roomNumber) async {
- await secureStorage.write(houseKeepingLastOrderedKey(roomNumber),
+ Future<void> saveHouseKeepingOrdered(Housekeeping housekeeping) async {
+ await secureStorage.write(
+ houseKeepingLastOrderedKey(housekeeping.roomNumber),
DateTime.now().millisecondsSinceEpoch.toString());
+ await api.orderHousekeeping(housekeeping);
}
static String houseKeepingLastOrderedKey(String roomNumber) =>
diff --git a/comwell_key_app/lib/housekeeping/models/housekeeping.dart b/comwell_key_app/lib/housekeeping/models/housekeeping.dart
new file mode 100644
index 00000000..993dec51
--- /dev/null
+++ b/comwell_key_app/lib/housekeeping/models/housekeeping.dart
@@ -0,0 +1,36 @@
+import 'package:comwell_key_app/housekeeping/components/housekeeping_service.dart';
+import 'package:json_annotation/json_annotation.dart';
+
+@JsonSerializable()
+class Housekeeping {
+ final String hotelCode;
+ final String roomNumber;
+ final bool cleaning;
+ final bool soap;
+ final bool towels;
+ final bool trash;
+ final bool refill;
+
+ Housekeeping({
+ required this.hotelCode,
+ required this.roomNumber,
+ required this.cleaning,
+ required this.soap,
+ required this.towels,
+ required this.trash,
+ required this.refill,
+ });
+
+ factory Housekeeping.toJson(
+ String hotelCode, String roomNumber, List<HouseKeepingService> services) {
+ return Housekeeping(
+ hotelCode: hotelCode,
+ roomNumber: roomNumber,
+ cleaning: services.contains(HouseKeepingService.cleaning),
+ soap: services.contains(HouseKeepingService.soap),
+ towels: services.contains(HouseKeepingService.towels),
+ trash: services.contains(HouseKeepingService.trash),
+ refill: services.contains(HouseKeepingService.refill),
+ );
+ }
+}
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 841ef86e..d7579fc1 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -328,8 +328,8 @@ GoRouter goRouter() {
path: "/${AppRoutes.houseKeeping.name}",
name: AppRoutes.houseKeeping.name,
builder: (context, state) {
- final roomNumber = state.extra as String;
- return HousekeepingPage(roomNumber: roomNumber);
+ final booking = state.extra as Booking;
+ return HousekeepingPage(booking: booking);
},
),
GoRoute(
diff --git a/comwell_key_app/lib/services/api.dart b/comwell_key_app/lib/services/api.dart
index b9b0d402..6349eeb3 100644
--- a/comwell_key_app/lib/services/api.dart
+++ b/comwell_key_app/lib/services/api.dart
@@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:adyen_checkout/adyen_checkout.dart';
import 'package:comwell_key_app/hotel_information/models/hotel.dart';
+import 'package:comwell_key_app/housekeeping/models/housekeeping.dart';
import 'package:comwell_key_app/notifications/models/notification_permission.dart';
import 'package:comwell_key_app/profile_settings/model/user.dart';
import 'package:comwell_key_app/services/http_client.dart';
@@ -165,6 +166,21 @@ class Api {
return response.data;
}
+ Future<Json?> orderHousekeeping(Housekeeping housekeeping) async {
+ final body = {
+ "hotelCode": housekeeping.hotelCode,
+ "roomNumber": housekeeping.roomNumber,
+ "cleaning": housekeeping.cleaning,
+ "soap": housekeeping.soap,
+ "towels": housekeeping.towels,
+ "trash": housekeeping.trash,
+ "refill": housekeeping.refill,
+ };
+ final data = jsonEncode(body);
+ final response = await dio.post<Json>(ApiEndpoints.orderHousekeeping, data: data);
+ return response.data;
+ }
+
Future<void> sendContact(String hotelCode) async {}
Future<void> bookSpa(Hotel hotel) async {
diff --git a/comwell_key_app/lib/services/utils/api_endpoints.dart b/comwell_key_app/lib/services/utils/api_endpoints.dart
index 6a18e494..fde9bddd 100644
--- a/comwell_key_app/lib/services/utils/api_endpoints.dart
+++ b/comwell_key_app/lib/services/utils/api_endpoints.dart
@@ -8,6 +8,9 @@ class ApiEndpoints {
static const String checkIn = '/booking/v1/CheckIn';
static const String getBookingDetails = '/booking/v1/GetBookingDetails?confirmationId=';
+ //Default endpoints
+ static const String orderHousekeeping = '/Content/v1/api/v1/house-keeping';
+
// Payment endpoints
static const String storedPaymentMethods = '/Payment/v1/stored-payment-methods';
static const String createAdyenSession = '/Payment/v1/CreateAdyenSession';