first commit

This commit is contained in:
Sas Andy
2025-02-04 19:39:14 +07:00
commit 541d84755c
179 changed files with 9390 additions and 0 deletions

View File

@@ -0,0 +1,230 @@
import 'dart:convert';
import 'dart:io';
import 'package:dio/dio.dart';
abstract class BaseRepository {
final Dio dio;
BaseRepository({required this.dio});
Future<Map<String, dynamic>> post({
required Map<String, dynamic> param,
required String service,
String? token,
}) async {
try {
final response = await dio.post(
// Constant.baseUrl + service,
service,
data: jsonEncode(param),
options: Options(
headers: token != null
? {
HttpHeaders.contentTypeHeader: "application/json",
HttpHeaders.authorizationHeader: "Bearer $token",
}
: {
HttpHeaders.contentTypeHeader: "application/json",
},
contentType: "application/json",
),
);
if (response.statusCode != 200) {
throw BaseRepositoryException(
message: "Invalid Http Response ${response.statusCode}",
);
}
Map<String, dynamic> jsonData = jsonDecode(response.data);
if (jsonData["status"] != "OK") {
throw BaseRepositoryException(
message: jsonData["message"],
);
} else {
return jsonData;
}
} on DioError catch (e) {
if (e.type == DioErrorType.connectTimeout) {
print("Conection Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Conection Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.sendTimeout) {
print("Send Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Send Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.receiveTimeout) {
print("Get Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Get Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.response) {
print("Response Error, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Response Error, periksa koneksi anda");
} else {
print("else");
throw BaseRepositoryException(message: e.message);
}
// throw BaseRepositoryException(message: e.message);
} on SocketException catch (e) {
throw BaseRepositoryException(message: e.message);
} on BaseRepositoryException catch (e) {
throw BaseRepositoryException(message: e.message);
}
}
Future<Map<String, dynamic>> get({
required String service,
}) async {
try {
final response = await dio.get(
// Constant.baseUrl + service,
service,
);
if (response.statusCode != 200) {
throw BaseRepositoryException(
message: "Invalid Http Response ${response.statusCode}",
);
}
// print(jsonDecode(response.data));
Map<String, dynamic> jsonData = response.data;
if (jsonData["status"] != "OK") {
throw BaseRepositoryException(
message: jsonData["message"],
);
} else {
return jsonData;
}
} on DioError catch (e) {
if (e.type == DioErrorType.connectTimeout) {
print("Conection Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Conection Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.sendTimeout) {
print("Send Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Send Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.receiveTimeout) {
print("Get Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Get Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.response) {
print("Response Error, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Response Error, periksa koneksi anda");
} else {
print("else");
throw BaseRepositoryException(message: e.message);
}
} on SocketException catch (e) {
throw BaseRepositoryException(message: e.message);
} on BaseRepositoryException catch (e) {
throw BaseRepositoryException(message: e.message);
}
}
Future<Map<String, dynamic>> getBooth({
required String service,
}) async {
try {
final response = await dio.get(
// Constant.baseUrl + service,
service,
);
if (response.statusCode != 200) {
throw BaseRepositoryException(
message: "Invalid Http Response ${response.statusCode}",
);
}
// print(jsonDecode(response.data));
Map<String, dynamic> jsonData = jsonDecode(response.data);
if (jsonData["status"] != "OK") {
throw BaseRepositoryException(
message: jsonData["message"],
);
} else {
return jsonData;
}
} on DioError catch (e) {
if (e.type == DioErrorType.connectTimeout) {
print("Conection Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Conection Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.sendTimeout) {
print("Send Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Send Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.receiveTimeout) {
print("Get Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Get Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.response) {
print("Response Error, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Response Error, periksa koneksi anda");
} else {
print("else");
throw BaseRepositoryException(message: e.message);
}
} on SocketException catch (e) {
throw BaseRepositoryException(message: e.message);
} on BaseRepositoryException catch (e) {
throw BaseRepositoryException(message: e.message);
}
}
Future<Map<String, dynamic>> getService({
required String service,
}) async {
try {
final response = await dio.get(
// Constant.baseUrl + service,
service,
);
if (response.statusCode != 200) {
throw BaseRepositoryException(
message: "Invalid Http Response ${response.statusCode}",
);
}
// print(jsonDecode(response.data));
Map<String, dynamic> jsonData = jsonDecode(response.data);
if (jsonData["status"] != "OK") {
throw BaseRepositoryException(
message: jsonData["message"],
);
} else {
return jsonData;
}
} on DioError catch (e) {
if (e.type == DioErrorType.connectTimeout) {
print("Conection Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Conection Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.sendTimeout) {
print("Send Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Send Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.receiveTimeout) {
print("Get Data Timeout, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Get Data Timeout, periksa koneksi anda");
} else if (e.type == DioErrorType.response) {
print("Response Error, periksa koneksi anda");
throw BaseRepositoryException(
message: "${e.message} Response Error, periksa koneksi anda");
} else {
print("else");
throw BaseRepositoryException(message: e.message);
}
} on SocketException catch (e) {
throw BaseRepositoryException(message: e.message);
} on BaseRepositoryException catch (e) {
throw BaseRepositoryException(message: e.message);
}
}
}
class BaseRepositoryException implements Exception {
final String message;
BaseRepositoryException({
required this.message,
});
}

View File

@@ -0,0 +1,42 @@
import 'dart:convert';
import 'package:queuedisplay/model/branch_model.dart';
import 'package:queuedisplay/model/counter_model.dart';
import '../app/constant.dart';
import 'base_repository.dart';
class CounterRepository extends BaseRepository {
CounterRepository({required super.dio});
Future<List<Counter>> getData() async {
final url =
"${Constant.baseUrl}antrian/AntrianCounterDedicated/list_counter";
final resp = await getService(service: url);
// print(resp);
final List<Counter> listCounter = List.empty(growable: true);
resp['data']['records'].forEach((e) {
final model = Counter.fromJson(e);
listCounter.add(model);
});
return listCounter;
}
Future<List<BranchModel>> getBranch() async {
// https://devcpone.aplikasi.web.id/one-api/mockup/fo/antrian/AntrianByStationAndLocation/getbranch
final url =
"${Constant.baseUrl}mockup/fo/antrian/AntrianByStationAndLocation/getbranch";
print(url);
// final url = "$hostIP/one-api/training/ticketbooth/index";
final resp = await getBooth(service: url);
final List<BranchModel> listBooth = List.empty(growable: true);
resp['data']['records'].forEach((e) {
final model = BranchModel.fromJson(e);
listBooth.add(model);
});
return listBooth;
}
}

View File

@@ -0,0 +1,23 @@
import 'package:queuedisplay/model/sampling_location_model.dart';
import '../app/constant.dart';
import 'base_repository.dart';
class SamplingLocationRepository extends BaseRepository {
SamplingLocationRepository({required super.dio});
Future<List<SamplingLocation>> getData() async {
final url =
"${Constant.baseUrl}mockup/fo/antrian/AntrianByStationAndLocation/getLocationName";
final resp = await getService(service: url);
final List<SamplingLocation> listLocation = List.empty(growable: true);
// print(resp);
resp['data']['records'].forEach((e) {
final model = SamplingLocation.fromJson(e);
listLocation.add(model);
});
return listLocation;
}
}

View File

@@ -0,0 +1,44 @@
import 'package:queuedisplay/model/service_model.dart';
import '../app/constant.dart';
import '../model/display_counter_dedicated_modelv2.dart';
import 'base_repository.dart';
class ServiceRepository extends BaseRepository {
ServiceRepository({required super.dio});
Future<List<Layanan>> getData(String branchID) async {
final url =
"${Constant.baseUrl}antrian/AntrianCounterDedicated/list_counter/$branchID";
final resp = await getService(service: url);
final List<Layanan> listLayanan = List.empty(growable: true);
resp['data']['records'].forEach((e) {
final model = Layanan.fromJson(e);
listLayanan.add(model);
});
return listLayanan;
}
// get data by Counter ID
// Future<List<DisplayCounterDedicatedModel>> getDataByCounterID(List<int> arrCounterID) async {
Future<List<DisplayCounterDedicatedModelV2>> getDataByCounterID(
List<int> arrCounterID, String branchID) async {
final url =
"${Constant.baseUrl}antrian/AntrianCounterDedicated/get_antrian";
final param = {"arr_counter": arrCounterID, "branchID": branchID};
// print(param);
final resp = await post(service: url, param: param);
// print(resp);
final List<DisplayCounterDedicatedModelV2> listDisplay =
List.empty(growable: true);
resp['data'].forEach((e) {
final model = DisplayCounterDedicatedModelV2.fromJson(e);
listDisplay.add(model);
});
// DisplayCounterDedicatedModel.fromJson(resp['data']);
return listDisplay;
}
}

View File

@@ -0,0 +1,39 @@
import '../app/constant.dart';
import '../model/layanan_dokter.dart';
import 'base_repository.dart';
class ServiceRepositoryLayananDokter extends BaseRepository {
ServiceRepositoryLayananDokter({required super.dio});
Future<List<LayananDokter>> getData() async {
final url = "${Constant.baseUrl}antrian/layanandokter/list_service";
final resp = await getService(service: url);
final List<LayananDokter> listLayanan = List.empty(growable: true);
resp['data']['records'].forEach((e) {
final model = LayananDokter.fromJson(e);
listLayanan.add(model);
});
return listLayanan;
}
// get data by serviceID
// Future<List<DisplayModel>> getDataByServiceID(List<int> serviceID) async {
// Future<List<DisplayModelV2>> getDataByServiceID(List<int> serviceID) async {
// final url = "${Constant.baseUrl}antrian/layanandokter/list_layanan_dokter";
// final param = {"serviceId": serviceID};
// // print(param);
// final resp = await post(service: url, param: param);
// // print(resp);
// final List<DisplayModelV2> listDisplay = List.empty(growable: true);
// resp['data'].forEach((e) {
// final model = DisplayModelV2.fromJson(e);
// listDisplay.add(model);
// });
// return listDisplay;
// }
}