123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import 'dart:convert';
- import 'package:fast_med_flutter/widgets/DataTableMySqlDemo/Horario.dart';
- import 'package:fast_med_flutter/widgets/DataTableMySqlDemo/Especialista.dart';
- import 'package:http/http.dart'
- as http;
- import 'Oficina.dart';
-
- class Services {
- static const URL_GET_ALL = 'http://ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php';
- static const URL_OFICINA_GET_BY_ID = 'https://ada.uprrp.edu/~oniel.mendez2/json/getOficinaByID.php';
- static const URL_HORARIO = 'https://ada.uprrp.edu/~oniel.mendez2/json/getHorario.php';
- static const URL_ESPECIALISTA = 'https://ada.uprrp.edu/~oniel.mendez2/json/getEspecialista.php';
- //static const _GET_ALL = "GET_ALL";
-
- //get all oficinas
- static Future<List<Oficina>> getOficinas() async {
- try {
- final response = await http.get(URL_GET_ALL);
- if (200 == response.statusCode) {
- final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
- List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
- return list;
- } else {
- final response = '[{"id":"1","name":"error."},{"id":"2","name":"el codigo"},{"id":"3","name":"!=200"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- } catch (e) {
- final response = '[{"id":"1","name":"oficina 1,"telephone":"787","address":"Carretera ##","email":"email@domain.com""},'
- '{"id":"2","name":"oficina 2","telephone":"787","address":"Carretera ##","email":"email@domain.com"},'
- '{"id":"3","name":"oficina 3","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- }
-
- static Future<List<Oficina>> getOficina(id) async {
- try {
- final response = await http.post(URL_OFICINA_GET_BY_ID, body: {'id': id});
- if (200 == response.statusCode) {
- final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
- List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
- return list;
- } else {
- final response = '[{"id":"1","name":"error.","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- } catch (e) {
- final response = '[{"id":"1","name":"oficina 1","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Oficina> list = parsed.map<Oficina>((json) => Oficina.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- }
-
- //para conseguir el horario de una oficina
- static Future<List<Horario>> getHorario(id) async {
- try {
- final response = await http.post(URL_HORARIO, body: {'id': id});
- if (200 == response.statusCode && response != null) {
- final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
- List<Horario> list = parsed.map<Horario>((json) => Horario.allFromJson(json)).toList();
- return list;
- } else {
- final response = '[{"id":"1","name":"error.","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Horario> list = parsed.map<Horario>((json) => Horario.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- } catch (e) {
- final response = '[{"id":"1","name":"oficina 1","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Horario> list = parsed.map<Horario>((json) => Horario.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- }
-
- //para conseguir especialistas que trabajen en una oficina
- static Future<List<Especialista>> getEspecialista(id) async {
- try {
- final response = await http.post(URL_ESPECIALISTA, body: {'id': id});
- if (200 == response.statusCode && response != null) {
- final parsed = json.decode(response.body).cast<Map<String, dynamic>>();
- List<Especialista> list = parsed.map<Especialista>((json) => Especialista.allFromJson(json)).toList();
- return list;
- } else {
- final response = '[{"id":"1","name":"error.","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Especialista> list = parsed.map<Especialista>((json) => Especialista.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- } catch (e) {
- final response = '[{"id":"1","name":"oficina 1","telephone":"787","address":"Carretera ##","email":"email@domain.com"}]';
- final parsed = json.decode(response).cast<Map<String, dynamic>>();
- List<Especialista> list = parsed.map<Especialista>((json) => Especialista.allFromJson(json)).toList();
- return list; // return an empty list on exception/error
- }
- }
-
- }
|