Compare commits
38 commits
master
...
v7/angel3-
Author | SHA1 | Date | |
---|---|---|---|
|
4f6c6caeb2 | ||
|
4839e2cef5 | ||
|
5ac098e3f5 | ||
|
31dea50201 | ||
|
5eefbcb26f | ||
|
b1bd5c341e | ||
|
b5fea5806d | ||
|
290b018ab9 | ||
|
65f62b75c0 | ||
|
3b67c9670d | ||
|
7401143635 | ||
|
8e00405e2e | ||
|
b120ba505f | ||
|
fab33a543c | ||
|
a32652b683 | ||
|
9eb81a541d | ||
|
9697137ae8 | ||
|
d11df03d97 | ||
|
636f33de37 | ||
|
bf9bf67fa8 | ||
|
a32bb29af6 | ||
|
10192bd29a | ||
|
233f10b384 | ||
|
54afecd3bc | ||
|
1482cb2ff7 | ||
|
007f926f1b | ||
|
514b697b00 | ||
|
ece9e5d4fa | ||
|
0d0cb707c2 | ||
|
ffbc93c668 | ||
|
5186ae8111 | ||
|
91ff5f4e11 | ||
|
772f74a908 | ||
|
850ccb71b1 | ||
|
a3d80686b4 | ||
|
d42dd2befb | ||
|
478d45bf47 | ||
|
84f5ae5403 |
24 changed files with 477 additions and 85 deletions
|
@ -1,10 +1,11 @@
|
||||||
.dart_tool
|
.dart_tool
|
||||||
.idea
|
.idea
|
||||||
.pub
|
|
||||||
.vscode
|
.vscode
|
||||||
|
.metals
|
||||||
|
.git
|
||||||
|
.github
|
||||||
|
.packages
|
||||||
logs/
|
logs/
|
||||||
test/
|
test/
|
||||||
build/
|
build/
|
||||||
.analysis-options
|
pubspec.lock
|
||||||
.packages
|
|
||||||
*.g.dart
|
|
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
|
@ -1,3 +0,0 @@
|
||||||
# These are supported funding model platforms
|
|
||||||
|
|
||||||
github: [thosakwe]
|
|
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -11,7 +11,6 @@
|
||||||
.project
|
.project
|
||||||
.pub/
|
.pub/
|
||||||
.scripts-bin/
|
.scripts-bin/
|
||||||
.metals/
|
|
||||||
build/
|
build/
|
||||||
**/packages/
|
**/packages/
|
||||||
|
|
||||||
|
@ -58,8 +57,6 @@ pubspec.lock
|
||||||
# Mongo Explorer plugin:
|
# Mongo Explorer plugin:
|
||||||
.idea/mongoSettings.xml
|
.idea/mongoSettings.xml
|
||||||
|
|
||||||
.vscode/
|
|
||||||
|
|
||||||
## File-based project format:
|
## File-based project format:
|
||||||
*.iws
|
*.iws
|
||||||
|
|
||||||
|
@ -81,7 +78,7 @@ crashlytics-build.properties
|
||||||
fabric.properties
|
fabric.properties
|
||||||
|
|
||||||
### VSCode template
|
### VSCode template
|
||||||
.vscode/*
|
.vscode/
|
||||||
!.vscode/settings.json
|
!.vscode/settings.json
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
|
@ -91,3 +88,5 @@ logs/
|
||||||
*.pem
|
*.pem
|
||||||
.DS_Store
|
.DS_Store
|
||||||
server_log.txt
|
server_log.txt
|
||||||
|
|
||||||
|
.metals/
|
||||||
|
|
12
AUTHORS.md
12
AUTHORS.md
|
@ -1,12 +0,0 @@
|
||||||
Primary Authors
|
|
||||||
===============
|
|
||||||
|
|
||||||
* __[Thomas Hii](dukefirehawk.apps@gmail.com)__
|
|
||||||
|
|
||||||
Thomas is the current maintainer of the code base. He has refactored and migrated the
|
|
||||||
code base to support NNBD.
|
|
||||||
|
|
||||||
* __[Tobe O](thosakwe@gmail.com)__
|
|
||||||
|
|
||||||
Tobe has written much of the original code prior to NNBD migration. He has moved on and
|
|
||||||
is no longer involved with the project.
|
|
|
@ -2,6 +2,4 @@
|
||||||
|
|
||||||
## 1.0.0
|
## 1.0.0
|
||||||
|
|
||||||
* Changed to use `angel3` packages
|
* Initial version
|
||||||
* Updated to support NNBD
|
|
||||||
* Updated linter to `package:lints`
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
|
|
||||||
# Contribution
|
|
||||||
|
|
||||||
Any help from the open-source community is always welcome and needed:
|
|
||||||
|
|
||||||
1. Found an issue?
|
|
||||||
- Please [fill a bug report][tracker] with error message and steps to reproduce it.
|
|
||||||
2. Wish a feature?
|
|
||||||
- Open a feature request with use cases.
|
|
||||||
3. Are you using and liking the project?
|
|
||||||
- Create an article about your use case
|
|
||||||
- Do a post on your likes and dislikes
|
|
||||||
- Make a donation.
|
|
||||||
4. Are you a developer?
|
|
||||||
- Fix a bug and send a [pull request][pull_request]
|
|
||||||
- Implement a new feature
|
|
||||||
- Improve the Unit Tests
|
|
||||||
- Improve the [User Guide][doc] and send a [document pull request][doc_repo]
|
|
||||||
5. Have you already helped in any way?
|
|
||||||
- **Many thanks to the contributors and everybody that uses this project!**
|
|
||||||
|
|
||||||
[tracker]: https://github.com/dukefirehawk/angel/issues
|
|
||||||
[pull_request]: https://github.com/dukefirehawk/angel/pulls
|
|
||||||
[doc]: https://angel3-docs.dukefirehawk.com
|
|
||||||
[doc_repo]: https://github.com/dukefirehawk/angel3-guide/pulls
|
|
|
@ -20,4 +20,5 @@ EXPOSE 3000
|
||||||
CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0
|
CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0
|
||||||
|
|
||||||
# Use -j flag to set higher number of isolates
|
# Use -j flag to set higher number of isolates
|
||||||
#CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 -j 50
|
#CMD dart ./bin/prod.dart -p 3000 -a 0.0.0.0 -j 50
|
||||||
|
|
||||||
|
|
52
README.md
52
README.md
|
@ -1,11 +1,37 @@
|
||||||
|
# ORM Starter Application for Angel3 framework
|
||||||
|
|
||||||
# Basic Starter Application for Angel3 framework
|
This is an ORM starter application for [Angel3 framework](https://angel3-framework.web.app) which is a full-stack Web framework in Dart. The default database is `postgresql`. `mysql` support is still in active development.
|
||||||
|
|
||||||
This is a basic starter application for [Angel3 framework](https://angel3-framework.web.app) which is a full-stack Web framework in Dart.
|
|
||||||
|
|
||||||
## Installation & Setup
|
## Installation & Setup
|
||||||
|
|
||||||
1. Download and install [Dart](https://dart.dev/get-dart).
|
1. Download and install [Dart](https://dart.dev/get-dart).
|
||||||
|
2. Install `postgresql` version 10, 11, 12 and 13
|
||||||
|
3. Create a new user and database in postgres using `psql` cli. For example:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
postgres=# create database appdb;
|
||||||
|
postgres=# create user appuser with encrypted password 'App1970#';
|
||||||
|
postgres=# grant all privileges on database appdb to appuser;
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Update the `postgres` section in the `config/default.yaml` file with the newly created user and database name.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
postgres:
|
||||||
|
host: localhost
|
||||||
|
port: 5432
|
||||||
|
database_name: appdb
|
||||||
|
username: appuser
|
||||||
|
password: App1970#
|
||||||
|
useSSL: false
|
||||||
|
time_zone: UTC
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Run the migration to generate `migrations` and `greetings` tables in the database.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dart bin/migrate.dart up
|
||||||
|
```
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
|
|
||||||
|
@ -17,6 +43,24 @@ This is a basic starter application for [Angel3 framework](https://angel3-framew
|
||||||
|
|
||||||
2. Modify the code and watch the changes applied to the application
|
2. Modify the code and watch the changes applied to the application
|
||||||
|
|
||||||
|
3. Insert a message into DB:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -H "Content-Type: application/json" -X POST -d '{"message":"OK_Message" }' "http://localhost:3000/greetings/"
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST -d 'message=OK_Message2' "http://localhost:3000/greetings/"
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Query DB:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:3000/greetings/
|
||||||
|
```
|
||||||
|
|
||||||
### Production
|
### Production
|
||||||
|
|
||||||
1. Run the following command:
|
1. Run the following command:
|
||||||
|
@ -32,3 +76,5 @@ This is a basic starter application for [Angel3 framework](https://angel3-framew
|
||||||
Visit the [Developer Guide](https://angel3-docs.dukefirehawk.com/guides) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3.
|
Visit the [Developer Guide](https://angel3-docs.dukefirehawk.com/guides) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3.
|
||||||
|
|
||||||
Examples and complete projects can be found [here](https://angel3-framework.web.app/#/examples).
|
Examples and complete projects can be found [here](https://angel3-framework.web.app/#/examples).
|
||||||
|
|
||||||
|
You can also view the [API Documentation](https://pub.dev/documentation/angel3_framework/latest/).
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
include: package:lints/recommended.yaml
|
include: package:lints/recommended.yaml
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:angel/angel.dart';
|
||||||
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
|
||||||
import 'package:angel3_container/mirrors.dart';
|
import 'package:angel3_container/mirrors.dart';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_hot/angel3_hot.dart';
|
import 'package:angel3_hot/angel3_hot.dart';
|
||||||
import 'package:angel/angel.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
// Watch the config/ and web/ directories for changes, and hot-reload the server.
|
||||||
|
@ -24,5 +24,5 @@ void main() async {
|
||||||
|
|
||||||
var server = await hot.startServer('127.0.0.1', 3000);
|
var server = await hot.startServer('127.0.0.1', 3000);
|
||||||
print(
|
print(
|
||||||
'[Angel3] server listening at http://${server.address.address}:${server.port}');
|
'[angel] server listening at http://${server.address.address}:${server.port}');
|
||||||
}
|
}
|
||||||
|
|
28
bin/migrate.dart
Normal file
28
bin/migrate.dart
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import 'package:angel/src/config/plugins/orm.dart';
|
||||||
|
import 'package:angel/models.dart';
|
||||||
|
import 'package:angel3_configuration/angel3_configuration.dart';
|
||||||
|
import 'package:angel3_migration_runner/angel3_migration_runner.dart';
|
||||||
|
import 'package:angel3_migration_runner/postgres.dart';
|
||||||
|
import 'package:file/local.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
|
void main(List<String> args) async {
|
||||||
|
// Enable the logging
|
||||||
|
Logger.root.level = Level.INFO;
|
||||||
|
Logger.root.onRecord.listen((rec) {
|
||||||
|
print('${rec.time}: ${rec.level.name}: ${rec.loggerName}: ${rec.message}');
|
||||||
|
|
||||||
|
if (rec.error != null) {
|
||||||
|
print(rec.error);
|
||||||
|
print(rec.stackTrace);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var fs = LocalFileSystem();
|
||||||
|
var configuration = await loadStandaloneConfiguration(fs);
|
||||||
|
var connection = await connectToPostgres(configuration);
|
||||||
|
var migrationRunner = PostgresMigrationRunner(connection, migrations: [
|
||||||
|
GreetingMigration(),
|
||||||
|
]);
|
||||||
|
return await runMigrations(migrationRunner, args);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
|
import 'package:angel/angel.dart';
|
||||||
import 'package:angel3_container/mirrors.dart';
|
import 'package:angel3_container/mirrors.dart';
|
||||||
import 'package:angel3_production/angel3_production.dart';
|
import 'package:angel3_production/angel3_production.dart';
|
||||||
import 'package:angel/angel.dart';
|
|
||||||
|
|
||||||
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
|
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
|
||||||
// reflector, by default.
|
// reflector, by default.
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
# Default server configuration.
|
# Default server configuration.
|
||||||
jwt_secret: INSECURE_DEFAULT_SECRET
|
jwt_secret: INSECURE_DEFAULT_SECRET
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
mongo_db: mongodb://localhost:27017/angel
|
|
||||||
port: 3000
|
port: 3000
|
||||||
|
postgres:
|
||||||
|
host: localhost
|
||||||
|
port: 5432
|
||||||
|
database_name: appdb
|
||||||
|
username: appuser
|
||||||
|
password: App1970#
|
||||||
|
use_ssl: false
|
||||||
|
time_zone: UTC
|
||||||
|
|
||||||
|
|
1
lib/models.dart
Normal file
1
lib/models.dart
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export 'src/models/greeting.dart';
|
|
@ -1,4 +1,3 @@
|
||||||
/// Configuration for this Angel instance.
|
|
||||||
import 'package:angel3_configuration/angel3_configuration.dart';
|
import 'package:angel3_configuration/angel3_configuration.dart';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_jael/angel3_jael.dart';
|
import 'package:angel3_jael/angel3_jael.dart';
|
||||||
|
|
38
lib/src/config/plugins/orm.dart
Normal file
38
lib/src/config/plugins/orm.dart
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
|
import 'package:angel3_orm_postgres/angel3_orm_postgres.dart';
|
||||||
|
import 'package:postgres/postgres.dart';
|
||||||
|
|
||||||
|
Future<void> configureServer(Angel app) async {
|
||||||
|
try {
|
||||||
|
var connection = await connectToPostgres(app.configuration);
|
||||||
|
await connection.open();
|
||||||
|
|
||||||
|
var executor = PostgreSqlExecutor(connection, logger: app.logger);
|
||||||
|
|
||||||
|
app
|
||||||
|
..container.registerSingleton<QueryExecutor>(executor)
|
||||||
|
..shutdownHooks.add((_) => connection.close());
|
||||||
|
} catch (e) {
|
||||||
|
app.logger.severe("Failed to connect to PostgreSQL. ORM disabled.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<PostgreSQLConnection> connectToPostgres(Map configuration) async {
|
||||||
|
var postgresConfig = configuration['postgres'] as Map? ?? {};
|
||||||
|
var connection = PostgreSQLConnection(
|
||||||
|
postgresConfig['host'] as String? ?? 'localhost',
|
||||||
|
postgresConfig['port'] as int? ?? 5432,
|
||||||
|
postgresConfig['database_name'] as String? ??
|
||||||
|
Platform.environment['USER'] ??
|
||||||
|
Platform.environment['USERNAME'] ??
|
||||||
|
'',
|
||||||
|
username: postgresConfig['username'] as String?,
|
||||||
|
password: postgresConfig['password'] as String?,
|
||||||
|
timeZone: postgresConfig['time_zone'] as String? ?? 'UTC',
|
||||||
|
timeoutInSeconds: postgresConfig['timeout_in_seconds'] as int? ?? 30,
|
||||||
|
useSSL: postgresConfig['use_ssl'] as bool? ?? false);
|
||||||
|
return connection;
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
/// Custom plugins go here.
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
|
import 'orm.dart' as orm;
|
||||||
|
|
||||||
Future configureServer(Angel app) async {
|
Future configureServer(Angel app) async {
|
||||||
// Include any plugins you have made here.
|
// Include any plugins you have made here.
|
||||||
|
await app.configure(orm.configureServer);
|
||||||
}
|
}
|
||||||
|
|
12
lib/src/models/greeting.dart
Normal file
12
lib/src/models/greeting.dart
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
|
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
|
import 'package:optional/optional.dart';
|
||||||
|
part 'greeting.g.dart';
|
||||||
|
|
||||||
|
@serializable
|
||||||
|
@orm
|
||||||
|
abstract class _Greeting extends Model {
|
||||||
|
@SerializableField(isNullable: false)
|
||||||
|
String? get message;
|
||||||
|
}
|
267
lib/src/models/greeting.g.dart
Normal file
267
lib/src/models/greeting.g.dart
Normal file
|
@ -0,0 +1,267 @@
|
||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'greeting.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// MigrationGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class GreetingMigration extends Migration {
|
||||||
|
@override
|
||||||
|
void up(Schema schema) {
|
||||||
|
schema.create('greetings', (table) {
|
||||||
|
table.serial('id').primaryKey();
|
||||||
|
table.varChar('message');
|
||||||
|
table.timeStamp('created_at');
|
||||||
|
table.timeStamp('updated_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void down(Schema schema) {
|
||||||
|
schema.drop('greetings');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// OrmGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class GreetingQuery extends Query<Greeting, GreetingQueryWhere> {
|
||||||
|
GreetingQuery({Set<String>? trampoline}) {
|
||||||
|
trampoline ??= <String>{};
|
||||||
|
trampoline.add(tableName);
|
||||||
|
_where = GreetingQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final GreetingQueryValues values = GreetingQueryValues();
|
||||||
|
|
||||||
|
GreetingQueryWhere? _where;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get tableName {
|
||||||
|
return 'greetings';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> get fields {
|
||||||
|
return const ['id', 'message', 'created_at', 'updated_at'];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
GreetingQueryWhere? get where {
|
||||||
|
return _where;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
GreetingQueryWhere newWhereClause() {
|
||||||
|
return GreetingQueryWhere(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Greeting? parseRow(List row) {
|
||||||
|
if (row.every((x) => x == null)) return null;
|
||||||
|
var model = Greeting(
|
||||||
|
id: row[0].toString(),
|
||||||
|
message: (row[1] as String?),
|
||||||
|
createdAt: (row[2] as DateTime?),
|
||||||
|
updatedAt: (row[3] as DateTime?));
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Optional<Greeting> deserialize(List row) {
|
||||||
|
return Optional.ofNullable(parseRow(row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GreetingQueryWhere extends QueryWhere {
|
||||||
|
GreetingQueryWhere(GreetingQuery query)
|
||||||
|
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
|
||||||
|
message = StringSqlExpressionBuilder(query, 'message'),
|
||||||
|
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
|
||||||
|
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at');
|
||||||
|
|
||||||
|
final NumericSqlExpressionBuilder<int> id;
|
||||||
|
|
||||||
|
final StringSqlExpressionBuilder message;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder createdAt;
|
||||||
|
|
||||||
|
final DateTimeSqlExpressionBuilder updatedAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<SqlExpressionBuilder> get expressionBuilders {
|
||||||
|
return [id, message, createdAt, updatedAt];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GreetingQueryValues extends MapQueryValues {
|
||||||
|
@override
|
||||||
|
Map<String, String> get casts {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
String? get id {
|
||||||
|
return (values['id'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(String? value) => values['id'] = value;
|
||||||
|
String? get message {
|
||||||
|
return (values['message'] as String?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set message(String? value) => values['message'] = value;
|
||||||
|
DateTime? get createdAt {
|
||||||
|
return (values['created_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set createdAt(DateTime? value) => values['created_at'] = value;
|
||||||
|
DateTime? get updatedAt {
|
||||||
|
return (values['updated_at'] as DateTime?);
|
||||||
|
}
|
||||||
|
|
||||||
|
set updatedAt(DateTime? value) => values['updated_at'] = value;
|
||||||
|
void copyFrom(Greeting model) {
|
||||||
|
message = model.message;
|
||||||
|
createdAt = model.createdAt;
|
||||||
|
updatedAt = model.updatedAt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonModelGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
@generatedSerializable
|
||||||
|
class Greeting extends _Greeting {
|
||||||
|
Greeting({this.id, required this.message, this.createdAt, this.updatedAt});
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String? id;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String? message;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final DateTime? createdAt;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final DateTime? updatedAt;
|
||||||
|
|
||||||
|
Greeting copyWith(
|
||||||
|
{String? id, String? message, DateTime? createdAt, DateTime? updatedAt}) {
|
||||||
|
return Greeting(
|
||||||
|
id: id ?? this.id,
|
||||||
|
message: message ?? this.message,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(other) {
|
||||||
|
return other is _Greeting &&
|
||||||
|
other.id == id &&
|
||||||
|
other.message == message &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.updatedAt == updatedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return hashObjects([id, message, createdAt, updatedAt]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Greeting(id=$id, message=$message, createdAt=$createdAt, updatedAt=$updatedAt)';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return GreetingSerializer.toMap(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// SerializerGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
const GreetingSerializer greetingSerializer = GreetingSerializer();
|
||||||
|
|
||||||
|
class GreetingEncoder extends Converter<Greeting, Map> {
|
||||||
|
const GreetingEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map convert(Greeting model) => GreetingSerializer.toMap(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
class GreetingDecoder extends Converter<Map, Greeting> {
|
||||||
|
const GreetingDecoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Greeting convert(Map map) => GreetingSerializer.fromMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
class GreetingSerializer extends Codec<Greeting, Map> {
|
||||||
|
const GreetingSerializer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
GreetingEncoder get encoder => const GreetingEncoder();
|
||||||
|
|
||||||
|
@override
|
||||||
|
GreetingDecoder get decoder => const GreetingDecoder();
|
||||||
|
static Greeting fromMap(Map map) {
|
||||||
|
if (map['message'] == null) {
|
||||||
|
throw FormatException("Missing required field 'message' on Greeting.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Greeting(
|
||||||
|
id: map['id'] as String?,
|
||||||
|
message: map['message'] as String?,
|
||||||
|
createdAt: map['created_at'] != null
|
||||||
|
? (map['created_at'] is DateTime
|
||||||
|
? (map['created_at'] as DateTime?)
|
||||||
|
: DateTime.parse(map['created_at'].toString()))
|
||||||
|
: null,
|
||||||
|
updatedAt: map['updated_at'] != null
|
||||||
|
? (map['updated_at'] is DateTime
|
||||||
|
? (map['updated_at'] as DateTime?)
|
||||||
|
: DateTime.parse(map['updated_at'].toString()))
|
||||||
|
: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, dynamic> toMap(_Greeting model) {
|
||||||
|
if (model.message == null) {
|
||||||
|
throw FormatException("Missing required field 'message' on Greeting.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'id': model.id,
|
||||||
|
'message': model.message,
|
||||||
|
'created_at': model.createdAt?.toIso8601String(),
|
||||||
|
'updated_at': model.updatedAt?.toIso8601String()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class GreetingFields {
|
||||||
|
static const List<String> allFields = <String>[
|
||||||
|
id,
|
||||||
|
message,
|
||||||
|
createdAt,
|
||||||
|
updatedAt
|
||||||
|
];
|
||||||
|
|
||||||
|
static const String id = 'id';
|
||||||
|
|
||||||
|
static const String message = 'message';
|
||||||
|
|
||||||
|
static const String createdAt = 'created_at';
|
||||||
|
|
||||||
|
static const String updatedAt = 'updated_at';
|
||||||
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
/// This app's route configuration.
|
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:angel3_static/angel3_static.dart';
|
import 'package:angel3_static/angel3_static.dart';
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
import 'controllers/controllers.dart' as controllers;
|
import 'controllers/controllers.dart' as controllers;
|
||||||
|
import '../models/greeting.dart';
|
||||||
|
|
||||||
/// Put your app routes here!
|
/// Put your app routes here!
|
||||||
///
|
///
|
||||||
|
@ -17,6 +18,33 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||||
// Render `views/hello.jl` when a user visits the application root.
|
// Render `views/hello.jl` when a user visits the application root.
|
||||||
app.get('/', (req, res) => res.render('hello'));
|
app.get('/', (req, res) => res.render('hello'));
|
||||||
|
|
||||||
|
app.get('/greetings', (req, res) {
|
||||||
|
var executor = req.container!.make<QueryExecutor>();
|
||||||
|
var query = GreetingQuery();
|
||||||
|
return query.get(executor);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/greetings', (req, res) async {
|
||||||
|
await req.parseBody();
|
||||||
|
|
||||||
|
if (!req.bodyAsMap.containsKey('message')) {
|
||||||
|
throw AngelHttpException.badRequest(message: 'Missing "message".');
|
||||||
|
} else {
|
||||||
|
var executor = req.container!.make<QueryExecutor>();
|
||||||
|
var message = req.bodyAsMap['message'].toString();
|
||||||
|
var query = GreetingQuery()..values.message = message;
|
||||||
|
var optional = await query.insert(executor);
|
||||||
|
return optional.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/greetings/:message', (req, res) {
|
||||||
|
var message = req.params['message'] as String;
|
||||||
|
var executor = req.container!.make<QueryExecutor>();
|
||||||
|
var query = GreetingQuery()..where!.message.equals(message);
|
||||||
|
return query.get(executor);
|
||||||
|
});
|
||||||
|
|
||||||
// Mount static server at web in development.
|
// Mount static server at web in development.
|
||||||
// The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers.
|
// The `CachingVirtualDirectory` variant of `VirtualDirectory` also sends `Cache-Control` headers.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/// Declare services here!
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
|
|
||||||
|
|
40
pubspec.yaml
40
pubspec.yaml
|
@ -1,25 +1,31 @@
|
||||||
name: angel
|
name: angel
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
description: A basic starter application template for Angel3 framework
|
description: An ORM starter application for Angel3 framework
|
||||||
publish_to: none
|
publish_to: none
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.16.0 <3.0.0'
|
sdk: '>=2.17.0 <3.0.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
angel3_auth: ^6.0.0
|
angel3_auth: ^7.0.0
|
||||||
angel3_configuration: ^6.0.0
|
angel3_configuration: ^7.0.0
|
||||||
angel3_framework: ^6.0.0
|
angel3_framework: ^7.0.0
|
||||||
angel3_jael: ^6.0.0
|
angel3_jael: ^7.0.0
|
||||||
angel3_production: ^6.0.0
|
angel3_migration: ^7.0.0
|
||||||
angel3_static: ^6.0.0
|
angel3_orm: ^7.0.0
|
||||||
angel3_validate: ^6.0.0
|
angel3_orm_postgres: ^7.0.0
|
||||||
belatuk_pretty_logging: ^4.0.0
|
angel3_serialize: ^7.0.0
|
||||||
|
angel3_production: ^7.0.0
|
||||||
|
angel3_static: ^7.0.0
|
||||||
|
angel3_validate: ^7.0.0
|
||||||
|
belatuk_pretty_logging: ^5.0.0
|
||||||
|
optional: ^6.0.0
|
||||||
|
logging: ^1.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
angel3_hot: ^6.0.0
|
angel3_hot: ^7.0.0
|
||||||
angel3_test: ^6.0.0
|
angel3_migration_runner: ^7.0.0
|
||||||
|
angel3_orm_generator: ^7.0.0
|
||||||
|
angel3_serialize_generator: ^7.0.0
|
||||||
|
angel3_test: ^7.0.0
|
||||||
|
build_runner: ^2.0.3
|
||||||
io: ^1.0.0
|
io: ^1.0.0
|
||||||
test: ^1.21.0
|
test: ^1.21.0
|
||||||
lints: ^1.0.0
|
lints: ^2.0.0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
import 'package:angel/angel.dart';
|
||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:angel3_test/angel3_test.dart';
|
import 'package:angel3_test/angel3_test.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:angel/angel.dart';
|
|
||||||
|
|
||||||
// Angel also includes facilities to make testing easier.
|
// Angel also includes facilities to make testing easier.
|
||||||
//
|
//
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
<head>
|
<head>
|
||||||
<title>{{ title ?? 'Angel' }}</title>
|
<title>{{ title ?? 'Angel' }}</title>
|
||||||
|
|
||||||
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
|
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Lato:100" >
|
||||||
<link rel="stylesheet" href="/css/site.css">
|
<link rel="stylesheet" type="text/css" href="/css/site.css">
|
||||||
<link rel="icon" href="/images/favicon.png">
|
<link rel="icon" href="/images/favicon.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Reference in a new issue