add user service and update user model for customer details retrieval
This commit is contained in:
parent
713b14ee88
commit
faf478a7b0
28
lib/api/services/customer_service.dart
Normal file
28
lib/api/services/customer_service.dart
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:kmobile/data/models/user.dart';
|
||||||
|
|
||||||
|
class UserService {
|
||||||
|
final Dio _dio;
|
||||||
|
UserService(this._dio);
|
||||||
|
|
||||||
|
Future<List<User>> getUserDetails(String customerNo) async {
|
||||||
|
try {
|
||||||
|
final response = await _dio.get('/customer/details');
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
return (response.data as List)
|
||||||
|
.map((user) => User.fromJson(user))
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
throw Exception('Failed to load customer details');
|
||||||
|
}
|
||||||
|
} on DioException catch (e) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print(e.toString());
|
||||||
|
}
|
||||||
|
throw Exception('Network error: ${e.message}');
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Unexpected error: ${e.toString()}');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,55 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
class User extends Equatable {
|
class User extends Equatable {
|
||||||
final String id;
|
|
||||||
final String username;
|
final String accountNo;
|
||||||
final String email;
|
final String accountType;
|
||||||
final String? phoneNumber;
|
final String bookingNumber;
|
||||||
|
final String branchId;
|
||||||
|
final String currency;
|
||||||
|
final String? productType;
|
||||||
|
final String? approvedAmount;
|
||||||
|
final String availableBalance;
|
||||||
|
final String currentBalance;
|
||||||
|
final String name;
|
||||||
|
final String mobileNo;
|
||||||
|
final String address;
|
||||||
|
final String picode;
|
||||||
|
|
||||||
const User({
|
const User({
|
||||||
required this.id,
|
required this.accountNo,
|
||||||
required this.username,
|
required this.accountType,
|
||||||
required this.email,
|
required this.bookingNumber,
|
||||||
this.phoneNumber,
|
required this.branchId,
|
||||||
|
required this.currency,
|
||||||
|
this.productType,
|
||||||
|
this.approvedAmount,
|
||||||
|
required this.availableBalance,
|
||||||
|
required this.currentBalance,
|
||||||
|
required this.name,
|
||||||
|
required this.mobileNo,
|
||||||
|
required this.address,
|
||||||
|
required this.picode,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory User.fromJson(Map<String, dynamic> json) {
|
factory User.fromJson(Map<String, dynamic> json) {
|
||||||
return User(
|
return User(
|
||||||
id: json['id'],
|
accountNo: json['stAccountNo'],
|
||||||
username: json['username'],
|
accountType: json['stAccountType'],
|
||||||
email: json['email'],
|
bookingNumber: json['stBookingNumber'],
|
||||||
phoneNumber: json['phone_number'],
|
branchId: json['stBranchId'],
|
||||||
|
currency: json['stCurrency'],
|
||||||
|
productType: json['stProductType'],
|
||||||
|
approvedAmount: json['stApprovedAmount'],
|
||||||
|
availableBalance: json['stAvailableBalance'],
|
||||||
|
currentBalance: json['stCurrentBalance'],
|
||||||
|
name: json['custname'],
|
||||||
|
mobileNo: json['mobileno'],
|
||||||
|
address: json['custaddress'],
|
||||||
|
picode: json['picode'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [id, username, email, phoneNumber];
|
List<Object?> get props => [accountNo, accountType, bookingNumber, branchId, currency, productType, approvedAmount, availableBalance, currentBalance, name, mobileNo, address, picode];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user