6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 5d6f9645

AuthorMikkel Thygesen<mth@dwarf.dk>
Date2025-01-30 11:42:54 +0100
553: Updated facilities to be polymorphic in accordance to endpoint spec agreement

Changed files

.../components/hotel_information_menu.dart         | 64 ++++++++++-------
 .../lib/hotel_information/models/facilities.dart   | 16 ++---
 .../lib/hotel_information/models/hotel.dart        |  2 +-
 .../lib/hotel_information/models/parking_info.dart | 14 ++--
 .../lib/hotel_information/models/restaurant.dart   | 13 ++--
 .../lib/hotel_information/models/spa.dart          |  8 ++-
 .../repository/hotel_information_repository.dart   | 82 ++++++++++------------
 7 files changed, 102 insertions(+), 97 deletions(-)

Diff

diff --git a/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart b/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart
index c873218b..5f0ed9c0 100644
--- a/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart
+++ b/comwell_key_app/lib/hotel_information/components/hotel_information_menu.dart
@@ -1,3 +1,6 @@
+import 'package:comwell_key_app/hotel_information/models/parking_info.dart';
+import 'package:comwell_key_app/hotel_information/models/restaurant.dart';
+import 'package:comwell_key_app/hotel_information/models/spa.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -15,6 +18,11 @@ class HotelInformationMenu extends StatelessWidget {
final height = MediaQuery.of(context).size.height;
final cubit = context.read<HotelInformationCubit>();
final hotel = cubit.hotel;
+ final hotelHasRestaurant =
+ hotel.facilities.any((facility) => facility is Restaurant);
+ final hotelHasSpa = hotel.facilities.any((facility) => facility is Spa);
+ final hotelHasParking =
+ hotel.facilities.any((facility) => facility is ParkingInfo);
return ListView(
shrinkWrap: true,
children: [
@@ -30,37 +38,45 @@ class HotelInformationMenu extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- Text(hotel.name, style: Theme.of(context).textTheme.headlineLarge),
+ Text(hotel.name,
+ style: Theme.of(context).textTheme.headlineLarge),
const SizedBox(height: 16),
- HotelInformationListTile(
- iconPath: "assets/icons/ic_chefs_hat.svg",
- title: "hotel_information_page_menu_restaurants_title".tr(),
- subtitle: "hotel_information_page_menu_restaurants_subtitle".tr(),
- onClick: () {
- context.pushNamed("${AppRoutes.hotelInformation.name}/${AppRoutes.restaurants.name}");
- },
- ),
+ if (hotelHasRestaurant)
+ HotelInformationListTile(
+ iconPath: "assets/icons/ic_chefs_hat.svg",
+ title: "hotel_information_page_menu_restaurants_title".tr(),
+ subtitle:
+ "hotel_information_page_menu_restaurants_subtitle".tr(),
+ onClick: () {
+ context.pushNamed(
+ "${AppRoutes.hotelInformation.name}/${AppRoutes.restaurants.name}");
+ },
+ ),
const SizedBox(height: 6),
- HotelInformationListTile(
- iconPath: "assets/icons/ic_spa.svg",
- title: "hotel_information_page_menu_spa_title".tr(),
- subtitle: "hotel_information_page_menu_spa_subtitle".tr(),
- onClick: () {
- context.pushNamed("${AppRoutes.hotelInformation.name}/${AppRoutes.spa.name}");
- },
- ),
+ if (hotelHasSpa)
+ HotelInformationListTile(
+ iconPath: "assets/icons/ic_spa.svg",
+ title: "hotel_information_page_menu_spa_title".tr(),
+ subtitle: "hotel_information_page_menu_spa_subtitle".tr(),
+ onClick: () {
+ context.pushNamed(
+ "${AppRoutes.hotelInformation.name}/${AppRoutes.spa.name}");
+ },
+ ),
const SizedBox(height: 6),
- HotelInformationListTile(
- iconPath: "assets/icons/ic_car.svg",
- title: "hotel_information_page_menu_parking_title".tr(),
- subtitle: "",
- onClick: cubit.onParkingClicked,
- ),
+ if (hotelHasParking)
+ HotelInformationListTile(
+ iconPath: "assets/icons/ic_car.svg",
+ title: "hotel_information_page_menu_parking_title".tr(),
+ subtitle: "",
+ onClick: cubit.onParkingClicked,
+ ),
const SizedBox(height: 6),
HotelInformationListTile(
iconPath: "assets/icons/ic_info.svg",
title: "hotel_information_page_menu_other_info_title".tr(),
- subtitle: "hotel_information_page_menu_other_info_subtitle".tr(),
+ subtitle:
+ "hotel_information_page_menu_other_info_subtitle".tr(),
onClick: cubit.onMoreInformationClicked,
),
const SizedBox(height: 100)
diff --git a/comwell_key_app/lib/hotel_information/models/facilities.dart b/comwell_key_app/lib/hotel_information/models/facilities.dart
index 6a09be67..7cf48532 100644
--- a/comwell_key_app/lib/hotel_information/models/facilities.dart
+++ b/comwell_key_app/lib/hotel_information/models/facilities.dart
@@ -7,17 +7,9 @@ import 'package:json_annotation/json_annotation.dart';
part '../../.generated/hotel_information/models/facilities.g.dart';
@JsonSerializable()
-class Facilities {
- final Iterable<Restaurant> restaurants;
- final Iterable<Spa> spas;
- final ParkingInfo parking;
+class Facility {
+ final String type;
- Facilities({
- required this.restaurants,
- required this.spas,
- required this.parking
- });
-
- Json toJson() => _$FacilitiesToJson(this);
- factory Facilities.fromJson(Map<String, dynamic> json) => _$FacilitiesFromJson(json);
+ Facility({required this.type});
}
+
diff --git a/comwell_key_app/lib/hotel_information/models/hotel.dart b/comwell_key_app/lib/hotel_information/models/hotel.dart
index 7a88ef69..cabffa72 100644
--- a/comwell_key_app/lib/hotel_information/models/hotel.dart
+++ b/comwell_key_app/lib/hotel_information/models/hotel.dart
@@ -13,7 +13,7 @@ class Hotel {
final String country;
final int starRating;
final String image;
- final Facilities facilities;
+ final Iterable<Facility> facilities;
Hotel({
required this.id,
diff --git a/comwell_key_app/lib/hotel_information/models/parking_info.dart b/comwell_key_app/lib/hotel_information/models/parking_info.dart
index 0e6ecd3d..2da8d124 100644
--- a/comwell_key_app/lib/hotel_information/models/parking_info.dart
+++ b/comwell_key_app/lib/hotel_information/models/parking_info.dart
@@ -1,11 +1,11 @@
-
+import 'package:comwell_key_app/hotel_information/models/facilities.dart';
import 'package:comwell_key_app/utils/json.dart';
import 'package:json_annotation/json_annotation.dart';
part '../../.generated/hotel_information/models/parking_info.g.dart';
@JsonSerializable()
-class ParkingInfo {
+class ParkingInfo extends Facility {
final String title;
final String description;
final bool electricCharging;
@@ -17,9 +17,11 @@ class ParkingInfo {
required this.description,
required this.electricCharging,
required this.electricChargingTitle,
- required this.electricChargingDescription
- });
+ required this.electricChargingDescription,
+ }) : super(type: "parking");
+
+ Json toJson() => _$ParkingInfoToJson(this);
- Json toJson() => _$ParkingInfoToJson(this);
- factory ParkingInfo.fromJson(Map<String, dynamic> json) => _$ParkingInfoFromJson(json);
+ factory ParkingInfo.fromJson(Map<String, dynamic> json) =>
+ _$ParkingInfoFromJson(json);
}
diff --git a/comwell_key_app/lib/hotel_information/models/restaurant.dart b/comwell_key_app/lib/hotel_information/models/restaurant.dart
index 93a4d368..3db54abe 100644
--- a/comwell_key_app/lib/hotel_information/models/restaurant.dart
+++ b/comwell_key_app/lib/hotel_information/models/restaurant.dart
@@ -1,10 +1,11 @@
+import 'package:comwell_key_app/hotel_information/models/facilities.dart';
import 'package:comwell_key_app/utils/json.dart';
import 'package:json_annotation/json_annotation.dart';
part '../../.generated/hotel_information/models/restaurant.g.dart';
@JsonSerializable()
-class Restaurant {
+class Restaurant extends Facility {
final String name;
final String description;
final String imageUrl;
@@ -20,9 +21,11 @@ class Restaurant {
required this.address,
required this.openingHours,
required this.phoneNumber,
- required this.email
- });
+ required this.email,
+ }) : super(type: "restaurant");
Json toJson() => _$RestaurantToJson(this);
- factory Restaurant.fromJson(Map<String, dynamic> json) => _$RestaurantFromJson(json);
-}
\ No newline at end of file
+
+ factory Restaurant.fromJson(Map<String, dynamic> json) =>
+ _$RestaurantFromJson(json);
+}
diff --git a/comwell_key_app/lib/hotel_information/models/spa.dart b/comwell_key_app/lib/hotel_information/models/spa.dart
index 4306f6d1..10330e99 100644
--- a/comwell_key_app/lib/hotel_information/models/spa.dart
+++ b/comwell_key_app/lib/hotel_information/models/spa.dart
@@ -1,10 +1,11 @@
+import 'package:comwell_key_app/hotel_information/models/facilities.dart';
import 'package:comwell_key_app/utils/json.dart';
import 'package:json_annotation/json_annotation.dart';
part '../../.generated/hotel_information/models/spa.g.dart';
@JsonSerializable()
-class Spa {
+class Spa extends Facility {
final String title;
final String description;
final String image;
@@ -12,9 +13,10 @@ class Spa {
Spa({
required this.title,
required this.description,
- required this.image
- });
+ required this.image,
+ }) : super(type: "spa");
Json toJson() => _$SpaToJson(this);
+
factory Spa.fromJson(Map<String, dynamic> json) => _$SpaFromJson(json);
}
diff --git a/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart b/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart
index edec6cb4..761681a9 100644
--- a/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart
+++ b/comwell_key_app/lib/hotel_information/repository/hotel_information_repository.dart
@@ -6,58 +6,48 @@ import 'package:comwell_key_app/hotel_information/models/restaurant.dart';
import 'package:comwell_key_app/hotel_information/models/spa.dart';
class HotelInformationRepository {
-
Future<Hotel> fetchHotelInformation() async {
// Fetch hotel information
return Hotel(
- id: '1',
- name: 'Comwell Hotel',
- address: 'Vesterbrogade 6C',
- city: 'Copenhagen',
- country: 'Denmark',
- starRating: 4,
- image: 'assets/images/current_room.png',
- facilities: Facilities(
- restaurants: [
- Restaurant(
- name: 'Restaurant 1',
- description: 'Description 1',
- imageUrl: 'assets/images/restaurant1.jpg',
- address: 'Address 1',
- openingHours: 'Opening Hours 1',
- phoneNumber: '+4528424242',
- email: 'email@comwell.com'
- ),
- Restaurant(
- name: 'Restaurant 2',
- description: 'Description 1',
- imageUrl: 'assets/images/restaurant1.jpg',
- address: 'Address 2',
- openingHours: 'Opening Hours 2',
- phoneNumber: '+4528424242',
- email: 'email@comwell.com'
- ),
- ],
- spas: [
- Spa(
- title: 'Spa 1',
- description: 'Description 1',
- image: 'assets/images/spa1.jpg'
- ),
- Spa(
- title: 'Spa 2',
- description: 'Description 2',
- image: 'assets/images/spa2.jpg'
- ),
- ],
- parking: ParkingInfo(
+ id: '1',
+ name: 'Comwell Hotel',
+ address: 'Vesterbrogade 6C',
+ city: 'Copenhagen',
+ country: 'Denmark',
+ starRating: 4,
+ image: 'assets/images/current_room.png',
+ facilities: [
+ Restaurant(
+ name: 'Restaurant 1',
+ description: 'Description 1',
+ imageUrl: 'assets/images/restaurant1.jpg',
+ address: 'Address 1',
+ openingHours: 'Opening Hours 1',
+ phoneNumber: '+4528424242',
+ email: 'email@comwell.com'),
+ Restaurant(
+ name: 'Restaurant 2',
+ description: 'Description 1',
+ imageUrl: 'assets/images/restaurant1.jpg',
+ address: 'Address 2',
+ openingHours: 'Opening Hours 2',
+ phoneNumber: '+4528424242',
+ email: 'email@comwell.com'),
+ Spa(
+ title: 'Spa 1',
+ description: 'Description 1',
+ image: 'assets/images/spa1.jpg'),
+ Spa(
+ title: 'Spa 2',
+ description: 'Description 2',
+ image: 'assets/images/spa2.jpg'),
+ ParkingInfo(
title: 'Parking',
description: 'Description',
electricCharging: true,
electricChargingTitle: 'Electric Charging',
- electricChargingDescription: 'Electric Charging Description'
- ),
- ),
+ electricChargingDescription: 'Electric Charging Description'),
+ ],
);
}
-}
\ No newline at end of file
+}