init
This commit is contained in:
commit
e833bcaec4
224 files changed
+11812
No files matched your search
@@ -0,0 +1,59 @@
|
||||
class Address {
|
||||
final int id;
|
||||
final String country;
|
||||
final String postalCode;
|
||||
final String county;
|
||||
final String province;
|
||||
final String city;
|
||||
final String street;
|
||||
final String houseNumber;
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
final bool active;
|
||||
|
||||
Address({
|
||||
required this.id,
|
||||
required this.country,
|
||||
required this.postalCode,
|
||||
required this.county,
|
||||
required this.province,
|
||||
required this.city,
|
||||
required this.street,
|
||||
required this.houseNumber,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
required this.active,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'country': country,
|
||||
'postalCode': postalCode,
|
||||
'county': county,
|
||||
'province': province,
|
||||
'city': city,
|
||||
'street': street,
|
||||
'houseNumber': houseNumber,
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'active': active,
|
||||
};
|
||||
}
|
||||
|
||||
factory Address.fromJson(Map<String, dynamic> json) {
|
||||
return Address(
|
||||
id: json['id'] as int,
|
||||
country: json['country'] as String,
|
||||
postalCode: json['postalCode'] as String,
|
||||
county: json['county'] as String,
|
||||
province: json['province'] as String,
|
||||
city: json['city'] as String,
|
||||
street: json['street'] as String,
|
||||
houseNumber: json['houseNumber'] as String,
|
||||
latitude: (json['latitude'] as num).toDouble(),
|
||||
longitude: (json['longitude'] as num).toDouble(),
|
||||
active: json['active'] as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'contact.type.dart';
|
||||
|
||||
class Contact {
|
||||
final int id;
|
||||
final ContactType contactType;
|
||||
final String value;
|
||||
final int priority;
|
||||
final String notes;
|
||||
final DateTime creationDate;
|
||||
final DateTime? updateDate;
|
||||
final bool active;
|
||||
|
||||
Contact({
|
||||
required this.id,
|
||||
required this.contactType,
|
||||
required this.value,
|
||||
required this.priority,
|
||||
required this.notes,
|
||||
required this.creationDate,
|
||||
this.updateDate,
|
||||
required this.active,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'contactType': contactType.toJson(),
|
||||
'value': value,
|
||||
'priority': priority,
|
||||
'notes': notes,
|
||||
'creationDate': creationDate.toIso8601String(),
|
||||
'updateDate': updateDate?.toIso8601String(),
|
||||
'active': active,
|
||||
};
|
||||
}
|
||||
|
||||
factory Contact.fromJson(Map<String, dynamic> json) {
|
||||
return Contact(
|
||||
id: json['id'] as int,
|
||||
contactType: ContactType.fromJson(json['contactType'] as Map<String, dynamic>),
|
||||
value: json['value'] as String,
|
||||
priority: json['priority'] as int,
|
||||
notes: json['notes'] as String,
|
||||
creationDate: DateTime.parse(json['creationDate'] as String),
|
||||
updateDate: json['updateDate'] != null ? DateTime.parse(json['updateDate'] as String) : null,
|
||||
active: json['active'] as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
class ContactType {
|
||||
final int id;
|
||||
final String type;
|
||||
final String description;
|
||||
final bool active;
|
||||
|
||||
ContactType({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.description,
|
||||
required this.active,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'description': description,
|
||||
'active': active,
|
||||
};
|
||||
}
|
||||
|
||||
factory ContactType.fromJson(Map<String, dynamic> json) {
|
||||
return ContactType(
|
||||
id: json['id'] as int,
|
||||
type: json['type'] as String,
|
||||
description: json['description'] as String,
|
||||
active: json['active'] as bool,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
class Coordinates {
|
||||
final double latitude;
|
||||
final double longitude;
|
||||
|
||||
Coordinates({
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
};
|
||||
}
|
||||
|
||||
factory Coordinates.fromJson(Map<String, dynamic> json) {
|
||||
return Coordinates(
|
||||
latitude: (json['latitude'] as num).toDouble(),
|
||||
longitude: (json['longitude'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// Importa le classi annidate
|
||||
import 'contact.dart';
|
||||
import 'vineyard.dart';
|
||||
import 'address.dart';
|
||||
|
||||
class Owner {
|
||||
final int id;
|
||||
final String? name;
|
||||
final String? surname;
|
||||
final String? companyName;
|
||||
final bool isActive;
|
||||
final DateTime creationDate;
|
||||
final String note;
|
||||
final List<Contact>? contacts;
|
||||
final List<Vineyard>? vineyards;
|
||||
final List<Address>? addresses;
|
||||
|
||||
// Costruttore con parametri nominati e 'required'
|
||||
Owner({
|
||||
required this.id,
|
||||
this.name,
|
||||
this.surname,
|
||||
this.companyName,
|
||||
required this.isActive,
|
||||
required this.creationDate,
|
||||
required this.note,
|
||||
this.contacts,
|
||||
this.vineyards,
|
||||
this.addresses,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
/// Converte l'oggetto Owner in una mappa per la serializzazione JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'surname': surname,
|
||||
'companyName': companyName,
|
||||
'isActive': isActive,
|
||||
'creationDate': creationDate.toIso8601String(),
|
||||
'note': note,
|
||||
'contacts': contacts?.map((contact) => contact.toJson()).toList(),
|
||||
'vineyards': vineyards?.map((vineyard) => vineyard.toJson()).toList(),
|
||||
'addresses': addresses?.map((address) => address.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Crea un oggetto Owner da una mappa (es. da una risposta JSON).
|
||||
factory Owner.fromJson(Map<String, dynamic> json) {
|
||||
try{
|
||||
return Owner(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
surname: json['surname'] as String,
|
||||
companyName: json['companyName'] as String,
|
||||
isActive: json['isActive'] as bool,
|
||||
creationDate: DateTime.parse(json['creationDate'] as String),
|
||||
note: json['note'] as String,
|
||||
// Mappa ogni elemento JSON in un oggetto Contact
|
||||
contacts: (json['contacts'] as List).map((i) => Contact.fromJson(i as Map<String, dynamic>)).toList(),
|
||||
// Mappa ogni elemento JSON in un oggetto Vineyard
|
||||
vineyards: (json['vineyards'] as List).map((i) => Vineyard.fromJson(i as Map<String, dynamic>)).toList(),
|
||||
// Mappa ogni elemento JSON in un oggetto Address
|
||||
addresses: (json['addresses'] as List).map((i) => Address.fromJson(i as Map<String, dynamic>)).toList(),
|
||||
);
|
||||
}
|
||||
catch (e) {
|
||||
print('Errore durante la deserializzazione dell\'oggetto Owner: $e');
|
||||
return Owner(id: 0, isActive: false, creationDate: DateTime.now(), note: ''); // Restituisce un oggetto Owner vuoto in caso di errore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
class PlantVariety {
|
||||
final int id;
|
||||
final String type;
|
||||
final String quality;
|
||||
final String name;
|
||||
final String colour;
|
||||
|
||||
PlantVariety({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.quality,
|
||||
required this.name,
|
||||
required this.colour,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'quality': quality,
|
||||
'name': name,
|
||||
'colour': colour,
|
||||
};
|
||||
}
|
||||
|
||||
factory PlantVariety.fromJson(Map<String, dynamic> json) {
|
||||
return PlantVariety(
|
||||
id: json['id'] as int,
|
||||
type: json['type'] as String,
|
||||
quality: json['quality'] as String,
|
||||
name: json['name'] as String,
|
||||
colour: json['colour'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
class Role {
|
||||
// Proprietà della classe
|
||||
final int id;
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
// Costruttore con parametri nominati e 'required'
|
||||
Role({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
/// Converte l'oggetto Role in una mappa per la serializzazione JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
|
||||
/// Crea un oggetto Role da una mappa (es. da una risposta JSON).
|
||||
factory Role.fromJson(Map<String, dynamic> json) {
|
||||
return Role(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Assumiamo che la classe VinePlant sia stata definita in un file 'vine_plant.dart'
|
||||
import 'vine.plant.dart';
|
||||
|
||||
class Row {
|
||||
final int id;
|
||||
final int vineyardId;
|
||||
final int rowNum;
|
||||
final double length;
|
||||
final List<VinePlant>? vinePlants;
|
||||
|
||||
// Costruttore con parametri nominati.
|
||||
// 'vinePlants' è opzionale perché è nullable.
|
||||
Row({
|
||||
required this.id,
|
||||
required this.vineyardId,
|
||||
required this.rowNum,
|
||||
required this.length,
|
||||
this.vinePlants,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
/// Converte l'oggetto Row in una mappa per la serializzazione JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'vineyardId': vineyardId,
|
||||
'rowNum': rowNum,
|
||||
'length': length,
|
||||
// Se la lista non è null, la converte in una lista di mappe
|
||||
'vinePlants': vinePlants?.map((plant) => plant.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Crea un oggetto Row da una mappa (es. da una risposta JSON).
|
||||
factory Row.fromJson(Map<String, dynamic> json) {
|
||||
// La lista viene creata solo se esiste e non è null nella mappa JSON
|
||||
final List<dynamic>? plantsJson = json['vinePlants'];
|
||||
final List<VinePlant>? plantsList = plantsJson != null
|
||||
? plantsJson.map((json) => VinePlant.fromJson(json as Map<String, dynamic>)).toList()
|
||||
: null;
|
||||
|
||||
return Row(
|
||||
id: json['id'] as int,
|
||||
vineyardId: json['vineyardId'] as int,
|
||||
rowNum: json['rowNum'] as int,
|
||||
length: (json['length'] as num).toDouble(),
|
||||
vinePlants: plantsList,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// Importa le classi annidate
|
||||
import 'role.dart';
|
||||
import 'owner.dart';
|
||||
|
||||
class User {
|
||||
final int? id;
|
||||
final String? username;
|
||||
final String? password;
|
||||
final Role? role;
|
||||
final bool? active;
|
||||
final List<Owner>? owners;
|
||||
|
||||
// Costruttore con parametri nominati e 'required'
|
||||
User({
|
||||
this.id,
|
||||
this.username,
|
||||
this.password,
|
||||
this.role,
|
||||
this.active,
|
||||
this.owners,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
/// Converte l'oggetto User in una mappa per la serializzazione JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
try{
|
||||
return {
|
||||
'id': id,
|
||||
'username': username,
|
||||
'password': password,
|
||||
'role': role?.toJson(), // Chiama il metodo toJson() della classe Role
|
||||
'active': active,
|
||||
'owners': owners?.map((owner) => owner.toJson()).toList(), // Converte la lista in una lista di mappe JSON
|
||||
};
|
||||
} catch (e) {
|
||||
print('Errore durante la serializzazione dell\'oggetto User: $e');
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Crea un oggetto User da una mappa (es. da una risposta JSON).
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
final Map<String, dynamic> userJson = json['user'] as Map<String, dynamic>;
|
||||
try{
|
||||
return User(
|
||||
id: userJson['id'] as int,
|
||||
username: userJson['username'] as String?,
|
||||
password: userJson['password'] as String?,
|
||||
role: Role.fromJson(userJson['role'] as Map<String, dynamic>), // Crea un oggetto Role dalla mappa annidata
|
||||
active: json['active'] as bool?,
|
||||
owners: (userJson['owners'] as List)
|
||||
.map((i) => Owner.fromJson(i as Map<String, dynamic>))
|
||||
.toList(), // Mappa ogni elemento JSON in un oggetto Owner
|
||||
);
|
||||
} catch (e) {
|
||||
print('Errore durante la deserializzazione dell\'oggetto User: $e');
|
||||
return User(); // Restituisce un oggetto User vuoto in caso di errore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Assumiamo che la classe PlantVariety sia stata definita in un file 'plant_variety.dart'
|
||||
import 'plant.variety.dart';
|
||||
|
||||
class VinePlant {
|
||||
// Proprietà della classe
|
||||
final int id;
|
||||
final int rowId;
|
||||
final int plantNumberInRow;
|
||||
final int varietyId;
|
||||
final PlantVariety variety;
|
||||
final DateTime plantingDate;
|
||||
|
||||
// Costruttore con parametri nominati
|
||||
VinePlant({
|
||||
required this.id,
|
||||
required this.rowId,
|
||||
required this.plantNumberInRow,
|
||||
required this.varietyId,
|
||||
required this.variety,
|
||||
required this.plantingDate,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
/// Converte l'oggetto VinePlant in una mappa per la serializzazione JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'rowId': rowId,
|
||||
'plantNumberInRow': plantNumberInRow,
|
||||
'varietyId': varietyId,
|
||||
'variety': variety.toJson(),
|
||||
'plantingDate': plantingDate.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Crea un oggetto VinePlant da una mappa (es. da una risposta JSON).
|
||||
factory VinePlant.fromJson(Map<String, dynamic> json) {
|
||||
return VinePlant(
|
||||
id: json['id'] as int,
|
||||
rowId: json['rowId'] as int,
|
||||
plantNumberInRow: json['plantNumberInRow'] as int,
|
||||
varietyId: json['varietyId'] as int,
|
||||
variety: PlantVariety.fromJson(json['variety'] as Map<String, dynamic>),
|
||||
plantingDate: DateTime.parse(json['plantingDate'] as String),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Assumiamo che le classi Coordinates e Row siano definite
|
||||
// in file separati
|
||||
import 'coordinates.dart';
|
||||
import 'row.dart';
|
||||
|
||||
class Vineyard {
|
||||
final int id;
|
||||
final String name;
|
||||
final String location;
|
||||
final double hectares;
|
||||
final Coordinates? coordinates;
|
||||
final DateTime creationDate;
|
||||
final List<Row>? rows;
|
||||
final Map<int, Coordinates>? area;
|
||||
|
||||
// Costruttore con parametri nominati.
|
||||
// 'rows' è opzionale perché è nullable.
|
||||
Vineyard({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.location,
|
||||
required this.hectares,
|
||||
this.coordinates,
|
||||
required this.creationDate,
|
||||
this.rows,
|
||||
this.area,
|
||||
});
|
||||
|
||||
// ---
|
||||
|
||||
/// Converte l'oggetto Vineyard in una mappa per la serializzazione JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'location': location,
|
||||
'hectares': hectares,
|
||||
'coordinates': coordinates?.toJson(),
|
||||
'creationDate': creationDate.toIso8601String(),
|
||||
// Se 'rows' non è null, lo converte in una lista di mappe JSON
|
||||
'rows': rows?.map((row) => row.toJson()).toList(),
|
||||
// Converte la mappa 'area'
|
||||
'area': area?.map((key, value) => MapEntry(key.toString(), value.toJson())),
|
||||
};
|
||||
}
|
||||
|
||||
/// Crea un oggetto Vineyard da una mappa (es. da una risposta JSON).
|
||||
factory Vineyard.fromJson(Map<String, dynamic> json) {
|
||||
try{
|
||||
// Gestione della lista di 'rows'
|
||||
final List<dynamic>? rowsJson = json['rows'];
|
||||
final List<Row>? rowsList = rowsJson?.map((json) => Row.fromJson(json as Map<String, dynamic>)).toList();
|
||||
|
||||
// Gestione della mappa 'area'
|
||||
final Map<dynamic, dynamic> areaJson = json['area'] as Map<dynamic, dynamic>;
|
||||
final Map<int, Coordinates> areaMap = areaJson.map(
|
||||
(key, value) => MapEntry(
|
||||
int.parse(key as String), // Converte la chiave da String a int
|
||||
Coordinates.fromJson(value as Map<String, dynamic>),
|
||||
),
|
||||
);
|
||||
|
||||
return Vineyard(
|
||||
id: json['id'] as int,
|
||||
name: json['name'] as String,
|
||||
location: json['location'] as String,
|
||||
hectares: (json['hectares'] as num).toDouble(),
|
||||
coordinates: null,//Coordinates.fromJson(json['coordinates'] as Map<String, dynamic>),
|
||||
creationDate: DateTime.parse(json['creationDate'] as String),
|
||||
rows: rowsList,
|
||||
area: areaMap,
|
||||
);
|
||||
} catch (e) {
|
||||
print('Errore durante la deserializzazione dell\'oggetto Vineyard: $e');
|
||||
return Vineyard(
|
||||
id: 0,
|
||||
name: '',
|
||||
location: '',
|
||||
hectares: 0.0,
|
||||
coordinates: null,
|
||||
creationDate: DateTime.now(),
|
||||
rows: [],
|
||||
area: {},
|
||||
); // Restituisce un oggetto Vineyard vuoto in caso di errore
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user