-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from fga-eps-mds/feature/193-Testes
#193 Testes
- Loading branch information
Showing
74 changed files
with
1,745 additions
and
913 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
117 changes: 117 additions & 0 deletions
117
hortum_mobile/lib/data/announcements/announcements_backend.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:hortum_mobile/globals.dart'; | ||
|
||
class AnnouncementsApi { | ||
Dio dio; | ||
List<dynamic> announcements = []; | ||
|
||
AnnouncementsApi([Dio client]) { | ||
if (client == null) | ||
this.dio = Dio(); | ||
else | ||
this.dio = client; | ||
} | ||
|
||
Future getAnnoun(String filter) async { | ||
//Trocar o IPLOCAL pelo ip de sua máquina | ||
String url; | ||
if (filter.isEmpty) | ||
url = 'http://$ip:8000/announcement/list'; | ||
else | ||
url = 'http://$ip:8000/announcement/list/${filter}'; | ||
|
||
var header = { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + actualUser.tokenAccess | ||
}; | ||
Response response = | ||
await this.dio.get(url, options: Options(headers: header)); | ||
this.announcements = response.data; | ||
manipulateData(); | ||
} | ||
|
||
Future registerAnnoun( | ||
String name, String description, double price, String category) async { | ||
//Trocar o IPLOCAL pelo ip de sua máquina | ||
String userAccessToken = actualUser.tokenAccess; | ||
String url = 'http://$ip:8000/announcement/create'; | ||
var header = { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + userAccessToken, | ||
}; | ||
|
||
String email = actualUser.email; | ||
Map params = { | ||
"email": email, | ||
"name": name, | ||
"description": description, | ||
"price": price, | ||
"type_of_product": category, | ||
}; | ||
|
||
String _body = json.encode(params); | ||
Response response = await this | ||
.dio | ||
.post(url, data: _body, options: Options(headers: header)); | ||
|
||
return response; | ||
} | ||
|
||
Future deleteAnnoun(String anuncio) async { | ||
String userAccessToken = actualUser.tokenAccess; | ||
String url = 'http://$ip:8000/announcement/update/$anuncio'; | ||
var header = { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + userAccessToken, | ||
}; | ||
|
||
Response response = | ||
await this.dio.delete(url, options: Options(headers: header)); | ||
return response.statusCode; | ||
} | ||
|
||
Future editAnnoun(String nomeOriginal, | ||
{String name, | ||
String description, | ||
double price, | ||
String category, | ||
bool inventory}) async { | ||
String url = 'http://$ip:8000/announcement/update/$nomeOriginal'; | ||
|
||
var header = { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + actualUser.tokenAccess, | ||
}; | ||
|
||
Map params = { | ||
"name": name, | ||
"description": description, | ||
"price": price, | ||
"type_of_product": category, | ||
"inventory": inventory | ||
}; | ||
params.removeWhere((key, value) => value == null); | ||
|
||
String _body = json.encode(params); | ||
|
||
var response = await dio.patch(url, | ||
data: _body, | ||
options: Options( | ||
headers: header, | ||
validateStatus: (status) { | ||
return status <= 500; | ||
}, | ||
)); | ||
return response; | ||
} | ||
|
||
manipulateData() { | ||
this.announcements.forEach((element) { | ||
element['price'] = | ||
"R\$ ${element['price'].toStringAsFixed(2).replaceFirst('.', ',')}"; | ||
element['username'] = element['username'].toString().split(" ")[0]; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.