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';
|
||||
|
||||
class User extends Equatable {
|
||||
final String id;
|
||||
final String username;
|
||||
final String email;
|
||||
final String? phoneNumber;
|
||||
|
||||
final String accountNo;
|
||||
final String accountType;
|
||||
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({
|
||||
required this.id,
|
||||
required this.username,
|
||||
required this.email,
|
||||
this.phoneNumber,
|
||||
required this.accountNo,
|
||||
required this.accountType,
|
||||
required this.bookingNumber,
|
||||
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) {
|
||||
return User(
|
||||
id: json['id'],
|
||||
username: json['username'],
|
||||
email: json['email'],
|
||||
phoneNumber: json['phone_number'],
|
||||
accountNo: json['stAccountNo'],
|
||||
accountType: json['stAccountType'],
|
||||
bookingNumber: json['stBookingNumber'],
|
||||
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
|
||||
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