Commit 4ace81ac authored by qorri_di's avatar qorri_di

Consume API

- contact_api
- contact_model
- user_api
- user_model
- wa_api
- wa_model
parent 546076ec
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:medapp_eksad/model/contact_model.dart';
Future<bool> savecontact(nama, email, nohp, message) async {
final response = await http.post(
Uri.parse('http://10.3.4.231:8081/medapp/v1/api/contact/save'),
body: jsonEncode({
"nama": nama,
"email": email,
"noHp": nohp,
"message": message}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
});
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
Future<List<contact>> showcontact() async {
var response = await http
.get(Uri.parse('http://10.3.4.231:8082/medapp/v1/api/contact/get'));
var resultJson = jsonDecode(response.body)['data'];
List<contact> contactlist = await resultJson
.map<contact>((json) => contact.fromJson(json))
.toList();
return contactlist;
}
\ No newline at end of file
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:medapp_eksad/model/wa_model.dart';
Future<bool> savewa(nama, nohp) async {
final response = await http.post(
Uri.parse('http://10.3.4.231:8081/medapp/v1/api/whatapps/save'),
body: jsonEncode({
"nama": nama,
"no": nohp
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
});
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}
Future<List<dynamic>> showa() async {
var response = await http
.get(Uri.parse('http://10.3.4.231:8082/medapp/v1/api/whatapps/get'));
var resultJson = jsonDecode(response.body)['data'];
List<wa> walist = await resultJson
.map<wa>((json) => wa.fromJson(json))
.toList();
return walist;
}
\ No newline at end of file
class contact {
int? idContact;
String? namaContact;
String? emailContact;
String? noHp;
String? messageContact;
contact(
{this.idContact,
this.namaContact,
this.emailContact,
this.noHp,
this.messageContact});
contact.fromJson(Map<String, dynamic> json) {
idContact = json['idContact'];
namaContact = json['namaContact'];
emailContact = json['emailContact'];
noHp = json['noHp'];
messageContact = json['messageContact'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['idContact'] = this.idContact;
data['namaContact'] = this.namaContact;
data['emailContact'] = this.emailContact;
data['noHp'] = this.noHp;
data['messageContact'] = this.messageContact;
return data;
}
}
class user {
String? idUser;
String? namaUser;
String? emailUser;
String? noHp;
String? username;
String? password;
String? statusUser;
user(
{this.idUser,
this.namaUser,
this.emailUser,
this.noHp,
this.username,
this.password,
this.statusUser});
user.fromJson(Map<String, dynamic> json) {
idUser = json['idUser'];
namaUser = json['namaUser'];
emailUser = json['emailUser'];
noHp = json['noHp'];
username = json['username'];
password = json['password'];
statusUser = json['statusUser'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['idUser'] = this.idUser;
data['namaUser'] = this.namaUser;
data['emailUser'] = this.emailUser;
data['noHp'] = this.noHp;
data['username'] = this.username;
data['password'] = this.password;
data['statusUser'] = this.statusUser;
return data;
}
}
class wa {
int? idWa;
String? namaWa;
String? noWa;
String? statusWa;
bool? activeWa;
wa({this.idWa, this.namaWa, this.noWa, this.statusWa, this.activeWa});
wa.fromJson(Map<String, dynamic> json) {
idWa = json['idWa'];
namaWa = json['namaWa'];
noWa = json['noWa'];
statusWa = json['statusWa'];
activeWa = json['activeWa'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['idWa'] = this.idWa;
data['namaWa'] = this.namaWa;
data['noWa'] = this.noWa;
data['statusWa'] = this.statusWa;
data['activeWa'] = this.activeWa;
return data;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment