Skip to content

Commit

Permalink
24082021
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson-Antunes-Sampaio committed Aug 24, 2021
1 parent 52c71a6 commit 820e4b9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
15 changes: 15 additions & 0 deletions lib/controllers/apply_vaccine_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:covid_19/models/schedule_model.dart';
import 'package:covid_19/models/vaccine_model.dart';
import 'package:covid_19/repositories/vaccines_repository.dart';
import 'package:get/get.dart';

Expand All @@ -10,6 +11,13 @@ class ApplyVaccineController extends GetxController{
//RxString userApply = ''.obs;
VaccineRepository vaccineRepository = VaccineRepository();
RxList<ScheduleModel> listvaccines = <ScheduleModel>[].obs;
List<VaccinesModel> listVaccines = [];

@override
void onInit() {
super.onInit();
getAllVaccines();
}

Future<void> postUserVaccine(String cpf) async{
try {
Expand Down Expand Up @@ -47,4 +55,11 @@ class ApplyVaccineController extends GetxController{
stateApplyVaccine.value = StateApplyVaccine.SUCCESS;

}

getAllVaccines()async{
listVaccines = [];
var response = await vaccineRepository.getAllVaccines();
listVaccines.addAll(response);
print(listVaccines);
}
}
15 changes: 1 addition & 14 deletions lib/controllers/vaccine_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ import 'package:get/get.dart';

class VaccineController extends GetxController {
var repository = StockVacineRepository();
List<VaccinesModel> listVaccines = [];
List<String> vacines = [];

static VaccineController get to => Get.find();

@override
void onInit() {
super.onInit();
getAllVaccines();
}



VaccineController() {
Expand All @@ -30,12 +25,4 @@ class VaccineController extends GetxController {
});
update();
}

getAllVaccines()async{
listVaccines = [];
var response = await repository.getAllVaccines();
listVaccines.addAll(response);
print(listVaccines);
}

}
4 changes: 2 additions & 2 deletions lib/models/vaccine_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Type {
int? duration;
String? manufacturer;
int? numberOfDoses;
int? timeBetweenDoses;
String? timeBetweenDoses;

Type(
{this.duration,
Expand All @@ -51,7 +51,7 @@ class Type {
duration = json['duration'];
manufacturer = json['manufacturer'];
numberOfDoses = json['numberOfDoses'];
timeBetweenDoses = json['timeBetweenDoses'];
timeBetweenDoses = json['timeBetweenDoses'].toString();
}

Map<String, dynamic> toJson() {
Expand Down
24 changes: 0 additions & 24 deletions lib/repositories/stock_vacine_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,4 @@ class StockVacineRepository {
print('Error Insert $e');
}
}
Future<List<VaccinesModel>> getAllVaccines() async {
try {
Dio? dio = CustomDio().instance;

final storage = FlutterSecureStorage();

final token = await storage.read(key: "cookie");
dio!.options.headers["Cookie"] = token;

final response = await dio.post(API_URL + 'vaccines');

if (response.statusCode == 200) {
return (response.data as List).map<VaccinesModel>((e) {
return VaccinesModel.fromJson(e);
}).toList();

} else {
print('Error code ${response.statusCode}');
return [];
}
} catch (e) {
return Future.error(e);
}
}
}
29 changes: 28 additions & 1 deletion lib/repositories/vaccines_repository.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:covid_19/models/schedule_model.dart';
import 'package:covid_19/models/vaccine_model.dart';
import 'package:covid_19/models/vacine_card_model.dart';
import 'package:covid_19/utils/constants.dart';
import 'package:covid_19/utils/dio/custom_dio.dart';
Expand Down Expand Up @@ -54,7 +55,6 @@ class VaccineRepository {
final token = await storage.read(key: "token");
dio!.options.headers["Cookie"] = token;

print(dose);
Map<String, dynamic> map = {
"target" : cpf,
"applicationDate" : date,
Expand All @@ -72,4 +72,31 @@ class VaccineRepository {
return Future.error("error");
}
}

Future<List<VaccinesModel>> getAllVaccines() async {
try {

Dio? dio = CustomDio().instance;
final storage = FlutterSecureStorage();
final token = await storage.read(key: "token");
dio!.options.headers["Cookie"] = token;

final response = await dio.get(API_URL + 'vaccines');

print("response.data: ${response.data}");

if (response.statusCode == 200) {
return (response.data as List).map<VaccinesModel>((e) {
return VaccinesModel.fromJson(e);
}).toList();

} else {
print('Error code ${response.statusCode}');
return [];
}
} catch (e) {
return Future.error(e);
}
}

}

0 comments on commit 820e4b9

Please sign in to comment.