-
Notifications
You must be signed in to change notification settings - Fork 1
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 #25 from gohealthnow/23-implementao-de-busca-na-ba…
…rra-de-pesquisa New features
- Loading branch information
Showing
21 changed files
with
778 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
analyzer: | ||
errors: | ||
invalid_return_type_for_catch_error: ignore | ||
library_private_types_in_public_api: ignore | ||
unused_field: ignore | ||
unused_local_variable: ignore | ||
use_build_context_synchronously: ignore | ||
# include: package:flutter_lints/flutter.yaml |
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 @@ | ||
abstract class IPharmacyStockItem {} |
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,25 @@ | ||
class PharmacyStockItem { | ||
int? id; | ||
int? pharmacyId; | ||
int? productId; | ||
int? quantity; | ||
|
||
PharmacyStockItem({this.id, this.pharmacyId, this.productId, this.quantity}); | ||
|
||
PharmacyStockItem.fromJson(Map<String, dynamic> json) { | ||
id = json['id']; | ||
pharmacyId = json['pharmacyId']; | ||
productId = json['productId']; | ||
quantity = json['quantity']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['id'] = this.id; | ||
data['pharmacyId'] = this.pharmacyId; | ||
data['productId'] = this.productId; | ||
data['quantity'] = this.quantity; | ||
return data; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,56 +1,167 @@ | ||
import 'package:gohealth/api/models/pharmacy_to_product_model.dart'; | ||
import 'package:gohealth/api/models/user_models.dart'; | ||
|
||
class ProductModels { | ||
int? id; | ||
String? name; | ||
String? description; | ||
double? price; | ||
int? stock; | ||
String? image; | ||
double? weight; | ||
double? dimensions; | ||
double? rating; | ||
String? createdAt; | ||
String? updatedAt; | ||
List<UserModels>? user; | ||
List<PharmacyStockItem>? pharmacyProduct; | ||
List<Review>? reviews; | ||
List<String>? categories; | ||
|
||
ProductModels( | ||
{this.id, | ||
this.name, | ||
this.description, | ||
this.price, | ||
this.stock, | ||
this.image, | ||
this.weight, | ||
this.dimensions, | ||
this.rating, | ||
this.createdAt, | ||
this.updatedAt}); | ||
|
||
ProductModels.fromJson(Map<String, dynamic> json) { | ||
id = json['id']; | ||
name = json['name']; | ||
description = json['description']; | ||
price = json['price']; | ||
stock = json['stock']; | ||
image = json['image']; | ||
weight = json['weight']; | ||
dimensions = json['dimensions']; | ||
rating = json['rating']; | ||
createdAt = json['createdAt']; | ||
updatedAt = json['updatedAt']; | ||
this.updatedAt, | ||
this.user, | ||
this.pharmacyProduct, | ||
this.reviews, | ||
this.categories}); | ||
|
||
factory ProductModels.fromJson(Map<String, dynamic> json) { | ||
return ProductModels( | ||
id: json['id'], | ||
name: json['name'], | ||
description: json['description'], | ||
price: json['price'], | ||
image: json['image'], | ||
weight: json['weight'], | ||
dimensions: json['dimensions'], | ||
rating: json['rating'], | ||
createdAt: json['createdAt'], | ||
updatedAt: json['updatedAt'], | ||
categories: json['categories'] != null | ||
? (json['categories'] as List).map((i) => i.toString()).toList() | ||
: null, | ||
user: json['user'] != null | ||
? (json['user'] as List).map((i) => UserModels.fromJson(i)).toList() | ||
: null, | ||
pharmacyProduct: json['PharmacyProduct'] != null | ||
? (json['PharmacyProduct'] as List) | ||
.map((i) => PharmacyStockItem.fromJson(i)) | ||
.toList() | ||
: null, | ||
reviews: json['review'] != null | ||
? (json['review'] as List).map((i) => Review.fromJson(i)).toList() | ||
: null, | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'id': id, | ||
'name': name, | ||
'description': description, | ||
'price': price, | ||
'image': image, | ||
'weight': weight, | ||
'dimensions': dimensions, | ||
'rating': rating, | ||
'createdAt': createdAt, | ||
'updatedAt': updatedAt, | ||
'user': user?.map((v) => v.toJson()).toList(), | ||
'PharmacyProduct': pharmacyProduct?.map((v) => v.toJson()).toList(), | ||
'review': reviews?.map((v) => v.toJson()).toList(), | ||
}; | ||
} | ||
} | ||
|
||
class Order { | ||
String id; | ||
int userId; | ||
int productId; | ||
int quantity; | ||
DateTime createdAt; | ||
DateTime updatedAt; | ||
ProductModels product; | ||
UserModels user; | ||
|
||
Order({ | ||
required this.id, | ||
required this.userId, | ||
required this.productId, | ||
required this.quantity, | ||
required this.createdAt, | ||
required this.updatedAt, | ||
required this.product, | ||
required this.user, | ||
}); | ||
|
||
factory Order.fromJson(Map<String, dynamic> json) { | ||
return Order( | ||
id: json['id'], | ||
userId: json['userId'], | ||
productId: json['productId'], | ||
quantity: json['quantity'], | ||
createdAt: DateTime.parse(json['createdAt']), | ||
updatedAt: DateTime.parse(json['updatedAt']), | ||
product: ProductModels.fromJson(json['product']), | ||
user: UserModels.fromJson(json['user']), | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'id': id, | ||
'userId': userId, | ||
'productId': productId, | ||
'quantity': quantity, | ||
'createdAt': createdAt.toIso8601String(), | ||
'updatedAt': updatedAt.toIso8601String(), | ||
'product': product.toJson(), | ||
'user': user.toJson(), | ||
}; | ||
} | ||
} | ||
|
||
class Review { | ||
int id; | ||
DateTime createdAt; | ||
DateTime updatedAt; | ||
String title; | ||
String body; | ||
double rating; | ||
|
||
Review({ | ||
required this.id, | ||
required this.createdAt, | ||
required this.updatedAt, | ||
required this.title, | ||
required this.body, | ||
required this.rating, | ||
}); | ||
|
||
Review.fromJson(Map<String, dynamic> json) | ||
: id = json['id'], | ||
createdAt = DateTime.parse(json['createdAt']), | ||
updatedAt = DateTime.parse(json['updatedAt']), | ||
title = json['title'], | ||
body = json['body'], | ||
rating = json['rating']; | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data['id'] = id; | ||
data['name'] = name; | ||
data['description'] = description; | ||
data['price'] = price; | ||
data['stock'] = stock; | ||
data['image'] = image; | ||
data['weight'] = weight; | ||
data['dimensions'] = dimensions; | ||
data['rating'] = rating; | ||
data['createdAt'] = createdAt; | ||
data['updatedAt'] = updatedAt; | ||
return data; | ||
return { | ||
'id': id, | ||
'createdAt': createdAt.toIso8601String(), | ||
'updatedAt': updatedAt.toIso8601String(), | ||
'title': title, | ||
'body': body, | ||
'rating': rating, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,48 +1,76 @@ | ||
import 'package:gohealth/api/models/product_models.dart'; | ||
|
||
class UserModels { | ||
int? id; | ||
String? createdAt; | ||
String? updatedAt; | ||
DateTime? createdAt; | ||
DateTime? updatedAt; | ||
String? email; | ||
String? password; | ||
String? name; | ||
String? avatar; | ||
Map? product; | ||
String? bio; | ||
String? role; | ||
Role? role; | ||
List<ProductModels>? products; | ||
List<Review>? reviews; | ||
List<Order>? orders; | ||
|
||
UserModels({ | ||
this.id, | ||
this.createdAt, | ||
this.updatedAt, | ||
this.email, | ||
this.password, | ||
this.name, | ||
this.role, | ||
this.avatar, | ||
this.product, | ||
this.bio, | ||
this.role, | ||
this.products, | ||
this.reviews, | ||
this.orders, | ||
}); | ||
|
||
UserModels.fromJson(Map<String, dynamic> json) | ||
: id = json['id'], | ||
createdAt = json['createdAt'], | ||
updatedAt = json['updatedAt'], | ||
email = json['email'], | ||
name = json['name'], | ||
avatar = json['avatar'], | ||
product = json['product'], | ||
bio = json['bio'], | ||
role = json['role']; | ||
factory UserModels.fromJson(Map<String, dynamic> json) { | ||
return UserModels( | ||
id: json['id'], | ||
createdAt: DateTime.parse(json['createdAt']), | ||
updatedAt: DateTime.parse(json['updatedAt']), | ||
email: json['email'], | ||
password: json['password'], | ||
name: json['name'], | ||
avatar: json['avatar'], | ||
bio: json['bio'], | ||
role: | ||
Role.values.firstWhere((e) => e.toString() == 'Role.' + json['role']), | ||
products: json['products'] != null | ||
? (json['products'] as List) | ||
.map((i) => ProductModels.fromJson(i)) | ||
.toList() | ||
: null, | ||
reviews: json['reviews'] != null | ||
? (json['reviews'] as List).map((i) => Review.fromJson(i)).toList() | ||
: null, | ||
orders: json['orders'] != null | ||
? (json['orders'] as List).map((i) => Order.fromJson(i)).toList() | ||
: null, | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data['id'] = id; | ||
data['createdAt'] = createdAt; | ||
data['updatedAt'] = updatedAt; | ||
data['email'] = email; | ||
data['name'] = name; | ||
data['avatar'] = avatar; | ||
data['product'] = product; | ||
data['bio'] = bio; | ||
data['role'] = role; | ||
return data; | ||
return { | ||
'id': id, | ||
'createdAt': createdAt?.toIso8601String(), | ||
'updatedAt': updatedAt?.toIso8601String(), | ||
'email': email, | ||
'password': password, | ||
'name': name, | ||
'avatar': avatar, | ||
'bio': bio, | ||
'role': role.toString().split('.').last, | ||
'products': products?.map((i) => i.toJson()).toList(), | ||
'reviews': reviews?.map((i) => i.toJson()).toList(), | ||
'orders': orders?.map((i) => i.toJson()).toList(), | ||
}; | ||
} | ||
} | ||
|
||
enum Role { USER, ADMIN } |
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,22 @@ | ||
import 'package:gohealth/api/interfaces/pharmacy_to_product.dart'; | ||
import 'package:gohealth/api/services/http_client.dart'; | ||
|
||
class PharmacyUserRepository implements IPharmacyStockItem { | ||
late HttpClient stockItemHttpClient; | ||
|
||
PharmacyUserRepository() { | ||
stockItemHttpClient = HttpClient(); | ||
} | ||
|
||
getAvailableQuantity(int pharmacy, int product) async { | ||
var response = | ||
await stockItemHttpClient.client.get('/stock/$pharmacy/$product'); | ||
|
||
if (response.statusCode == 200) { | ||
var data = response.data; | ||
return data['availableQuantity']['quantity']; | ||
} else { | ||
return 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
Oops, something went wrong.