This commit is contained in:
Felipe
2024-03-13 13:59:33 -05:00
parent 312cc3d863
commit a25bc6a987
26 changed files with 684 additions and 60 deletions
@@ -1,36 +0,0 @@
import 'package:equatable/equatable.dart';
class CityEntity extends Equatable {
final String name;
final String coords;
const CityEntity({
required this.name,
required this.coords,
});
Map<String, Object?> toDocument() {
return {
'name': name,
'coords': coords,
};
}
static CityEntity fromDocument(Map<String, dynamic> doc) {
return CityEntity(
name: doc['name'] as String,
coords: doc['coords'] as String,
);
}
@override
List<Object?> get props => [name, coords];
@override
String toString() {
return '''CityEntity {
name: $name
coords: $coords
}''';
}
}
@@ -1,39 +0,0 @@
import 'package:equatable/equatable.dart';
import 'package:user_repository/user_repository.dart';
class CountryEntity extends Equatable {
final String name;
final List<RegionEntity> regions;
const CountryEntity({
required this.name,
required this.regions,
});
Map<String, Object?> toDocument() {
return {
'name': name,
'regions': regions,
};
}
static CountryEntity fromDocument(Map<String, dynamic> doc) {
return CountryEntity(
name: doc['name'] as String,
regions: (doc['regions'] as List)
.map((region) => RegionEntity.fromDocument(region))
.toList(),
);
}
@override
List<Object?> get props => [name, regions];
@override
String toString() {
return '''CountryEntity {
name: $name
regions: $regions
}''';
}
}
@@ -1,4 +1 @@
export 'my_user_entity.dart';
export 'country_entity.dart';
export 'region_entity.dart';
export 'city_entity.dart';
@@ -1,39 +0,0 @@
import 'package:equatable/equatable.dart';
import 'package:user_repository/user_repository.dart';
class RegionEntity extends Equatable {
final String name;
final List<CityEntity> cities;
const RegionEntity({
required this.name,
required this.cities,
});
Map<String, Object?> toDocument() {
return {
'name': name,
'cities': cities,
};
}
static RegionEntity fromDocument(Map<String, dynamic> doc) {
return RegionEntity(
name: doc['name'] as String,
cities: (doc['cities'] as List)
.map((city) => CityEntity.fromDocument(city))
.toList(),
);
}
@override
List<Object?> get props => [name, cities];
@override
String toString() {
return '''RegionEntity {
name: $name
cities: $cities
}''';
}
}
@@ -1,46 +0,0 @@
import 'package:equatable/equatable.dart';
import '../entities/entities.dart';
class City extends Equatable {
final String name;
final String coords;
const City({
required this.name,
required this.coords,
});
static const empty = City(name: '', coords: '');
City copyWith({
String? name,
String? coords,
}) {
return City(
name: name ?? this.name,
coords: coords ?? this.coords,
);
}
bool get isEmpty => this == City.empty;
bool get isNotEmpty => this != City.empty;
City toEntity() {
return City(
name: name,
coords: coords,
);
}
static City fromEntity(CityEntity entity) {
return City(
name: entity.name,
coords: entity.coords,
);
}
@override
List<Object?> get props => [name, coords];
}
@@ -1,42 +0,0 @@
import 'package:equatable/equatable.dart';
import 'package:user_repository/user_repository.dart';
class Country extends Equatable {
final String name;
final List<Region> regions;
const Country({
required this.name,
required this.regions,
});
static const empty = Country(name: '', regions: []);
Country copyWith({
String? name,
List<Region>? regions,
}) {
return Country(
name: name ?? this.name,
regions: regions ?? this.regions,
);
}
bool get isEmpty => this == Country.empty;
bool get isNotEmpty => this != Country.empty;
Country toEntity() {
return Country(name: name, regions: regions);
}
static Country fromEntity(CountryEntity entity) {
return Country(
name: entity.name,
regions:
entity.regions.map((region) => Region.fromEntity(region)).toList(),
);
}
@override
List<Object?> get props => [name, regions];
}
@@ -1,4 +1 @@
export 'my_user.dart';
export 'country.dart';
export 'region.dart';
export 'city.dart';
export 'my_user.dart';
@@ -1,41 +0,0 @@
import 'package:equatable/equatable.dart';
import 'package:user_repository/user_repository.dart';
class Region extends Equatable {
final String name;
final List<City> cities;
const Region({
required this.name,
required this.cities,
});
static const empty = Region(name: '', cities: []);
Region copyWith({
String? name,
List<City>? cities,
}) {
return Region(
name: name ?? this.name,
cities: cities ?? this.cities,
);
}
bool get isEmpty => this == Region.empty;
bool get isNotEmpty => this != Region.empty;
Region toEntity() {
return Region(name: name, cities: cities);
}
static Region fromEntity(RegionEntity entity) {
return Region(
name: entity.name,
cities: entity.cities.map((city) => City.fromEntity(city)).toList(),
);
}
@override
List<Object?> get props => [name, cities];
}
@@ -1 +0,0 @@
abstract class CityRepository {}
@@ -1,7 +0,0 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'city_repo.dart';
class FirebaseCityRepository implements CityRepository {
final usersCollection = FirebaseFirestore.instance.collection('users');
}