Fakultas Ilmu Komputer UI

LokasiRepository.dart 1.17 KB
Newer Older
1
2
import 'dart:convert';

3
import 'package:ppl_disabilitas/model/lokasi.dart';
4
import 'package:ppl_disabilitas/network/cookies_interface.dart';
5
6
7
8
9
10
import 'package:ppl_disabilitas/network/network_interface.dart';

class LokasiRepository {
  NetworkInterface _network = NetworkInterface();

  Future<LokasiListResponse> fetchLokasi() async {
11
12
13
    final response = await _network.get(
        url: 'https://my.api.mockaroo.com/mall.json?key=dbcde960',
        isLogin: false);
14
15
16
    return LokasiListResponse.fromJson(response);
  }

17
18
  Future<LokasiListResponse> fetchRecentSearch() async {
    var response;
19
20
    await CookiesInterface().checkCookieFileAvailability(fileName: "searchhistory").then((boolean) async {
      if (!boolean) {
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        response = [];
      } else {
        await CookiesInterface().getCookieFile(fileName: "searchhistory").then((cookie) {
          response = json.decode(cookie);
        });
      }
    });
    return LokasiListResponse.fromJson(response);
  }

  Future<void> saveRecentSearch(Lokasi recentSearch) async {
    Map<String, dynamic> searchToMap = recentSearch.toJson();
    await CookiesInterface()
        .createSearchHistoryCookie(recentSearch: searchToMap);
  }
}