6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit bc917f0e
Changed files
.../lib/check_in/bloc/check_in_cubit.dart | 38 ++++++-- .../lib/check_in/bloc/check_in_state.dart | 104 ++++++++++++++++----- comwell_key_app/lib/check_in/check_in_page.dart | 41 ++++---- .../lib/check_in/check_in_repository.dart | 45 +++++++++ .../lib/database/daos/bookings_dao.dart | 26 ++++-- comwell_key_app/lib/home/home_page.dart | 4 +- comwell_key_app/lib/overview/models/booking.dart | 2 + comwell_key_app/lib/services/api.dart | 7 ++ 8 files changed, 211 insertions(+), 56 deletions(-)
Diff
diff --git a/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart b/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
index 35be5bf9..8df22217 100644
--- a/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
+++ b/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
@@ -1,18 +1,40 @@
import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/check_in/bloc/check_in_state.dart';
+import 'package:comwell_key_app/check_in/check_in_repository.dart';
+import 'package:comwell_key_app/overview/models/booking.dart';
class CheckInCubit extends Cubit<CheckInState> {
- CheckInCubit() : super(CheckInStateInitial()) {
- Future.delayed(const Duration(seconds: 1), () {
- emit(CheckInStateLoading());
+ final CheckInRepository checkInRepository = CheckInRepository();
+
+ final String bookingId;
+ late final Booking booking;
+
+ CheckInCubit(this.bookingId) : super(CheckInState.initial()) {
+ getBooking();
+ }
+
+ void getBooking() async {
+ emit(state.setLoading(true));
+ try {
+ booking = await checkInRepository.getBooking(bookingId);
+ emit(state.setLoading(false));
startLoading();
- });
+ } catch (err) {
+ emit(state.checkInStatusError(Exception(err.toString())));
+ }
}
Future<void> startLoading() async {
- await Future.delayed(const Duration(seconds: 5));
- emit(CheckInStateRoomFound());
- await Future.delayed(const Duration(seconds: 2));
- emit(CheckInStateYourDigitalKeyCard("2000"));
+ try {
+ await Future<void>.delayed(const Duration(seconds: 1));
+ emit(state.checkInStatusLoading());
+ await checkInRepository.checkIn(booking.confirmationId);
+ emit(state.checkInStatusRoomFound(roomNumber: booking.roomNumber));
+ await Future<void>.delayed(const Duration(seconds: 1));
+ emit(state.checkInStatusYourDigitalCard(roomNumber: booking.roomNumber));
+ }catch(err){
+ emit(state.setLoading(false));
+ emit(state.checkInStatusError(Exception(err.toString())));
+ }
}
}
diff --git a/comwell_key_app/lib/check_in/bloc/check_in_state.dart b/comwell_key_app/lib/check_in/bloc/check_in_state.dart
index 71c1e767..04ed5cfe 100644
--- a/comwell_key_app/lib/check_in/bloc/check_in_state.dart
+++ b/comwell_key_app/lib/check_in/bloc/check_in_state.dart
@@ -1,35 +1,97 @@
-import 'package:easy_localization/easy_localization.dart';
+import '../../overview/models/booking.dart';
-abstract class CheckInState {
- final String title;
- final String subtitle;
+class CheckInState {
+ final bool loading;
+ final CheckInStatus checkInStatus;
- CheckInState(this.title, this.subtitle);
-}
+ CheckInState._({
+ required this.checkInStatus,
+ required this.loading,
+ });
-class CheckInStateInitial extends CheckInState {
- CheckInStateInitial() : super("", "");
-}
+ CheckInState.initial()
+ : this._(
+ checkInStatus: CheckInStatusInitial(),
+ loading: true,
+ );
+
+ String get titleStringId {
+ switch (checkInStatus) {
+ case CheckInStatusInitial _:
+ return "";
+ case CheckInStatusLoading _:
+ return "check_in_loading_title";
+ case CheckInStatusRoomFound _:
+ return "check_in_room_found_title";
+ case CheckInStatusYourDigitalCard _:
+ return "check_in_your_digital_card_title";
+ case CheckInStatusError _:
+ return "check_in_error_title";
+ }
+ }
+
+ String get subtitleStringId {
+ switch (checkInStatus) {
+ case CheckInStatusYourDigitalCard _:
+ return "check_in_your_digital_card_subtitle";
+ default:
+ return "";
+ }
+ }
+
+ CheckInState setLoading(bool loading) => _copyWith(loading: loading);
+
+ CheckInState checkInStatusInitial() =>
+ _copyWith(checkInStatus: CheckInStatusInitial());
+
+ CheckInState checkInStatusLoading() =>
+ _copyWith(checkInStatus: CheckInStatusLoading());
+
+ CheckInState checkInStatusRoomFound({required String roomNumber}) =>
+ _copyWith(checkInStatus: CheckInStatusRoomFound(roomNumber: roomNumber));
-class CheckInStateLoading extends CheckInState {
- CheckInStateLoading() : super("check_in_loading_title".tr(), "");
+ CheckInState checkInStatusYourDigitalCard({required String roomNumber}) =>
+ _copyWith(
+ checkInStatus: CheckInStatusYourDigitalCard(roomNumber: roomNumber));
+
+ CheckInState checkInStatusError(Exception exception) =>
+ _copyWith(checkInStatus: CheckInStatusError(exception: exception), loading: false);
+
+ CheckInState bookingLoaded({required Booking booking}) =>
+ _copyWith(booking: booking);
+
+ CheckInState _copyWith({
+ CheckInStatus? checkInStatus,
+ Booking? booking,
+ bool? loading,
+ }) {
+ return CheckInState._(
+ checkInStatus: checkInStatus ?? this.checkInStatus,
+ loading: loading ?? this.loading,
+ );
+ }
}
-class CheckInStateRoomFound extends CheckInState {
- CheckInStateRoomFound() : super("check_in_room_found_title".tr(), "");
+sealed class CheckInStatus {}
+
+final class CheckInStatusInitial extends CheckInStatus {}
+
+final class CheckInStatusLoading extends CheckInStatus {}
+
+final class CheckInStatusRoomFound extends CheckInStatus {
+ final String roomNumber;
+
+ CheckInStatusRoomFound({required this.roomNumber});
}
-class CheckInStateYourDigitalKeyCard extends CheckInState {
+final class CheckInStatusYourDigitalCard extends CheckInStatus {
final String roomNumber;
- CheckInStateYourDigitalKeyCard(this.roomNumber)
- : super("check_in_your_digital_card_title".tr(),
- "check_in_your_digital_card_subtitle".tr());
+ CheckInStatusYourDigitalCard({required this.roomNumber});
}
-class CheckInStateError extends CheckInState {
- final String errorMessage;
+final class CheckInStatusError extends CheckInStatus {
+ final Exception exception;
- CheckInStateError(this.errorMessage)
- : super("check_in_error_title".tr(), "check_in_error_subtitle".tr());
+ CheckInStatusError({required this.exception});
}
diff --git a/comwell_key_app/lib/check_in/check_in_page.dart b/comwell_key_app/lib/check_in/check_in_page.dart
index 09bc78c8..f94e1945 100644
--- a/comwell_key_app/lib/check_in/check_in_page.dart
+++ b/comwell_key_app/lib/check_in/check_in_page.dart
@@ -58,12 +58,12 @@ class _CheckInPageState extends State<CheckInPage>
final padding = mq.viewPadding;
final height = mq.size.height;
final startPosition = height - padding.bottom - padding.top - 100;
- switch (state) {
- case CheckInStateLoading _:
- case CheckInStateError _:
- case CheckInStateRoomFound _:
+ switch (state.checkInStatus) {
+ case CheckInStatusLoading _:
+ case CheckInStatusError _:
+ case CheckInStatusRoomFound _:
return height / 2 - 100;
- case CheckInStateYourDigitalKeyCard _:
+ case CheckInStatusYourDigitalCard _:
return 100;
case _:
return startPosition;
@@ -72,7 +72,7 @@ class _CheckInPageState extends State<CheckInPage>
Widget getCardContent(BuildContext context) {
final cubit = context.read<CheckInCubit>();
- if (cubit.state is CheckInStateYourDigitalKeyCard) {
+ if (cubit.state.checkInStatus is CheckInStatusYourDigitalCard) {
return Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(30)),
@@ -80,10 +80,10 @@ class _CheckInPageState extends State<CheckInPage>
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
- "${"check_in_your_digital_card_room_prefix".tr()} ${(cubit.state as CheckInStateYourDigitalKeyCard).roomNumber}",
+ "${"check_in_your_digital_card_room_prefix".tr()} ${(cubit.state.checkInStatus as CheckInStatusYourDigitalCard).roomNumber}",
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
- color: Colors.white,
- ),
+ color: Colors.white,
+ ),
),
),
);
@@ -106,13 +106,18 @@ class _CheckInPageState extends State<CheckInPage>
Widget build(BuildContext context) {
final mq = MediaQuery.of(context);
return BlocConsumer<CheckInCubit, CheckInState>(listener: (context, state) {
- switch (state) {
- case CheckInStateLoading _:
+ switch (state.checkInStatus) {
+ case CheckInStatusInitial _:
playLoading();
- case CheckInStateRoomFound _:
+ break;
+ case CheckInStatusRoomFound _:
playSuccess();
- case CheckInStateError _:
+ break;
+ case CheckInStatusError _:
playError();
+ break;
+ default:
+ break;
}
}, builder: (context, state) {
return Scaffold(
@@ -163,17 +168,19 @@ class _CheckInPageState extends State<CheckInPage>
),
const SizedBox(height: 80),
AnimatedOpacity(
- opacity: state is! CheckInStateInitial ? 1.0 : 0.0,
+ opacity: state.checkInStatus is! CheckInStatusInitial
+ ? 1.0
+ : 0.0,
duration: const Duration(milliseconds: 1000),
child: Container(
alignment: Alignment.center,
width: mq.size.width,
child: Column(
children: [
- Text(state.title),
+ Text(state.titleStringId.tr()),
const SizedBox(height: 12),
Text(
- state.subtitle,
+ state.subtitleStringId.tr(),
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
@@ -187,7 +194,7 @@ class _CheckInPageState extends State<CheckInPage>
],
),
),
- if (state is CheckInStateYourDigitalKeyCard)
+ if (state.checkInStatus is CheckInStatusYourDigitalCard)
Align(
alignment: Alignment.bottomCenter,
child: Column(
diff --git a/comwell_key_app/lib/check_in/check_in_repository.dart b/comwell_key_app/lib/check_in/check_in_repository.dart
new file mode 100644
index 00000000..25924737
--- /dev/null
+++ b/comwell_key_app/lib/check_in/check_in_repository.dart
@@ -0,0 +1,45 @@
+import 'dart:convert';
+
+import 'package:comwell_key_app/database/comwell_db.dart';
+import 'package:comwell_key_app/overview/models/booking.dart';
+import 'package:comwell_key_app/overview/models/payment_details.dart';
+import 'package:comwell_key_app/services/api.dart';
+import 'package:comwell_key_app/utils/json.dart';
+import 'package:comwell_key_app/utils/locator.dart';
+
+class CheckInRepository {
+ final api = Api();
+ final db = locator.get<ComwellDatabase>();
+
+ Future<void> checkIn(String confirmationId) async {
+ await api.checkIn(confirmationId);
+ }
+
+ Future<Booking> getBooking(String bookingId) async {
+ return Booking(
+ id: "helloworld",
+ userId: "123",
+ roomNumber: "1234",
+ startDate: DateTime.now(),
+ endDate: DateTime.now(),
+ status: BookingStatus.current,
+ image: "",
+ hotelName: "hotelName",
+ roomType: "roomType",
+ children: 0,
+ adults: 2,
+ hotelCode: "hotelCode",
+ booker: "booker",
+ bookingDate: DateTime.now(),
+ paymentDetails: const PaymentDetails(
+ cardNumber: "cardNumber",
+ cardHolder: "cardHolder",
+ expiryDate: "expiryDate",
+ cvc: "cvc",
+ cardType: CardType.visa),
+ );
+ final entity = await db.bookingsDao.getBooking(bookingId);
+ final Json json = jsonDecode(entity.json) as Json;
+ return Booking.fromJson(json);
+ }
+}
diff --git a/comwell_key_app/lib/database/daos/bookings_dao.dart b/comwell_key_app/lib/database/daos/bookings_dao.dart
index 89286958..ed370c77 100644
--- a/comwell_key_app/lib/database/daos/bookings_dao.dart
+++ b/comwell_key_app/lib/database/daos/bookings_dao.dart
@@ -19,13 +19,20 @@ class BookingsDao extends DatabaseAccessor<ComwellDatabase>
return bookingEntity.all().get();
}
+ Future<BookingDb> getBooking(String bookingId) {
+ return (select(bookingEntity)
+ ..where((entity) => entity.id.equals(bookingId)))
+ .getSingle();
+ }
+
Future<void> insert(Iterable<Booking> bookings, BookingStatus status) async {
final entities = bookings.map((booking) {
final json = jsonEncode(booking.toJson());
return BookingEntityCompanion.insert(
id: booking.id, json: json, status: status.toString());
});
- await batch((batch) => batch.insertAll(bookingEntity, entities, mode: InsertMode.insertOrReplace));
+ await batch((batch) => batch.insertAll(bookingEntity, entities,
+ mode: InsertMode.insertOrReplace));
}
Future<void> insertBookings(Bookings bookings) async {
@@ -36,7 +43,7 @@ class BookingsDao extends DatabaseAccessor<ComwellDatabase>
Stream<Iterable<Booking>> watchBookingsByStatus(BookingStatus status) {
return (select(bookingEntity)
- ..where((entity) => entity.status.equals(status.toString())))
+ ..where((entity) => entity.status.equals(status.toString())))
.watch()
.map((entities) {
return entities.map((entity) {
@@ -48,13 +55,14 @@ class BookingsDao extends DatabaseAccessor<ComwellDatabase>
Stream<Bookings> watchBookings() {
return (select(bookingEntity)).watch().map((entities) {
- final current = entities.where((ent) =>
- ent.status == BookingStatus.current.toString());
- final past = entities.where((ent) =>
- ent.status == BookingStatus.past.toString());
- final cancelled = entities.where((ent) =>
- ent.status == BookingStatus.cancelled.toString());
- return Bookings(current: _entityToBooking(current),
+ final current = entities
+ .where((ent) => ent.status == BookingStatus.current.toString());
+ final past =
+ entities.where((ent) => ent.status == BookingStatus.past.toString());
+ final cancelled = entities
+ .where((ent) => ent.status == BookingStatus.cancelled.toString());
+ return Bookings(
+ current: _entityToBooking(current),
past: _entityToBooking(past),
cancelled: _entityToBooking(cancelled));
});
diff --git a/comwell_key_app/lib/home/home_page.dart b/comwell_key_app/lib/home/home_page.dart
index c7d354a1..342e2390 100644
--- a/comwell_key_app/lib/home/home_page.dart
+++ b/comwell_key_app/lib/home/home_page.dart
@@ -121,7 +121,9 @@ class _HomeWidget extends State<HomeWidget> {
const SizedBox(height: 400),
ElevatedButton(
onPressed: () {
- context.pushNamed(AppRoutes.preregistration.name);
+ context.pushNamed(AppRoutes.checkIn.name, pathParameters: {
+ "booking_id": "hello world"
+ });
},
style: ButtonStyle(
backgroundColor:
diff --git a/comwell_key_app/lib/overview/models/booking.dart b/comwell_key_app/lib/overview/models/booking.dart
index d1c89c38..1e974c58 100644
--- a/comwell_key_app/lib/overview/models/booking.dart
+++ b/comwell_key_app/lib/overview/models/booking.dart
@@ -23,6 +23,8 @@ class Booking extends Equatable {
final DateTime bookingDate;
final PaymentDetails paymentDetails;
+ String get confirmationId => throw UnimplementedError();
+
const Booking({
required this.id,
required this.userId,
diff --git a/comwell_key_app/lib/services/api.dart b/comwell_key_app/lib/services/api.dart
index 5816115e..94313754 100644
--- a/comwell_key_app/lib/services/api.dart
+++ b/comwell_key_app/lib/services/api.dart
@@ -84,4 +84,11 @@ class Api {
},
);
}
+
+ // Check in
+ Future<void> checkIn(String confirmationId) async {
+ await dio.post("/booking/v1/CheckIn", data: {
+ "confirmationId": confirmationId
+ });
+ }
}