use of com.google.cloud.firestore.DocumentSnapshot in project Protego by nickdlc.
the class ProtegoHomeController method getUser.
@GetMapping("/user")
public ProtegoUser getUser(@RequestParam("user") String uid) {
// Get user with id uid
try {
// Temporarily create a new doctor and return that
FirebaseAttributes.firestore.collection("users").document(uid).get();
// Asynchronously retrieve multiple documents
ApiFuture<DocumentSnapshot> future = FirebaseAttributes.firestore.collection("users").document(uid).get();
// future.get() blocks on response
DocumentSnapshot document = future.get();
return document.toObject(ProtegoUser.class);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
use of com.google.cloud.firestore.DocumentSnapshot in project Protego by nickdlc.
the class ProtegoHomeController method getDoctor.
@GetMapping("/doctor")
public Doctor getDoctor(@RequestParam("doctor") String duid) {
// Get doctor with id duid
try {
// Temporarily create a new doctor and return that
FirebaseAttributes.firestore.collection("users").document(duid).get();
// Asynchronously retrieve multiple documents
ApiFuture<DocumentSnapshot> future = FirebaseAttributes.firestore.collection("users").document(duid).get();
// future.get() blocks on response
DocumentSnapshot document = future.get();
return document.toObject(Doctor.class);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return null;
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method deleteNestedFieldUsingFieldPath.
@Test
public void deleteNestedFieldUsingFieldPath() throws Exception {
DocumentReference documentReference = randomColl.document("doc1");
documentReference.set(map("a.b", SINGLE_FILED_MAP_WITH_DOT)).get();
DocumentSnapshot documentSnapshots = documentReference.get().get();
assertEquals(SINGLE_FILED_MAP_WITH_DOT, documentSnapshots.getData().get("a.b"));
FieldPath path = FieldPath.of("a.b", "c.d");
documentReference.update(path, FieldValue.delete()).get();
documentSnapshots = documentReference.get().get();
assertNull(documentSnapshots.getData().get("c.d"));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method updateDocument.
@Test
public void updateDocument() throws Exception {
AllSupportedTypes expectedResult = new AllSupportedTypes();
WriteResult writeResult = randomDoc.set(ALL_SUPPORTED_TYPES_MAP).get();
DocumentSnapshot documentSnapshot = randomDoc.get().get();
assertEquals(expectedResult, documentSnapshot.toObject(AllSupportedTypes.class));
randomDoc.update(Precondition.updatedAt(writeResult.getUpdateTime()), "foo", "updated").get();
documentSnapshot = randomDoc.get().get();
expectedResult.foo = "updated";
assertEquals(expectedResult, documentSnapshot.toObject(AllSupportedTypes.class));
expectedResult.model = ImmutableMap.of("foo", UPDATE_SINGLE_FIELD_OBJECT.foo);
randomDoc.update("model", UPDATE_SINGLE_FIELD_OBJECT).get();
documentSnapshot = randomDoc.get().get();
assertEquals(expectedResult, documentSnapshot.toObject(AllSupportedTypes.class));
}
use of com.google.cloud.firestore.DocumentSnapshot in project java-firestore by googleapis.
the class ITSystemTest method writeBatch.
@Test
public void writeBatch() throws Exception {
DocumentReference createDocument = randomColl.document();
DocumentReference setDocument = randomColl.document();
DocumentReference updateDocument = addDocument("foo", "bar");
DocumentReference deleteDocument = addDocument("foo", "bar");
WriteBatch batch = firestore.batch();
batch.create(createDocument, SINGLE_FIELD_OBJECT);
batch.set(setDocument, ALL_SUPPORTED_TYPES_OBJECT);
batch.update(updateDocument, "foo", "foobar");
batch.delete(deleteDocument);
batch.commit().get();
List<DocumentSnapshot> documentSnapshots = firestore.getAll(createDocument, setDocument, updateDocument, deleteDocument).get();
Iterator<DocumentSnapshot> iterator = documentSnapshots.iterator();
assertEquals(SINGLE_FIELD_OBJECT, iterator.next().toObject(SingleField.class));
assertEquals(ALL_SUPPORTED_TYPES_OBJECT, iterator.next().toObject(AllSupportedTypes.class));
assertEquals("foobar", iterator.next().get("foo"));
assertFalse(iterator.next().exists());
}
Aggregations