add flutter
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:ontime_merchant_flutter/data/api/api_client.dart';
|
||||
import 'package:ontime_merchant_flutter/features/auth/data/models/merchant_model.dart';
|
||||
|
||||
class MerchantAuthApi {
|
||||
MerchantAuthApi(this._client);
|
||||
final ApiClient _client;
|
||||
|
||||
Future<MerchantModel> login({
|
||||
required String noTelepon,
|
||||
required String password,
|
||||
String? fcmToken,
|
||||
}) async {
|
||||
final payload = <String, dynamic>{
|
||||
'no_telepon': noTelepon,
|
||||
'password': password,
|
||||
};
|
||||
if (fcmToken != null && fcmToken.isNotEmpty) payload['token'] = fcmToken;
|
||||
|
||||
final Response<dynamic> response =
|
||||
await _client.raw.post('Merchant/login', data: payload);
|
||||
final data = response.data is Map<String, dynamic>
|
||||
? response.data as Map<String, dynamic>
|
||||
: <String, dynamic>{};
|
||||
|
||||
if (data['message'] == 'banned') throw Exception('banned');
|
||||
if (data['code']?.toString() != '200') {
|
||||
throw Exception(data['message'] ?? 'Login failed');
|
||||
}
|
||||
|
||||
final list = data['data'] as List<dynamic>? ?? [];
|
||||
if (list.isEmpty) throw Exception('Merchant data not found');
|
||||
return MerchantModel.fromJson(list.first as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'merchant_model.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class MerchantModel {
|
||||
MerchantModel({
|
||||
required this.idMitra,
|
||||
required this.idMerchant,
|
||||
required this.teleponMitra,
|
||||
required this.tokenMerchant,
|
||||
this.namaMerchant,
|
||||
this.emailMitra,
|
||||
});
|
||||
|
||||
@JsonKey(name: 'id_mitra')
|
||||
final String idMitra;
|
||||
|
||||
@JsonKey(name: 'id_merchant')
|
||||
final String idMerchant;
|
||||
|
||||
@JsonKey(name: 'telepon_mitra')
|
||||
final String teleponMitra;
|
||||
|
||||
@JsonKey(name: 'token_merchant')
|
||||
final String tokenMerchant;
|
||||
|
||||
@JsonKey(name: 'nama_merchant')
|
||||
final String? namaMerchant;
|
||||
|
||||
@JsonKey(name: 'email_mitra')
|
||||
final String? emailMitra;
|
||||
|
||||
factory MerchantModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$MerchantModelFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$MerchantModelToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
part of 'merchant_model.dart';
|
||||
|
||||
MerchantModel _$MerchantModelFromJson(Map<String, dynamic> json) {
|
||||
return MerchantModel(
|
||||
idMitra: json['id_mitra'] as String? ?? '',
|
||||
idMerchant: json['id_merchant'] as String? ?? '',
|
||||
teleponMitra: json['telepon_mitra'] as String? ?? '',
|
||||
tokenMerchant: json['token_merchant'] as String? ?? '',
|
||||
namaMerchant: json['nama_merchant'] as String?,
|
||||
emailMitra: json['email_mitra'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$MerchantModelToJson(MerchantModel instance) =>
|
||||
<String, dynamic>{
|
||||
'id_mitra': instance.idMitra,
|
||||
'id_merchant': instance.idMerchant,
|
||||
'telepon_mitra': instance.teleponMitra,
|
||||
'token_merchant': instance.tokenMerchant,
|
||||
'nama_merchant': instance.namaMerchant,
|
||||
'email_mitra': instance.emailMitra,
|
||||
};
|
||||
Reference in New Issue
Block a user