make the domain and data layers

This commit is contained in:
raf-dev1
2025-06-16 13:48:15 +03:00
parent 3893740080
commit 9d7113cee8
5 changed files with 116 additions and 0 deletions

View 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,
)
];
}
}

View 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);
// }
//
}
}
}

View 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,
};
}

View File

@ -0,0 +1,5 @@
import 'package:syncrow_app/features/booking_system/domain/booking_model.dart';
abstract interface class BookingService {
Future<List<BookingModel>> get();
}

View File

@ -234,4 +234,7 @@ abstract class ApiEndpoints {
'/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/devices'; '/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/devices';
static const String getReportLogs = '/devices/{uuid}/report-logs?code={code}'; static const String getReportLogs = '/devices/{uuid}/report-logs?code={code}';
//booking System APIs
static const String upcomingBookings = '/bookings/{uuid}/';
} }