Skip to content

Commit a2f49f8

Browse files
committed
refactor
1 parent 8468b06 commit a2f49f8

File tree

9 files changed

+278
-302
lines changed

9 files changed

+278
-302
lines changed

lib/config/api.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
/// Save any API Endpoint here
3-
const String baseHost = 'https://www.googleapis.com/books/v1/volumes';
2+
// /// Save any API Endpoint here
3+
// const String baseHost = 'https://www.googleapis.com/books/v1/volumes';

lib/screens/bookshelf.dart

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -77,45 +77,5 @@ class _LibraryPageState extends State<LibraryPage> {
7777
);
7878
}
7979

80-
// void openDialog() {
81-
// showDialog<Text>(
82-
// context: context,
83-
// builder: (BuildContext ctx) {
84-
// return AlertDialog(
85-
// actions: <Widget>[
86-
// TextButton(
87-
// onPressed: () {
88-
// Navigator.pop(context);
89-
// },
90-
// child: Text(
91-
// 'CANCEL',
92-
// style: GoogleFonts.poppins(
93-
// color: Colors.black,
94-
// fontSize: 16,
95-
// fontWeight: FontWeight.w300),
96-
// ),
97-
// ),
98-
// TextButton(
99-
// onPressed: () {
100-
// Navigator.pop(context);
101-
// },
102-
// child: Text(
103-
// 'OK',
104-
// style: GoogleFonts.poppins(
105-
// color: Colors.black,
106-
// fontSize: 16,
107-
// fontWeight: FontWeight.w300),
108-
// ),
109-
// )
110-
// ],
111-
// // ignore: sized_box_for_whitespace
112-
// content: Container(
113-
// width: 350,
114-
// height: 200,
115-
// child: FilterItems(),
116-
// ),
117-
// );
118-
// },
119-
// );
120-
// }
80+
12181
}

lib/screens/dashboard/bookcard.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BookCard extends StatelessWidget {
7878
),
7979
],
8080
)
81-
: Center(),
81+
: const Center(),
8282
);
8383
}
8484

lib/screens/explore_nearby.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class _ExploreNearbyState extends State<ExploreNearby> {
5151
lon2: element.longitude);
5252

5353
// print('Distance: $dist');
54-
if (element.uid != null) if (dist <= 3) {
54+
if (element.uid != null) if (dist <= 3 ) {
5555
// print('dist <= 3: ' + element.uid.toString());
5656
_databaseService
5757
.getBooks(uid: element.uid)

lib/services/base/base_services.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22

3-
import 'dart:convert';
3+
// import 'dart:convert';
44

5-
import 'package:http/http.dart' as http;
5+
// import 'package:http/http.dart' as http;
66

77

8-
class BaseServices {
9-
Future<Map<String, dynamic>> getAPI(String url) async {
10-
final http.Response response = await http.get(url);
11-
return jsonDecode(response.body) as Map<String, dynamic>;
12-
}
13-
}
8+
// class BaseServices {
9+
// Future<Map<String, dynamic>> getAPI(String url) async {
10+
// final http.Response response = await http.get(url);
11+
// return jsonDecode(response.body) as Map<String, dynamic>;
12+
// }
13+
// }
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11

2-
import 'package:books_app/config/api.dart';
3-
import 'package:books_app/services/base/base_services.dart';
2+
// import 'package:books_app/config/api.dart';
3+
// import 'package:books_app/services/base/base_services.dart';
44

5-
class BooksServices extends BaseServices {
5+
// class BooksServices extends BaseServices {
66

7-
Future<Map<String, dynamic>> getBooksbyISBN(String isbn) async {
8-
final Map<String, dynamic> data = await getAPI('$baseHost?q=isbn$isbn');
9-
return data;
10-
}
7+
// Future<Map<String, dynamic>> getBooksbyISBN(String isbn) async {
8+
// final Map<String, dynamic> data = await getAPI('$baseHost?q=isbn$isbn');
9+
// return data;
10+
// }
1111

12-
Future<Map<String, dynamic>> getTop() async {
13-
final Map<String, dynamic> data = await getAPI('$baseHost?q=isbn');
14-
return data;
15-
}
12+
// Future<Map<String, dynamic>> getTop() async {
13+
// final Map<String, dynamic> data = await getAPI('$baseHost?q=isbn');
14+
// return data;
15+
// }
1616

17-
Future<Map<String, dynamic>> search(String name) async {
18-
final Map<String, dynamic> data = await getAPI('$baseHost?q=$name');
19-
return data;
20-
}
17+
// Future<Map<String, dynamic>> search(String name) async {
18+
// final Map<String, dynamic> data = await getAPI('$baseHost?q=$name');
19+
// return data;
20+
// }
2121

22-
}
22+
// }

lib/services/database_service.dart

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:ffi';
2-
31
import 'package:books_app/providers/book.dart';
42
import 'package:books_app/providers/user.dart';
53
import 'package:books_app/utils/location_helper.dart';
@@ -39,37 +37,6 @@ class DatabaseService {
3937
// .map(_userDataFromSnapShot);
4038
}
4139

42-
Future<List<Book>> getBooks({String uid}) async {
43-
List<Book> res = await booksCollection
44-
.doc(uid)
45-
.collection('ownedBooks')
46-
.get()
47-
.then((QuerySnapshot value) => booksList(value));
48-
return res;
49-
}
50-
51-
List<Book> booksList(QuerySnapshot querySnapshot) {
52-
return querySnapshot.docs
53-
.map((QueryDocumentSnapshot e) => Book(
54-
title: e.data()['title'] as String,
55-
author: e.data()['author'] as String,
56-
description: e.data()['description'] as String,
57-
genre: e.data()['genre'] as String,
58-
imageUrl: e.data()['imageUrl'] as String,
59-
infoLink: e.data()['infoLink'] as String,
60-
isbn: e.data()['isbn'] as String,
61-
isBookMarked: e.data()['isBookMarked'] as bool,
62-
isBorrowed: e.data()['isBorrowed'] as bool,
63-
isLent: e.data()['isLent'] as bool,
64-
isOwned: e.data()['isOwned'] as bool,
65-
pages: e.data()['pages'] as int,
66-
rating: e.data()['rating'] as double,
67-
userid: e.data()['userid'] as String,
68-
))
69-
.toList();
70-
}
71-
72-
//Update Users Location
7340
Future<void> addBook(Book book) async {
7441
//GET BOOK FROM API or an existing List and adds to both users and books collection
7542
await userDataCollection
@@ -114,6 +81,28 @@ class DatabaseService {
11481
});
11582
}
11683

84+
List<Book> booksList(QuerySnapshot querySnapshot) {
85+
return querySnapshot.docs
86+
.map((QueryDocumentSnapshot e) => Book(
87+
title: e.data()['title'] as String,
88+
author: e.data()['author'] as String,
89+
description: e.data()['description'] as String,
90+
genre: e.data()['genre'] as String,
91+
imageUrl: e.data()['imageUrl'] as String,
92+
infoLink: e.data()['infoLink'] as String,
93+
isbn: e.data()['isbn'] as String,
94+
isBookMarked: e.data()['isBookMarked'] as bool,
95+
isBorrowed: e.data()['isBorrowed'] as bool,
96+
isLent: e.data()['isLent'] as bool,
97+
isOwned: e.data()['isOwned'] as bool,
98+
pages: e.data()['pages'] as int,
99+
rating: e.data()['rating'] as double,
100+
userid: e.data()['userid'] as String,
101+
))
102+
.toList();
103+
}
104+
105+
//Update Users Location
117106
///This is for chat TEST.
118107
//Get All users Data
119108
List<UserData> getAllUserData(QuerySnapshot querySnapshot) {
@@ -137,6 +126,15 @@ class DatabaseService {
137126
}).toList();
138127
}
139128

