source_gen
This commit is contained in:
parent
4ad42ae682
commit
3c8cab050e
6 changed files with 40 additions and 22 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,6 +2,9 @@
|
|||
### Dart template
|
||||
# See https://www.dartlang.org/tools/private-files.html
|
||||
|
||||
# source_gen
|
||||
*.g.dart
|
||||
|
||||
# Files and directories created by pub
|
||||
.buildlog
|
||||
.packages
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
library angel.models.user;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:angel_mongo/model.dart';
|
||||
import 'package:source_gen/generators/json_serializable.dart';
|
||||
|
||||
class User extends Model {
|
||||
part 'user.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class User extends Model with _$UserSerializerMixin {
|
||||
@JsonKey('email')
|
||||
String email;
|
||||
|
||||
@JsonKey('username')
|
||||
String username;
|
||||
|
||||
@JsonKey('password')
|
||||
String password;
|
||||
|
||||
@JsonKey('roles')
|
||||
final List<String> roles = [];
|
||||
|
||||
factory User.fromJson(Map json) => _$UserFromJson(json);
|
||||
|
||||
User(
|
||||
{String id,
|
||||
this.email,
|
||||
|
@ -16,28 +28,9 @@ class User extends Model {
|
|||
this.password,
|
||||
List<String> roles: const []}) {
|
||||
this.id = id;
|
||||
|
||||
|
||||
if (roles != null) {
|
||||
this.roles.addAll(roles);
|
||||
}
|
||||
}
|
||||
|
||||
factory User.fromJson(String json) => new User.fromMap(JSON.decode(json));
|
||||
|
||||
factory User.fromMap(Map data) => new User(
|
||||
id: data['id'],
|
||||
email: data['email'],
|
||||
username: data['username'],
|
||||
password: data['password'],
|
||||
roles: data['roles']);
|
||||
|
||||
Map toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'email': email,
|
||||
'username': username,
|
||||
'password': password,
|
||||
'roles': roles
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,10 @@ dependencies:
|
|||
mailer: ^1.1.0+4
|
||||
validate: ^1.5.2
|
||||
dev_dependencies:
|
||||
build_runner: ^0.1.1
|
||||
grinder: ^0.8.0+2
|
||||
http: ^0.11.3
|
||||
source_gen: ^0.5.2
|
||||
test: ^0.12.13
|
||||
transformers:
|
||||
- angel_configuration
|
||||
|
|
4
tool/build.dart
Normal file
4
tool/build.dart
Normal file
|
@ -0,0 +1,4 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'phases.dart';
|
||||
|
||||
main() => build(PHASES, deleteFilesByDefault: true);
|
12
tool/phases.dart
Normal file
12
tool/phases.dart
Normal file
|
@ -0,0 +1,12 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'package:source_gen/builder.dart';
|
||||
import 'package:source_gen/generators/json_serializable_generator.dart';
|
||||
|
||||
final PhaseGroup PHASES = new PhaseGroup.singleAction(
|
||||
new GeneratorBuilder(const [const JsonSerializableGenerator()]),
|
||||
new InputSet('angel', const [
|
||||
'bin/**/*.dart',
|
||||
'lib/**/*.dart',
|
||||
'views/**/*.dart',
|
||||
'web/**/*.dart'
|
||||
]));
|
4
tool/watch.dart
Normal file
4
tool/watch.dart
Normal file
|
@ -0,0 +1,4 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'phases.dart';
|
||||
|
||||
main() => watch(PHASES, deleteFilesByDefault: true);
|
Loading…
Reference in a new issue