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