Fakultas Ilmu Komputer UI

Commit 0586d104 authored by Adzkia Aisyah Afrah Hardian's avatar Adzkia Aisyah Afrah Hardian
Browse files

[CHORE] connect postings to API

parent 11c27904
Pipeline #40406 passed with stages
in 5 minutes and 45 seconds
......@@ -13,17 +13,17 @@ class KomentarBloc {
Stream<NetworkModel<KomentarList>> get komentarListStream =>
_komentarListController.stream;
KomentarBloc() {
KomentarBloc(String namaLokasi) {
_komentarListController = StreamController<NetworkModel<KomentarList>>();
_komentarRepository = KomentarRepository();
fetchKomentarList();
fetchKomentarList(namaLokasi);
}
fetchKomentarList() async {
fetchKomentarList(String namaLokasi) async {
komentarListSink.add(NetworkModel.loading('Getting Komentar'));
try {
KomentarList komentarListResponse =
await _komentarRepository.fetchKomentar();
await _komentarRepository.fetchKomentar(namaLokasi);
komentarListSink.add(NetworkModel.completed(komentarListResponse));
} catch (e) {
komentarListSink.add(NetworkModel.error(e.toString()));
......
......@@ -10,13 +10,20 @@ class KomentarList {
@JsonSerializable()
class KomentarModel {
final String nama_orang;
final int suka;
final int tidak_suka;
final String foto;
final String nama_lokasi;
final String deskripsi;
final String creator;
final DateTime date_time;
final int like;
final int dislike;
final int rating;
final List<String> tag;
final String image;
final bool is_verified;
KomentarModel(
{this.nama_orang, this.suka, this.tidak_suka, this.foto});
{this.nama_lokasi, this.deskripsi, this.creator, this.date_time,
this.like, this.dislike, this.rating, this.tag, this.image, this.is_verified});
factory KomentarModel.fromJson(Map<String, dynamic> json) => _$KomentarModelFromJson(json);
......
......@@ -23,17 +23,31 @@ Map<String, dynamic> _$KomentarListToJson(KomentarList instance) =>
KomentarModel _$KomentarModelFromJson(Map<String, dynamic> json) {
return KomentarModel(
nama_orang: json['nama_orang'] as String,
suka: json['suka'] as int,
tidak_suka: json['tidak_suka'] as int,
foto: json['foto'] as String,
nama_lokasi: json['nama_lokasi'] as String,
deskripsi: json['deskripsi'] as String,
creator: json['creator'] as String,
date_time: json['date_time'] == null
? null
: DateTime.parse(json['date_time'] as String),
like: json['like'] as int,
dislike: json['dislike'] as int,
rating: json['rating'] as int,
tag: (json['tag'] as List)?.map((e) => e as String)?.toList(),
image: json['image'] as String,
is_verified: json['is_verified'] as bool,
);
}
Map<String, dynamic> _$KomentarModelToJson(KomentarModel instance) =>
<String, dynamic>{
'nama_orang': instance.nama_orang,
'suka': instance.suka,
'tidak_suka': instance.tidak_suka,
'foto': instance.foto,
'nama_lokasi': instance.nama_lokasi,
'deskripsi': instance.deskripsi,
'creator': instance.creator,
'date_time': instance.date_time?.toIso8601String(),
'like': instance.like,
'dislike': instance.dislike,
'rating': instance.rating,
'tag': instance.tag,
'image': instance.image,
'is_verified': instance.is_verified,
};
......@@ -9,12 +9,13 @@ class LokasiListResponse {
@JsonSerializable(nullable: true)
class Lokasi {
String nama;
int id;
String name;
double latitude;
double longitude;
String alamat;
String foto;
String telepon;
String image;
String no_telp;
Lokasi();
......
......@@ -22,19 +22,21 @@ Map<String, dynamic> _$LokasiListResponseToJson(LokasiListResponse instance) =>
Lokasi _$LokasiFromJson(Map<String, dynamic> json) {
return Lokasi()
..nama = json['name'] as String
..id = json['id'] as int
..name = json['name'] as String
..latitude = (json['latitude'] as num)?.toDouble()
..longitude = (json['longitude'] as num)?.toDouble()
..alamat = json['alamat'] as String
..foto = json['image'] as String
..telepon = json['no_telp'] as String;
..image = json['image'] as String
..no_telp = json['no_telp'] as String;
}
Map<String, dynamic> _$LokasiToJson(Lokasi instance) => <String, dynamic>{
'nama': instance.nama,
'id': instance.id,
'name': instance.name,
'latitude': instance.latitude,
'longitude': instance.longitude,
'alamat': instance.alamat,
'foto': instance.foto,
'telepon': instance.telepon,
'image': instance.image,
'no_telp': instance.no_telp,
};
......@@ -78,6 +78,9 @@ class NetworkInterface {
case 200:
var responseJson = json.decode(response.body.toString());
return responseJson;
case 201:
var responseJson = json.decode(response.body.toString());
return responseJson;
case 400:
throw BadRequestException(response.body.toString());
case 401:
......
......@@ -12,7 +12,8 @@ class Fasilitas extends StatefulWidget {
final String alamat;
final String url;
final String telpon;
Fasilitas({this.nama, this.alamat, this.url, this.telpon});
final int id;
Fasilitas({this.nama, this.alamat, this.url, this.telpon, this.id});
@override
_FasilitasState createState() => _FasilitasState();
}
......@@ -29,7 +30,16 @@ class _FasilitasState extends State<Fasilitas> {
var komentarRatingTertinggi = false;
var komentarTerpopuler = false;
var showUrutan = true;
final KomentarBloc _bloc = KomentarBloc();
KomentarBloc _bloc;
@override
void initState() {
print(widget.nama);
print(widget.id);
_bloc = KomentarBloc(widget.nama);
super.initState();
}
@override
Widget build(BuildContext context) {
print('widget.telpon ${widget.url}');
......@@ -87,7 +97,7 @@ class _FasilitasState extends State<Fasilitas> {
),
Flexible(
child: Text(
'08724981274',
widget.telpon,
softWrap: true,
textAlign: TextAlign.left,
style: TextStyle(
......@@ -189,21 +199,23 @@ class _FasilitasState extends State<Fasilitas> {
break;
case Status.COMPLETED:
final komentar = snapshot.data.data;
print("IN FASILITAs");
print(komentar.allKomentar[0].deskripsi);
return ListView.builder(
shrinkWrap: true,
itemCount: komentar.allKomentar.length,
itemBuilder: (BuildContext context, int index) {
return Komentar(
dislike:
komentar.allKomentar[index].tidak_suka,
komentar: 'Lorem ipsum',
like: komentar.allKomentar[index].suka,
tags: ['#toiletdisabilitas', '#kursiroda'],
komentar.allKomentar[index].dislike,
komentar: komentar.allKomentar[index].deskripsi,
like: komentar.allKomentar[index].like,
tags:komentar.allKomentar[index].tag,
urlImage: [
komentar.allKomentar[index].foto
komentar.allKomentar[index].image
],
user:
komentar.allKomentar[index].nama_orang,
komentar.allKomentar[index].creator,
);
});
break;
......
......@@ -47,7 +47,7 @@ class PencarianState extends State<Pencarian> {
for (int i = 0; i < places.length; i++) {
if (myController.text.isNotEmpty) {
if (places[i]
.nama
.name
.toLowerCase()
.contains(myController.text.toLowerCase())) {
tempList.add(places[i]);
......@@ -55,6 +55,8 @@ class PencarianState extends State<Pencarian> {
}
}
setState(() {
// print(places);
// print(places[0].nama);
currentSearch = tempList;
});
});
......@@ -202,15 +204,16 @@ class PencarianState extends State<Pencarian> {
itemCount: places.length,
itemBuilder: (context, index) {
return InkWell(
key: Key("$key-${places[index].nama}"),
key: Key("$key-${places[index].name}"),
onTap: () {
_bloc.saveRecentSearch(places[index]);
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => Fasilitas(
alamat: places[index].alamat,
nama: places[index].nama,
telpon: places[index].telepon,
nama: places[index].name,
telpon: places[index].no_telp,
url: 'http://dummyimage.com/128x141.png/ff4444/ffffff',
id: places[index].id,
)));
},
child: Container(
......@@ -236,7 +239,7 @@ class PencarianState extends State<Pencarian> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
places[index].nama,
places[index].name,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w800,
......
......@@ -4,12 +4,17 @@ import 'package:ppl_disabilitas/network/network_interface.dart';
class KomentarRepository {
NetworkInterface _network = NetworkInterface();
Future<KomentarList> fetchKomentar() async {
Future<KomentarList> fetchKomentar(String namaLokasi) async {
String nama = namaLokasi.replaceAll(" ", "%20");
String url = "http://poipole-staging.herokuapp.com/informasi-fasilitas/lokasi/list-fasilitas/" + nama;
print("in Repo");
print(url);
final response = await _network.get(
url: 'https://my.api.mockaroo.com/postingan.json?key=dbcde960',
url: url,
isLogin: false);
print(response);
final data = response.values.toList();
print(data);
return KomentarList(
response.map<KomentarModel>((komentar) => KomentarModel.fromJson(komentar)).toList());
data.map<KomentarModel>((komentar) => KomentarModel.fromJson(komentar)).toList());
}
}
Supports Markdown
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