Seller Filtering

This commit is contained in:
Ashish Bailkeri
2023-02-25 22:38:44 -05:00
parent 77b5e8d0b0
commit 4424932fed

View File

@@ -9,22 +9,29 @@ class TimeRange {
TimeRange(this.startTime, this.endTime); TimeRange(this.startTime, this.endTime);
} }
class PriceRange {
int low = 0;
int high = 0;
PriceRange(this.low, this.high);
}
class Seller { class Seller {
String name = ""; String name = "";
String uid = ""; String uid = "";
String location = ""; List<String> location;
TimeRange availableTime; TimeRange availableTime;
Int64 price; int price;
Seller(this.name, this.uid, this.location, this.availableTime, this.price); Seller(this.name, this.uid, this.location, this.availableTime, this.price);
} }
class Filter { class Filter {
String? location; List<String>? locations;
Int64? price; PriceRange? price;
TimeRange? meetingTime; TimeRange? meetingTime;
Filter(this.location, this.price, this.meetingTime); Filter(this.locations, this.price, this.meetingTime);
} }
Future<List<Seller>> getSellers(Filter filter) async { Future<List<Seller>> getSellers(Filter filter) async {
@@ -32,8 +39,10 @@ Future<List<Seller>> getSellers(Filter filter) async {
List<Seller> sellers = List.empty(); List<Seller> sellers = List.empty();
final Query query = users final Query query = users
.where('location', isEqualTo: filter.location) .where('location', arrayContainsAny: filter.locations)
.where('price', isEqualTo: filter.price) .where('price',
isGreaterThanOrEqualTo: filter.price?.low,
isLessThanOrEqualTo: filter.price?.high)
.where('start-time', .where('start-time',
isGreaterThanOrEqualTo: filter.meetingTime?.startTime) isGreaterThanOrEqualTo: filter.meetingTime?.startTime)
.where('end-time', isLessThanOrEqualTo: filter.meetingTime?.endTime); .where('end-time', isLessThanOrEqualTo: filter.meetingTime?.endTime);