diff --git a/lib/features/booking_system/data/booking_dummy_source.dart b/lib/features/booking_system/data/booking_dummy_source.dart new file mode 100644 index 0000000..d44e40d --- /dev/null +++ b/lib/features/booking_system/data/booking_dummy_source.dart @@ -0,0 +1,32 @@ +import 'package:syncrow_app/features/booking_system/domain/booking_model.dart'; +import 'package:syncrow_app/features/booking_system/domain/booking_service.dart'; + +class BookingDummySource implements BookingService { + @override + Future> get() async { + await Future.delayed(Duration(seconds: 2)); + return [ + BookingModel( + uuid: 'uuid1', + roomName: 'roomName1', + date: 'wed 28th May 2025', + timeSlot: '10:30 AM - 11:30 AM', + cost: 4, + ), + BookingModel( + uuid: 'uuid2', + roomName: 'roomName2', + date: 'wed 28th May 2025', + timeSlot: '10:30 AM - 11:30 AM', + cost: 6, + ), + BookingModel( + uuid: 'uuid3', + roomName: 'roomName3', + date: 'thur 2th june 2025', + timeSlot: '10:30 AM - 1:30 PM', + cost: 10, + ) + ]; + } +} diff --git a/lib/features/booking_system/data/booking_remote_source.dart b/lib/features/booking_system/data/booking_remote_source.dart new file mode 100644 index 0000000..bb9b2f9 --- /dev/null +++ b/lib/features/booking_system/data/booking_remote_source.dart @@ -0,0 +1,35 @@ +import 'package:dio/dio.dart'; +import 'package:syncrow_app/features/booking_system/domain/booking_model.dart'; +import 'package:syncrow_app/features/booking_system/domain/booking_service.dart'; +import 'package:syncrow_app/services/api/api_links_endpoints.dart'; +import 'package:syncrow_app/services/api/http_service.dart'; + +class BookingRemoteSource implements BookingService { + final HTTPService _httpService; + BookingRemoteSource(this._httpService); + + @override + Future> get() async { + try { + return _httpService.get( + path: ApiEndpoints.upcomingBookings, + expectedResponseModel: (json) { + return BookingModel.fromJsonList(json['data']); + }, + ); + } on DioException catch (e) { + return []; + // final message = e.response?.data as Map?; + // final error = message?['error'] as Map?; + // final errorMessage = error?['error'] as String? ?? ''; + // final formattedErrorMessage = + // [_defaultErrorMessage, errorMessage].join(': '); + // throw APIException(formattedErrorMessage); + // } catch (e) { + // final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': '); + // throw APIException(formattedErrorMessage); + // } + // + } + } +} diff --git a/lib/features/booking_system/domain/booking_model.dart b/lib/features/booking_system/domain/booking_model.dart new file mode 100644 index 0000000..8c3ead5 --- /dev/null +++ b/lib/features/booking_system/domain/booking_model.dart @@ -0,0 +1,41 @@ +import 'dart:convert'; + +class BookingModel { + String uuid, roomName, date, timeSlot; + int cost; + BookingModel({ + required this.uuid, + required this.roomName, + required this.date, + required this.timeSlot, + required this.cost, + }); + factory BookingModel.zero() => BookingModel( + uuid: '', + roomName: '', + date: '', + timeSlot: '', + cost: -1, + ); + factory BookingModel.fromJson(Map json) => BookingModel( + uuid: json['uuid'], + roomName: json['roomName'], + date: json['date'], + timeSlot: json['timeSlot'], + cost: json['cost'], + ); + + static List fromJsonList(List jsonList) => jsonList + .map( + (bookModel) => BookingModel.fromJson(bookModel), + ) + .toList(); + + Map toJson() => { + 'uuid': uuid, + 'roomName': roomName, + 'date': date, + 'timeSlot': timeSlot, + 'cost': cost, + }; +} diff --git a/lib/features/booking_system/domain/booking_service.dart b/lib/features/booking_system/domain/booking_service.dart new file mode 100644 index 0000000..f015712 --- /dev/null +++ b/lib/features/booking_system/domain/booking_service.dart @@ -0,0 +1,5 @@ +import 'package:syncrow_app/features/booking_system/domain/booking_model.dart'; + +abstract interface class BookingService { + Future> get(); +} diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index f8cd72f..e66849b 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -234,4 +234,7 @@ abstract class ApiEndpoints { '/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/devices'; static const String getReportLogs = '/devices/{uuid}/report-logs?code={code}'; + + //booking System APIs + static const String upcomingBookings = '/bookings/{uuid}/'; }