Skip to content

Commit

Permalink
feat(cloud_firestore_odm): Add support for DateTime/Timestamp/GeoPoint (
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Jul 11, 2022
1 parent 81ec08f commit f2ea369
Show file tree
Hide file tree
Showing 13 changed files with 2,422 additions and 14 deletions.
38 changes: 35 additions & 3 deletions packages/cloud_firestore_odm/cloud_firestore_odm/example/.metadata
@@ -1,10 +1,42 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable
revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
channel: dev

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
- platform: android
create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
- platform: ios
create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
- platform: macos
create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
- platform: web
create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
- platform: windows
create_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e
base_revision: 8662e22bac54c71bc4fa5a4f37e9ee80bfd08a4e

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
@@ -1,6 +1,25 @@
targets:
$default:
builders:
cloud_firestore_odm_generator:
enabled: true
generate_for:
include:
- lib/*
- lib/**
- test_driver/integration/*
- test_driver/integration/**/*
json_serializable:
enabled: true
generate_for:
include:
- lib/*
- lib/**
- test_driver/integration/*
- test_driver/integration/**/*
options:
create_field_map: true
create_field_map: true
source_gen|combining_builder:
options:
ignore_for_file:
- 'type=lint'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,55 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cloud_firestore_odm/cloud_firestore_odm.dart';
import 'package:json_annotation/json_annotation.dart';

part 'query.g.dart';

@Collection<DateTimeQuery>('firestore-example-app/42/date-time')
final dateTimeQueryRef = DateTimeQueryCollectionReference();

@JsonSerializable()
@FirestoreDateTimeConverter()
class DateTimeQuery {
DateTimeQuery(this.time);
final DateTime time;
}

class FirestoreDateTimeConverter extends JsonConverter<DateTime, Timestamp> {
const FirestoreDateTimeConverter();
@override
DateTime fromJson(Timestamp json) => json.toDate();

@override
Timestamp toJson(DateTime object) => Timestamp.fromDate(object);
}

@Collection<TimestampQuery>('firestore-example-app/42/timestamp-time')
final timestampQueryRef = TimestampQueryCollectionReference();

@JsonSerializable()
@FirestoreTimestampConverter()
class TimestampQuery {
TimestampQuery(this.time);
final Timestamp time;
}

@Collection<GeoPointQuery>('firestore-example-app/42/geopoint-time')
final geoPointQueryRef = GeoPointQueryCollectionReference();

@JsonSerializable()
@FirestoreGeoPointConverter()
class GeoPointQuery {
GeoPointQuery(this.point);
final GeoPoint point;
}

@Collection<DocumentReferenceQuery>('firestore-example-app/42/doc-ref')
final documentReferenceRef = DocumentReferenceQueryCollectionReference();

@JsonSerializable()
@FirestoreDocumentReferenceConverter()
class DocumentReferenceQuery {
DocumentReferenceQuery(this.ref);

final DocumentReference<Map<String, dynamic>> ref;
}

0 comments on commit f2ea369

Please sign in to comment.