feat: change api framework to angel3.

This commit is contained in:
2021-12-17 18:24:32 +08:00
parent 8face6f724
commit ed863ecb41
39 changed files with 1008 additions and 368 deletions
+28
View File
@@ -0,0 +1,28 @@
import 'dart:io';
import 'package:dde_gesture_manager_api/dde_gesture_manager_api.dart';
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
import 'package:angel3_container/mirrors.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_hot/angel3_hot.dart';
import 'package:logging/logging.dart';
void main() async {
// Watch the config/ and web/ directories for changes, and hot-reload the server.
hierarchicalLoggingEnabled = true;
var hot = HotReloader(() async {
var logger = Logger.detached('dde_gesture_manager_api')
..level = Level.ALL
..onRecord.listen(prettyLog);
var app = Angel(logger: logger, reflector: MirrorsReflector());
await app.configure(configureServer);
return app;
}, [
Directory('config'),
Directory('lib'),
]);
var server = await hot.startServer('127.0.0.1', 3000);
print(
'dde_gesture_manager_api server listening at http://${server.address.address}:${server.port}');
}
-13
View File
@@ -1,13 +0,0 @@
import 'package:dde_gesture_manager/dde_gesture_manager.dart';
Future main() async {
final app = Application<DdeGestureManagerChannel>()
..options.configurationFilePath = "config.yaml"
..options.port = 8888;
await app.startOnCurrentIsolate();
print("Application started on port: ${app.options.port}.");
print("Click to open in browser: http://localhost:${app.options.port}");
print("Use Ctrl-C (SIGINT) to stop running the application.");
}
+28
View File
@@ -0,0 +1,28 @@
import 'package:dde_gesture_manager_api/src/config/plugins/orm.dart';
import 'package:dde_gesture_manager_api/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: [
UserMigration(),
]);
await runMigrations(migrationRunner, args);
}
+27
View File
@@ -0,0 +1,27 @@
import 'package:dde_gesture_manager_api/dde_gesture_manager_api.dart';
import 'package:angel3_production/angel3_production.dart';
// NOTE: By default, the Runner class does not use the `MirrorsReflector`, or any
// reflector, by default.
//
// If your application is using any sort of functionality reliant on annotations or reflection,
// either include the MirrorsReflector, or use a static reflector variant.
//
// The following use cases require reflection:
// * Use of Controllers, via @Expose() or @ExposeWS()
// * Use of dependency injection into constructors, whether in controllers or plain `container.make` calls
// * Use of the `ioc` function in any route
//
// The `MirrorsReflector` from `package:angel_container/mirrors.dart` is by far the most convenient pattern,
// so use it if possible.
//
// However, the following alternatives exist:
// * Generation via `package:angel_container_generator`
// * Creating an instance of `StaticReflector`
// * Manually implementing the `Reflector` interface (cumbersome; not recommended)
//
// As of January 4th, 2018, the documentation has not yet been updated to state this,
// so in the meantime, visit the Angel chat for further questions:
//
// https://gitter.im/angel_dart/discussion
void main(List<String> args) => Runner('dde_gesture_manager_api', configureServer).run(args);