Refactor database layer: convert to DatabaseProvider class with initialization
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
class Geoposition {
|
||||
final int id;
|
||||
final int userId;
|
||||
final double xValue;
|
||||
final double yValue;
|
||||
final DateTime datetime;
|
||||
final Duration lifetime;
|
||||
final DateTime expiresAt;
|
||||
|
||||
Geoposition({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
required this.xValue,
|
||||
required this.yValue,
|
||||
required this.datetime,
|
||||
required this.lifetime,
|
||||
required this.expiresAt,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'x': xValue,
|
||||
'y': yValue,
|
||||
'datetime': datetime.toIso8601String(),
|
||||
'remainingSeconds': expiresAt.difference(DateTime.now()).inSeconds,
|
||||
};
|
||||
}
|
||||
|
||||
factory Geoposition.fromMap(Map<String, dynamic> map) {
|
||||
return Geoposition(
|
||||
id: map['id'],
|
||||
userId: map['user_id'],
|
||||
xValue: map['x_value'].toDouble(),
|
||||
yValue: map['y_value'].toDouble(),
|
||||
datetime: map['datetime'] as DateTime,
|
||||
lifetime: Duration(seconds: map['lifetime']),
|
||||
expiresAt: map['expires_at'] as DateTime,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
class Log {
|
||||
final int id;
|
||||
final String username;
|
||||
final String action;
|
||||
final DateTime datetime;
|
||||
|
||||
Log({
|
||||
required this.id,
|
||||
required this.username,
|
||||
required this.action,
|
||||
required this.datetime,
|
||||
});
|
||||
|
||||
factory Log.fromMap(Map<String, dynamic> map) {
|
||||
return Log(
|
||||
id: map['id'],
|
||||
username: map['username'],
|
||||
action: map['action'],
|
||||
datetime: map['datetime'] as DateTime,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
class User {
|
||||
final int id;
|
||||
final String login;
|
||||
final String pwdHash;
|
||||
|
||||
User({
|
||||
required this.id,
|
||||
required this.login,
|
||||
required this.pwdHash,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'login': login,
|
||||
};
|
||||
}
|
||||
|
||||
factory User.fromMap(Map<String, dynamic> map) {
|
||||
return User(
|
||||
id: map['id'],
|
||||
login: map['login'],
|
||||
pwdHash: map['pwd_hash'],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user