Skip to content

Commit

Permalink
Merge pull request #43 from fga-eps-mds/feature/193-Testes
Browse files Browse the repository at this point in the history
#193 Testes
  • Loading branch information
VitorLamego authored Apr 29, 2021
2 parents f7faeb9 + 87c4350 commit 7199eef
Show file tree
Hide file tree
Showing 74 changed files with 1,745 additions and 913 deletions.
2 changes: 1 addition & 1 deletion hortum_mobile/lib/components/productors_box.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hortum_mobile/services/codec_string.dart';
import 'package:hortum_mobile/views/productor_details/productor_details.dart';
import 'package:hortum_mobile/views/productor_details/productor_details_page.dart';

class ProductorsBox extends StatefulWidget {
final String name;
Expand Down
42 changes: 0 additions & 42 deletions hortum_mobile/lib/data/announ_data_backend.dart

This file was deleted.

15 changes: 0 additions & 15 deletions hortum_mobile/lib/data/announ_delete_backend.dart

This file was deleted.

50 changes: 0 additions & 50 deletions hortum_mobile/lib/data/announ_edit_backend.dart

This file was deleted.

30 changes: 0 additions & 30 deletions hortum_mobile/lib/data/announ_register_backend.dart

This file was deleted.

117 changes: 117 additions & 0 deletions hortum_mobile/lib/data/announcements/announcements_backend.dart
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];
});
}
}
31 changes: 24 additions & 7 deletions hortum_mobile/lib/data/login_backend.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:hortum_mobile/globals.dart';
import 'package:hortum_mobile/model/user.dart';
import 'package:http/http.dart' as http;

class LoginApi {
static Future<User> login(String email, String password) async {
Dio dio;

LoginApi([Dio client]) {
if (client == null) {
this.dio = Dio();
} else {
this.dio = client;
}
}

Future login(String email, String password) async {
//Trocar o IPLOCAL pelo ip de sua máquina
Uri url = Uri.parse('http://$ip:8000/login/');
var url = 'http://$ip:8000/login/';
var header = {"Content-Type": "application/json"};

Map params = {
Expand All @@ -15,12 +25,19 @@ class LoginApi {
};

String _body = json.encode(params);
var response = await http.post(url, headers: header, body: _body);
Map mapResponse = json.decode(response.body);
mapResponse['password'] = password;
Response response = await dio.post(
url,
data: _body,
options: Options(
headers: header,
validateStatus: (status) {
return status <= 500;
},
),
);

if (response.statusCode == 200) {
actualUser = User.fromJson(mapResponse);
actualUser = User.fromJson(response.data);
actualUser.writeSecureData('email', actualUser.email);
actualUser.writeSecureData('token_refresh', actualUser.tokenRefresh);
actualUser.writeSecureData('token_access', actualUser.tokenAccess);
Expand Down
37 changes: 27 additions & 10 deletions hortum_mobile/lib/data/register_backend.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:hortum_mobile/globals.dart';
import 'package:http/http.dart' as http;
import 'package:hortum_mobile/views/login/login_page.dart';

class RegisterApi {
static Future register(
String username, String email, String password, bool isProductor) async {
//Trocar o IPLOCAL pelo ip de sua máquina
Uri urlCustomer = Uri.parse('http://$ip:8000/signup/customer/');
Uri urlProductor = Uri.parse('http://$ip:8000/signup/productor/');
Dio dio;
RegisterApi([Dio client]) {
if (client == null)
this.dio = Dio();
else
this.dio = client;
}

Future register(String username, String email, String password,
bool isProductor, BuildContext context) async {
String urlCustomer = 'http://$ip:8000/signup/customer/';
String urlProductor = 'http://$ip:8000/signup/productor/';
Response response;

var header = {"Content-Type": "application/json"};

Map params = {
Expand All @@ -20,12 +31,18 @@ class RegisterApi {

String _body = json.encode(params);
if (isProductor == false) {
await http.post(urlCustomer, headers: header, body: _body);
response = await this
.dio
.post(urlCustomer, data: _body, options: Options(headers: header));
} else {
await http.post(urlProductor, headers: header, body: _body);
response = await dio.post(urlProductor,
data: _body, options: Options(headers: header));
}
if (response.statusCode == 201) {
Navigator.push(context, MaterialPageRoute(builder: (context) {
return LoginPage();
}));
}
// Exemplo de código para depois que a conta for criada
// if (response.statusCode == 201) {}
// else {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _ChangePasswordState extends State<ChangePasswordPage> {
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
key: Key('profileContent'),
key: Key('changePasswordContent'),
children: [
Text(
'MUDAR SENHA',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _PasswordFormState extends State<PasswordForm> {
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
key: Key('changePasswordForm'),
height: size.height * 0.6,
child: Column(
children: <Widget>[
Expand Down
Loading

0 comments on commit 7199eef

Please sign in to comment.