mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 07:24:55 +00:00
make the domain and data layers
This commit is contained in:
32
lib/features/booking_system/data/booking_dummy_source.dart
Normal file
32
lib/features/booking_system/data/booking_dummy_source.dart
Normal file
@ -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<List<BookingModel>> 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,
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
35
lib/features/booking_system/data/booking_remote_source.dart
Normal file
35
lib/features/booking_system/data/booking_remote_source.dart
Normal file
@ -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<List<BookingModel>> 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<String, dynamic>?;
|
||||
// final error = message?['error'] as Map<String, dynamic>?;
|
||||
// final errorMessage = error?['error'] as String? ?? '';
|
||||
// final formattedErrorMessage =
|
||||
// [_defaultErrorMessage, errorMessage].join(': ');
|
||||
// throw APIException(formattedErrorMessage);
|
||||
// } catch (e) {
|
||||
// final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||
// throw APIException(formattedErrorMessage);
|
||||
// }
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
41
lib/features/booking_system/domain/booking_model.dart
Normal file
41
lib/features/booking_system/domain/booking_model.dart
Normal file
@ -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<String, dynamic> json) => BookingModel(
|
||||
uuid: json['uuid'],
|
||||
roomName: json['roomName'],
|
||||
date: json['date'],
|
||||
timeSlot: json['timeSlot'],
|
||||
cost: json['cost'],
|
||||
);
|
||||
|
||||
static List<BookingModel> fromJsonList(List<dynamic> jsonList) => jsonList
|
||||
.map(
|
||||
(bookModel) => BookingModel.fromJson(bookModel),
|
||||
)
|
||||
.toList();
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'uuid': uuid,
|
||||
'roomName': roomName,
|
||||
'date': date,
|
||||
'timeSlot': timeSlot,
|
||||
'cost': cost,
|
||||
};
|
||||
}
|
||||
5
lib/features/booking_system/domain/booking_service.dart
Normal file
5
lib/features/booking_system/domain/booking_service.dart
Normal file
@ -0,0 +1,5 @@
|
||||
import 'package:syncrow_app/features/booking_system/domain/booking_model.dart';
|
||||
|
||||
abstract interface class BookingService {
|
||||
Future<List<BookingModel>> get();
|
||||
}
|
||||
@ -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}/';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user