This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
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 #1 from Superformula/scaffolding
- Loading branch information
Showing
8 changed files
with
504 additions
and
57 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'restaurant.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Category { | ||
final String alias; | ||
final String title; | ||
|
||
Category({ | ||
this.alias, | ||
this.title, | ||
}); | ||
|
||
factory Category.fromJson(Map<String, dynamic> json) => | ||
_$CategoryFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$CategoryToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class Hours { | ||
@JsonKey(name: 'is_open_now') | ||
final bool isOpenNow; | ||
|
||
const Hours({ | ||
this.isOpenNow, | ||
}); | ||
|
||
factory Hours.fromJson(Map<String, dynamic> json) => _$HoursFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$HoursToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class User { | ||
final String id; | ||
@JsonKey(name: 'image_url') | ||
final String imageUrl; | ||
final String name; | ||
|
||
const User({ | ||
this.id, | ||
this.imageUrl, | ||
this.name, | ||
}); | ||
|
||
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$UserToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class Review { | ||
final String id; | ||
final int rating; | ||
final User user; | ||
|
||
const Review({ | ||
this.id, | ||
this.rating, | ||
this.user, | ||
}); | ||
|
||
factory Review.fromJson(Map<String, dynamic> json) => _$ReviewFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ReviewToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class Location { | ||
@JsonKey(name: 'formatted_address') | ||
final String formattedAddress; | ||
|
||
Location({ | ||
this.formattedAddress, | ||
}); | ||
|
||
factory Location.fromJson(Map<String, dynamic> json) => | ||
_$LocationFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$LocationToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class Restaurant { | ||
final String id; | ||
final String name; | ||
final String price; | ||
final double rating; | ||
@JsonKey(name: 'review_count') | ||
final int reviewCount; | ||
final List<String> photos; | ||
final List<Category> categories; | ||
final List<Hours> hours; | ||
final List<Review> reviews; | ||
final Location location; | ||
|
||
const Restaurant({ | ||
this.id, | ||
this.name, | ||
this.price, | ||
this.rating, | ||
this.reviewCount, | ||
this.photos, | ||
this.categories, | ||
this.hours, | ||
this.reviews, | ||
this.location, | ||
}); | ||
|
||
factory Restaurant.fromJson(Map<String, dynamic> json) => | ||
_$RestaurantFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$RestaurantToJson(this); | ||
|
||
/// Use the first category for the category shown to the user | ||
String get displayCategory => | ||
categories?.isNotEmpty ?? false ? categories.first.title : ''; | ||
|
||
/// Use the first image as the image shown to the user | ||
String get heroImage => photos?.isNotEmpty ?? false ? photos.first : null; | ||
|
||
/// This logic is probably not correct in all cases but it is ok | ||
/// for this application | ||
bool get isOpen => hours?.isNotEmpty ?? false ? hours.first.isOpenNow : null; | ||
} | ||
|
||
@JsonSerializable() | ||
class RestaurantQueryResult { | ||
final int total; | ||
@JsonKey(name: 'business') | ||
final List<Restaurant> restaurants; | ||
|
||
const RestaurantQueryResult({ | ||
this.total, | ||
this.restaurants, | ||
}); | ||
|
||
factory RestaurantQueryResult.fromJson(Map<String, dynamic> json) => | ||
_$RestaurantQueryResultFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$RestaurantQueryResultToJson(this); | ||
} |
Oops, something went wrong.