Skip to content

Commit 6fa626c

Browse files
committed
start rewrite.
1 parent c8c24b3 commit 6fa626c

File tree

11 files changed

+285
-185
lines changed

11 files changed

+285
-185
lines changed

lib/models/place.dart

+34-33
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
1+
import 'package:harmony/models/review.dart';
2+
import 'package:harmony/models/user.dart';
3+
import 'package:harmony/utilites/places/place_category_enum.dart';
4+
15
import 'package:cloud_firestore/cloud_firestore.dart';
26
import 'package:geoflutterfire/geoflutterfire.dart';
3-
import 'package:harmony/utilites/places/place_category_enum.dart';
47

5-
class Place{
8+
class Place {
69
final String id;
7-
PlaceCategory category;
8-
GeoFirePoint point;
9-
String name;
10-
List<dynamic> pastUserIds;
11-
List<dynamic> reviewIds;
12-
double rating;
13-
14-
15-
Place(this.id, this.category, this.point, this.name, this.pastUserIds,
16-
this.reviewIds, this.rating);
17-
18-
///FROM DB
19-
10+
final PlaceCategory category;
11+
final GeoFirePoint point;
12+
final String name;
13+
final List<HarmonyUser> pastUsers;
14+
final List<Review> reviews;
15+
final double rating;
16+
17+
Place({
18+
required this.id,
19+
required this.category,
20+
required this.point,
21+
required this.name,
22+
required this.pastUsers,
23+
required this.reviews,
24+
required this.rating
25+
});
2026

2127
factory Place.fromJson(Map<String, dynamic> data, String id) {
22-
PlaceCategory parsePlaceCategory(String sPlaceCategory){
23-
return PlaceCategory.values.firstWhere((e) => e.toString() == sPlaceCategory); //from string to enum
24-
}
2528
GeoFirePoint parsePoint(Map<String, dynamic> point){
2629
GeoPoint geoPoint = point['geopoint'];
2730
return GeoFirePoint(geoPoint.latitude, geoPoint.longitude);
2831
}
2932

30-
//TODO
3133
return Place(
32-
id,
33-
parsePlaceCategory(data["category"] as String),
34-
parsePoint(data['point']),
35-
data["name"] as String,
36-
data["past_user_ids"] as List<dynamic>,
37-
data['review_ids'] as List<dynamic>,
38-
(data["rating"] as int).toDouble(),
34+
id: id,
35+
category: PlaceCategory.values.byName(data["category"]),
36+
point: parsePoint(data['point']),
37+
name: data["name"],
38+
pastUsers: data["pastUsers"], // TODO
39+
reviews: data["reviews"], // TODO
40+
rating: data["rating"],
3941
);
4042
}
4143

4244
Map<String, dynamic> toJson(){
4345
return {
44-
'category': category.toString(),
45-
'name': name,
46-
'point': point.data,
47-
'past_user_ids': pastUserIds,
48-
'review_ids': reviewIds,
49-
'rating': rating,
46+
"category": category.toString(),
47+
"name": name,
48+
"point": point,
49+
"pastUsers": pastUsers,
50+
"reviews": reviews,
51+
"rating": rating,
5052
};
5153
}
52-
5354
}

lib/models/user.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
33

44
import 'associative_entities/check_in.dart';
55

6-
class HarmonyUser{
6+
class HarmonyUser {
77
final String id; // Not designated by us as all other classes, comes from firestore when creating document
88
final String uid;
99
String username;//May change in profile settings etc.

lib/services/firestore.dart

+24-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:io';
22
import 'package:cloud_firestore/cloud_firestore.dart';
3+
import 'package:firebase_auth/firebase_auth.dart';
34
import 'package:firebase_storage/firebase_storage.dart';
45
import 'package:geoflutterfire/geoflutterfire.dart';
56
import 'package:harmony/models/associative_entities/check_in.dart';
@@ -15,7 +16,6 @@ import 'package:location/location.dart';
1516

1617

1718
class FireStoreService {
18-
1919
static CollectionReference users = FirebaseFirestore.instance.collection('users');
2020
static CollectionReference places = FirebaseFirestore.instance.collection('places');
2121
static CollectionReference reviews = FirebaseFirestore.instance.collection('reviews');
@@ -32,8 +32,9 @@ class FireStoreService {
3232
Future<List<Place>> getPlacesNearUser(LocationData userLocation, FilterModel filterModel) async {
3333
GeoFirePoint center = _geoFireService.createGeoPoint(userLocation.latitude!, userLocation.longitude!);
3434
String field = "point";
35-
Stream<List<DocumentSnapshot>> documentStream = _geoFireService.geo.collection(collectionRef: places).within(
36-
center: center, radius: filterModel.proximity, field: field);
35+
Stream<List<DocumentSnapshot>> documentStream = _geoFireService.geo.collection(collectionRef: places).within(
36+
center: center, radius: filterModel.proximity, field: field
37+
);
3738
return await filterNearPlacesStream(documentStream, filterModel.chosenCategories, filterModel.minimumRating);
3839
}
3940

@@ -361,45 +362,43 @@ class FireStoreService {
361362
}
362363

363364
void _updatePlacePUIDS(Place place, HarmonyUser user) { // PUIDS stands for PastUserIds,
364-
List pastUserIds = place.pastUserIds;
365-
pastUserIds.add(user.id);
365+
List<HarmonyUser> pastUsers = place.pastUsers;
366+
pastUsers.add(user);
366367

367368
places.doc(place.id).get().then(
368-
(placeDoc) {
369-
placeDoc.reference.update(
370-
{
371-
"past_user_ids": pastUserIds
372-
}
373-
);
374-
}
369+
(placeDoc) {
370+
placeDoc.reference.update({
371+
"past_user_ids": pastUserIds
372+
});
373+
}
375374
);
376375
}
377376

378-
void reviewLikedByUser(Review review, HarmonyUser user){
377+
void reviewLikedByUser(Review review, HarmonyUser user) {
379378
_handleLikeForReview(review, user);
380379
}
381380

382-
void _handleLikeForReview(Review review, HarmonyUser user){
381+
void _handleLikeForReview(Review review, HarmonyUser user) {
383382
review.like(user);
384383
_updateReview(
385-
review,
386-
{
387-
"likes": review.getLikesAsString()
388-
}
384+
review,
385+
{
386+
"likes": review.getLikesAsString()
387+
}
389388
);
390389
}
391390

392-
void _updateReview(Review review, Map<String, dynamic> fields){
391+
void _updateReview(Review review, Map<String, dynamic> fields) {
393392
reviews.doc(review.id).get().then(
394-
(reviewDoc){
395-
reviewDoc.reference.update(
396-
fields
397-
);
398-
}
393+
(reviewDoc) {
394+
reviewDoc.reference.update(
395+
fields
396+
);
397+
}
399398
);
400399
}
401400

402-
void reviewUnlikedByUser(Review review, HarmonyUser user){
401+
void reviewUnlikedByUser(Review review, HarmonyUser user) {
403402
review.unlike(user);
404403
_updateReview(
405404
review,
@@ -408,7 +407,4 @@ class FireStoreService {
408407
}
409408
);
410409
}
411-
412-
413-
414410
}

lib/utilites/page_enum.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
enum PAGE_ENUM{
2-
LOGIN_PAGE,
3-
REGISTER_PAGE,
4-
DISCOVER_PAGE,
5-
NEARBY_PAGE,
6-
ACCOUNT_PAGE,
1+
enum PageEnum{
2+
loginPage,
3+
registerPage,
4+
discoverPage,
5+
nearbyPage,
6+
accountPage,
77
}

lib/viewmodel/add_place/add_place_viewmodel.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import 'package:harmony/utilites/custom_exception.dart';
1111
import 'package:harmony/utilites/places/place_category_enum.dart';
1212
import 'package:location/location.dart';
1313

14-
class AddPlaceViewModel{
15-
14+
class AddPlaceViewModel {
1615
Future<Place> createPlace(String name, PlaceCategory category, File imageFile, double latitude, double longitude) async {
1716
FireStoreService fireStoreService = FireStoreService();
1817

@@ -38,8 +37,8 @@ class AddPlaceViewModel{
3837
Future<bool> checkIfAnyPlaceExistsNearby(LocationData locationOfPotentialData) async{
3938
GeoFirePoint point = GeoFireService().createGeoPoint(locationOfPotentialData.latitude!, locationOfPotentialData.longitude!);
4039
List<String> hashesToBeChecked = point.neighbors..add(point.hash);
41-
for(String geoHash in hashesToBeChecked){
42-
if(await FireStoreService().anyPlaceExistWithHash(geoHash)){
40+
for (String geoHash in hashesToBeChecked) {
41+
if (await FireStoreService().anyPlaceExistWithHash(geoHash)) {
4342
return true;
4443
}
4544
}

lib/views/account/account_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class AccountPage extends StatelessWidget {
140140
),
141141
),
142142
bottomNavigationBar: pushedFromSpotInfo ? const SizedBox() : HarmonyBottomNavigationBar(
143-
PAGE_ENUM.ACCOUNT_PAGE
143+
PageEnum.accountPage
144144
),
145145
),
146146
);

lib/views/discover/discover_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DiscoverPageState extends State<DiscoverPage> with FilterSheetCreator impl
4242
),
4343
),
4444
bottomNavigationBar: HarmonyBottomNavigationBar(
45-
PAGE_ENUM.DISCOVER_PAGE
45+
PageEnum.discoverPage
4646
),
4747
);
4848
}

lib/views/place/near_place.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class _NearbyPageState extends State<NearbyPage> with FilterSheetCreator impleme
4242
),
4343
),
4444
bottomNavigationBar: HarmonyBottomNavigationBar(
45-
PAGE_ENUM.NEARBY_PAGE,
45+
PageEnum.nearbyPage,
4646
),
4747
floatingActionButton: FloatingActionButton(
4848
onPressed: () {

lib/widgets/general_use/harmony_bottom_navigation_bar.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:harmony/views/discover/discover_page.dart';
77
import 'package:harmony/views/place/near_place.dart';
88

99
class HarmonyBottomNavigationBar extends StatelessWidget {
10-
final PAGE_ENUM currPage;
10+
final PageEnum currPage;
1111
final Color _activeColor = const Color(0xff00CA9D);
1212
final Color _inactiveColor = Colors.black54;
1313

@@ -27,7 +27,7 @@ class HarmonyBottomNavigationBar extends StatelessWidget {
2727
IconButton(
2828
icon: Icon(
2929
FontAwesomeIcons.compass,
30-
color: currPage == PAGE_ENUM.DISCOVER_PAGE ? _activeColor : _inactiveColor,
30+
color: currPage == PageEnum.discoverPage ? _activeColor : _inactiveColor,
3131

3232
),
3333
onPressed: () => Navigator.pushReplacement(
@@ -43,7 +43,7 @@ class HarmonyBottomNavigationBar extends StatelessWidget {
4343
icon: Icon(
4444
Icons.near_me_outlined,
4545
size: 26,
46-
color: currPage == PAGE_ENUM.NEARBY_PAGE ? _activeColor : _inactiveColor,
46+
color: currPage == PageEnum.nearbyPage ? _activeColor : _inactiveColor,
4747
),
4848
onPressed: () => Navigator.pushReplacement(
4949

@@ -58,7 +58,7 @@ class HarmonyBottomNavigationBar extends StatelessWidget {
5858
icon: Icon(
5959
FontAwesomeIcons.user,
6060
size: 22,
61-
color: currPage == PAGE_ENUM.ACCOUNT_PAGE ? _activeColor : _inactiveColor,
61+
color: currPage == PageEnum.accountPage ? _activeColor : _inactiveColor,
6262
),
6363
onPressed: () => Navigator.pushReplacement(
6464

0 commit comments

Comments
 (0)