129+
Future<List<Book>> getBooks({String uid}) async {
130+
final List<Book> res = await booksCollection
131+
.doc(uid)
132+
.collection('ownedBooks')
133+
.get()
134+
.then((QuerySnapshot value) => booksList(value));
135+
return res;
136+
}
137+
140138
// Stream<QuerySnapshot> getMessageStream(String from, String to) {
141139
// return chatCollection
142140
// .doc(from)
@@ -198,21 +196,39 @@ class DatabaseService {
198196

199197
// final DocumentReference docReference =
200198
// booksCollection.doc(uid).collection('ownedBooks').doc(book.isbn);
201-
await userDataCollection
202-
.doc(uid)
203-
.collection('ownedBooks')
204-
.doc(book.isbn)
205-
.update(<String, bool>{
206-
'isBookMarked': book.isBookMarked,
207-
});
199+
if (book.isOwned) {
200+
await userDataCollection
201+
.doc(uid)
202+
.collection('ownedBooks')
203+
.doc(book.isbn)
204+
.update(<String, bool>{
205+
'isBookMarked': book.isBookMarked,
206+
});
208207

209-
await booksCollection
210-
.doc(uid)
211-
.collection('ownedBooks')
212-
.doc(book.isbn)
213-
.update(<String, bool>{
214-
'isBookMarked': book.isBookMarked,
215-
});
208+
await booksCollection
209+
.doc(uid)
210+
.collection('ownedBooks')
211+
.doc(book.isbn)
212+
.update(<String, bool>{
213+
'isBookMarked': book.isBookMarked,
214+
});
215+
} else {
216+
await userDataCollection
217+
.doc(uid)
218+
.collection('savedBooks')
219+
.doc(book.isbn)
220+
.update(<String, bool>{
221+
'isBookMarked': book.isBookMarked,
222+
});
223+
224+
await booksCollection
225+
.doc(uid)
226+
.collection('savedBooks')
227+
.doc(book.isbn)
228+
.update(<String, bool>{
229+
'isBookMarked': book.isBookMarked,
230+
});
231+
}
216232
}
217233

218234
Future<void> updateGenres(List<String> genres) async {

0 commit comments

Comments
 (0)