Skip to content

Commit

Permalink
incomplete things
Browse files Browse the repository at this point in the history
  • Loading branch information
AshutoshPatole committed Nov 24, 2021
1 parent f5a8138 commit 8a9a41b
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions lib/core/services/firebase/user_services.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:zerosandones/core/logger.dart';

Expand All @@ -27,20 +26,38 @@ class UserService {
required String itemName}) async {
try {
if (_auth.currentUser?.uid != null) {
CollectionReference collectionReference = database
.collection("users")
.doc(_auth.currentUser?.uid)
.collection("cart");
String docId = collectionReference.doc().id;
await collectionReference.doc(docId).set({
"itemId": itemId,
"price": price,
"itemPhoto": itemPhoto,
"quantity": quantity,
"id": docId,
"itemName": itemName,
});
return true;
var existsDoc = await database
.collection("users/${_auth.currentUser?.uid}/cart")
.where(
'itemId',
isEqualTo: itemId,
)
.get();
if (existsDoc.docs[0].exists) {
var docId = existsDoc.docs[0].reference.id;
CollectionReference updateRef = database
.collection("users")
.doc(_auth.currentUser?.uid)
.collection("cart");
// await updateRef.doc(docId).update({
// 'quantity': // ! TODO Incomplete
// });
} else {
CollectionReference addRef = database
.collection("users")
.doc(_auth.currentUser?.uid)
.collection("cart");
String docId = addRef.doc().id;
await addRef.doc(docId).set({
"itemId": itemId,
"price": price,
"itemPhoto": itemPhoto,
"quantity": quantity,
"id": docId,
"itemName": itemName,
});
return true;
}
} else {
log.e("could not add product $itemId - $price");
return false;
Expand Down

0 comments on commit 8a9a41b

Please sign in to comment.