diff --git a/README.md b/README.md index bea5e20d..875b1e5c 100644 --- a/README.md +++ b/README.md @@ -47,30 +47,54 @@ You can check the documentation at [dartness docs](https://ricardorb.github.io/d $ dart create -t console your_project_name ``` -1. Add dartness into the pubspec.yaml +### 1. Add dartness into the pubspec.yaml ```yaml dependencies: - dartness_server: ^0.4.5-alpha + dartness_server: ^0.5.0-alpha dev_dependencies: build_runner: ^2.2.0 - dartness_generator: ^0.1.2-alpha + dartness_generator: ^0.4.6-alpha ``` -2. Create the file in "bin/main.dart" + +### 2.Create the file in "src/app.dart" ```dart -void main() async { - final app = Dartness( - port: 3000, - ); - await app.create(); -} +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [], + providers: [], + exports: [], + imports: [], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} +``` +### 4.Generate the code + +```bash +$ dart run build_runner build +``` + +### 5.Modify "bin/main.dart" +```dart +void main(List args) async { + await App().init(); +} ``` -3. Run the server +### 6.Run the server ```bash $ dart run bin/main.dart @@ -99,13 +123,13 @@ Server listening on port 3000 - Middleware - Interceptor - Websockets -2. Exceptions +2. Exceptions - Exception Handler 3. Security - Roles - CORS -4. Dependency Injection - - Injectable +4. Dependency Injection + - Injectable 5. Scheduling - Annotation 6. Database diff --git a/docs/README.md b/docs/README.md index 8f0d09a7..875b1e5c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -30,7 +30,7 @@ the [/examples folder](https://github.com/RicardoRB/dartness/tree/master/example ## Requisites -Install [Dart SDK](https://dart.dev/get-dart) version >=2.17.0 +Install [Dart SDK](https://dart.dev/get-dart) version >=3.0.0 ```bash $ dart --version @@ -47,30 +47,54 @@ You can check the documentation at [dartness docs](https://ricardorb.github.io/d $ dart create -t console your_project_name ``` -1. Add dartness into the pubspec.yaml +### 1. Add dartness into the pubspec.yaml ```yaml dependencies: - dartness_server: ^0.4.3-alpha + dartness_server: ^0.5.0-alpha dev_dependencies: build_runner: ^2.2.0 - dartness_generator: ^0.1.0-alpha + dartness_generator: ^0.4.6-alpha ``` -2. Create the file in "bin/main.dart" + +### 2.Create the file in "src/app.dart" ```dart -void main() async { - final app = Dartness( - port: 3000, - ); - await app.create(); -} +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [], + providers: [], + exports: [], + imports: [], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} +``` +### 4.Generate the code + +```bash +$ dart run build_runner build +``` + +### 5.Modify "bin/main.dart" +```dart +void main(List args) async { + await App().init(); +} ``` -3. Run the server +### 6.Run the server ```bash $ dart run bin/main.dart @@ -99,13 +123,13 @@ Server listening on port 3000 - Middleware - Interceptor - Websockets -2. Exceptions +2. Exceptions - Exception Handler 3. Security - Roles - CORS -4. Dependency Injection - - Injectable +4. Dependency Injection + - Injectable 5. Scheduling - Annotation 6. Database diff --git a/docs/exceptions.md b/docs/exceptions.md index 04d6ce36..9b8e071e 100644 --- a/docs/exceptions.md +++ b/docs/exceptions.md @@ -94,14 +94,26 @@ This new created class accepts an instance of the class from where have been cre must be used in the `errorHandlers` param. You can see an example in the following code: ```dart -void main() async { - final errorHandlers = [ - ExampleDartnessErrorHandler(ExampleErrorHandler()), - ]; - final app = Dartness( - port: 3000, - errorHandlers: errorHandlers, - ); - await app.create(); -} + +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [], + providers: [ + ProviderMetadata( + classType: MyException, + ), + ], + exports: [], + imports: [], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} ``` \ No newline at end of file diff --git a/docs/first_steps.md b/docs/first_steps.md index b709c988..ce558259 100644 --- a/docs/first_steps.md +++ b/docs/first_steps.md @@ -16,29 +16,32 @@ Please make sure that [Dart SDK](https://dart.dev/get-dart) version >=2.17.0 is $ dart create -t console your_project_name ``` -1. Add dartness into the pubspec.yaml +### 1. Add dartness into the pubspec.yaml ```yaml dependencies: - dartness_server: ^0.4.3-alpha + dartness_server: ^0.5.0-alpha dev_dependencies: build_runner: ^2.2.0 - dartness_generator: ^0.1.0-alpha + dartness_generator: ^0.4.6-alpha ``` -2. Create the file in "bin/main.dart" or whatever file that runs your application. +### 2. Create the file in "bin/app.dart" or whatever file that you consider that you root application is. ```dart -void main() async { - final app = Dartness( - port: 3000, - ); - await app.create(); -} +@Application( + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} ``` -## Generate the code +### 3. Generate the code Dartness uses the code generation feature provided by the package `code_builder`, this is the way that dart is able to use reflection since `dart:mirrors` is unstable and not supported in order to compile your package. @@ -57,7 +60,7 @@ $ dart run build_runner build > * [dart:mirrors](https://api.dart.dev/stable/2.17.6/dart-mirrors/dart-mirrors-library.html) > * [discontinuing support for dart:mirrors](https://github.com/dart-lang/sdk/issues/44489) -## Adding a controller +### 4. Adding a controller In order to create a controller, you need to import it and add it to the `Dartness` app. You can do it in two different ways, either adding it when you create the dartness app by the `controllers` param or after @@ -77,15 +80,36 @@ This new created class accepts an instance of the class from where have been cre must be used in the `controllers` param. You can see an example in the following code: ```dart -void main() async { - final controllers = [ - CityDartnessController(CityController(CityService())), - ]; - final app = Dartness( - port: 3000, - controllers: controllers, - ); - await app.create(); +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: CityController, + ), + ], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} +``` + +### 5. Generate the code + +```bash +$ dart run build_runner build +``` + +### 6. Modify "bin/main.dart" +```dart +void main(List args) async { + await App().init(); } ``` diff --git a/docs/index.html b/docs/index.html index 38700e09..04dd4a72 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,23 +1,22 @@ - - Document - - - - + + Document + + + + -
- - - + + + diff --git a/docs/interceptor.md b/docs/interceptor.md index 54eeb461..6462c01d 100644 --- a/docs/interceptor.md +++ b/docs/interceptor.md @@ -39,17 +39,30 @@ class MyInterceptor implements DartnessInterceptor { ## Applying interceptor -In order to apply your interceptor, you need to add it to the `interpcetors` list in the `DartnessServer` class. This +In order to apply your interceptor, you need to add it to the `interpcetors` list in the `Module` annotation. This will create a global interceptors and are used across the whole application, for every controller and every route handler. ```dart -void main() async { - final app = Dartness( - port: 3000, - interceptors: [MyInterceptor()], - ); - // As optional, you can also use app.addInterceptor(MyInterceptor()); - await app.create(); -} +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [], + providers: [ + ProviderMetadata( + classType: MyInterceptor, + ), + ], + exports: [], + imports: [], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} ``` \ No newline at end of file diff --git a/docs/middleware.md b/docs/middleware.md index bee612b6..9fc58fdc 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -23,15 +23,28 @@ class MyMiddleware implements DartnessMiddleware { ## Applying middleware -In order to apply your middleware, you need to add it to the `middleware` list in the `DartnessServer` class. +In order to apply your middleware, you need to add it to the `middleware` list in the `Module` annotation. ```dart -void main() async { - final app = Dartness( - port: 3000, - middlewares: [MyMiddleware()], - ); - // As optional, you can also use app.addMiddleware(MyMiddleware()); - await app.create(); -} +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [], + providers: [ + ProviderMetadata( + classType: MyMiddleWare, + ), + ], + exports: [], + imports: [], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} ``` \ No newline at end of file diff --git a/docs/quickstart.md b/docs/quickstart.md index 86648562..31a7d96e 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -6,7 +6,7 @@ You can run the example with the [Dart SDK](https://dart.dev/get-dart) like this: ```bash -$ dart run bin/dartness.dart +$ dart run bin/example.dart Server listening on port 8080 ``` @@ -25,26 +25,51 @@ Dart SDK version: 3.0.0 (stable) $ dart create -t console your_project_name ``` -1Add dartness into the pubspec.yaml +### 1.Add dartness into the pubspec.yaml ```yaml dependencies: - dartness_server: ^0.4.3-alpha + dartness_server: ^0.5.0-alpha +dev_dependencies: + dartness_generator: ^0.4.6-alpha ``` -2.Create the file in "bin/main.dart" +### 2.Create the file in "src/app.dart" ```dart -void main() async { - final app = Dartness( - port: 3000, - ); - await app.create(); -} +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [], + providers: [], + exports: [], + imports: [], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} +``` + +### 4.Generate the code + +```bash +$ dart run build_runner build +``` +### 5.Modify "bin/main.dart" +```dart +void main(List args) async { + await App().init(); +} ``` -3.Run the server +### 6.Run the server ```bash $ dart run bin/main.dart diff --git a/examples/dartness_flutter_melos/apps/my_app/.gitignore b/examples/dartness_flutter_melos/apps/my_app/.gitignore index a8e938c0..1eab1a22 100644 --- a/examples/dartness_flutter_melos/apps/my_app/.gitignore +++ b/examples/dartness_flutter_melos/apps/my_app/.gitignore @@ -33,7 +33,6 @@ migrate_working_dir/ /build/ # Web related -lib/generated_plugin_registrant.dart # Symbolication related app.*.symbols diff --git a/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml b/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml index 4306341f..d580a277 100644 --- a/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml +++ b/examples/dartness_flutter_melos/apps/my_app/pubspec.yaml @@ -11,13 +11,13 @@ environment: dependencies: flutter: sdk: flutter - cupertino_icons: ^1.0.5 - http: ^1.0.0 + cupertino_icons: ^1.0.6 + http: ^1.1.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.1 + flutter_lints: ^2.0.3 flutter: uses-material-design: true diff --git a/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml b/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml index 54cf9d05..4da1e0e6 100644 --- a/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml +++ b/examples/dartness_flutter_melos/servers/my_server/pubspec.yaml @@ -9,10 +9,10 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - dartness_server: ^0.4.4-alpha + dartness_server: ^0.4.6-alpha dev_dependencies: - lints: ^2.0.0 - test: ^1.21.4 - build_runner: ^2.2.0 - dartness_generator: ^0.1.0-alpha + lints: ^2.1.1 + test: ^1.24.7 + build_runner: ^2.4.6 + dartness_generator: ^0.1.3-alpha diff --git a/examples/dartness_simple/.gitignore b/examples/dartness_simple/.gitignore index 65c34dc8..4c1d3c7f 100644 --- a/examples/dartness_simple/.gitignore +++ b/examples/dartness_simple/.gitignore @@ -8,3 +8,4 @@ build/ # Omit committing pubspec.lock for library packages; see # https://dart.dev/guides/libraries/private-files#pubspeclock. pubspec.lock +/build.dart diff --git a/examples/dartness_simple/bin/example.dart b/examples/dartness_simple/bin/example.dart index a0381c34..872f0713 100644 --- a/examples/dartness_simple/bin/example.dart +++ b/examples/dartness_simple/bin/example.dart @@ -1,27 +1,5 @@ -import 'package:dartness_server/dartness.dart'; -import 'package:example/src/controllers/city_controller.dart'; -import 'package:example/src/error_handlers/example_error_handler.dart'; -import 'package:example/src/interceptors/example_interceptor.dart'; -import 'package:example/src/middlewares/example_middleware.dart'; -import 'package:example/src/services/city_service.dart'; +import 'package:example/src/app.dart'; void main(List args) async { - final controllers = [ - CityDartnessController(CityController(CityService())), - ]; - final errorHandlers = [ - ExampleDartnessErrorHandler(ExampleErrorHandler()), - ]; - final app = Dartness( - port: 3000, - controllers: controllers, - errorHandlers: errorHandlers, - middlewares: [ - ExampleMiddleware(), - ], - interceptors: [ - ExampleInterceptor(), - ], - ); - app.create(); + await App().init(); } diff --git a/examples/dartness_simple/lib/app_module.dart b/examples/dartness_simple/lib/app_module.dart new file mode 100644 index 00000000..5b001e87 --- /dev/null +++ b/examples/dartness_simple/lib/app_module.dart @@ -0,0 +1,20 @@ +import 'package:dartness_server/modules.dart'; +import 'package:example/src/services/city_service.dart'; + +import 'src/controllers/city/city_controller.dart'; + +@Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: CityController, + ), + ], + providers: [ + ProviderMetadata( + classType: CityService, + ), + ], + ), +) +class AppModule {} diff --git a/examples/dartness_simple/lib/src/app.dart b/examples/dartness_simple/lib/src/app.dart new file mode 100644 index 00000000..3caf66fc --- /dev/null +++ b/examples/dartness_simple/lib/src/app.dart @@ -0,0 +1,42 @@ +import 'package:dartness_server/dartness.dart'; +import 'package:dartness_server/modules.dart'; +import 'package:dartness_server/server.dart'; +import 'package:example/src/controllers/city/city_module.dart'; +import 'package:example/src/controllers/user/user_module.dart'; +import 'package:example/src/services/city_service.dart'; + +import 'controllers/city/city_controller.dart'; +import 'controllers/health_controller.dart'; +import 'controllers/user/user_controller.dart'; +import 'error_handlers/example_error_handler.dart'; + +part 'app.g.dart'; + +@Application( + module: Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: HealthController, + ), + ], + providers: [ + ProviderMetadata( + classType: ExampleErrorHandler, + ), + ], + exports: [], + imports: [ + userModule, + cityModule, + ], + ), + ), + options: DartnessApplicationOptions( + port: int.fromEnvironment( + 'port', + defaultValue: 8080, + ), + ), +) +class App {} diff --git a/examples/dartness_simple/lib/src/app.g.dart b/examples/dartness_simple/lib/src/app.g.dart new file mode 100644 index 00000000..4f5c5dea --- /dev/null +++ b/examples/dartness_simple/lib/src/app.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'app.dart'; + +// ************************************************************************** +// ApplicationGenerator +// ************************************************************************** + +extension AppExtension on App { + initDependencies() { + final injectRegister = InstanceRegister.instance; + injectRegister.register(UserController()); + injectRegister.register(CityService()); + injectRegister.register(CityController( + injectRegister.resolve(), + )); + injectRegister.register(HealthController()); + injectRegister.register(ExampleErrorHandler()); + } + + Future init() async { + initDependencies(); + final injectRegister = InstanceRegister.instance; + final app = Dartness(); + await app.create( + controllers: [ + UserDartnessController(injectRegister.resolve()), + CityDartnessController(injectRegister.resolve()), + HealthDartnessController(injectRegister.resolve()), + ], + options: DartnessApplicationOptions( + logRequest: false, + port: 8080, + ), + ); + } +} diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.dart b/examples/dartness_simple/lib/src/controllers/city/city_controller.dart similarity index 71% rename from examples/dartness_simple/lib/src/controllers/city_controller.dart rename to examples/dartness_simple/lib/src/controllers/city/city_controller.dart index 3c836ce7..ca6f03ab 100644 --- a/examples/dartness_simple/lib/src/controllers/city_controller.dart +++ b/examples/dartness_simple/lib/src/controllers/city/city_controller.dart @@ -2,12 +2,13 @@ import 'dart:io'; import 'package:dartness_server/route.dart'; -import '../dtos/city_dto.dart'; -import '../services/city_service.dart'; +import '../../dtos/city_dto.dart'; +import '../../services/city_service.dart'; part 'city_controller.g.dart'; @Controller('/cities') +@Header(HttpHeaders.contentTypeHeader, 'application/json') class CityController { CityController(this._cityService); @@ -16,12 +17,11 @@ class CityController { @HttpCode(202) @Get() List getCities({ - @QueryParam() int? offset = 100, + @QueryParam() int? offset, }) { return _cityService.getCities(offset); } - @Header(HttpHeaders.contentTypeHeader, 'application/json') @Get('/') CityDto getCity(@PathParam() int id) { return _cityService.getCity(id); diff --git a/examples/dartness_simple/lib/src/controllers/city/city_controller.g.dart b/examples/dartness_simple/lib/src/controllers/city/city_controller.g.dart new file mode 100644 index 00000000..3ca3e74c --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/city/city_controller.g.dart @@ -0,0 +1,64 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'city_controller.dart'; + +// ************************************************************************** +// ControllerGenerator +// ************************************************************************** + +extension CityControllerRoutes on CityController { + List getRoutes() { + final routes = []; + routes.add(ControllerRoute( + method: 'GET', + path: '/cities', + handler: getCities, + params: [ + DartnessParam( + name: 'offset', + isQuery: true, + isPath: false, + isBody: false, + isNamed: true, + isPositional: false, + isOptional: true, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: 202, + headers: {'content-type': 'application/json'}, + )); + routes.add(ControllerRoute( + method: 'GET', + path: '/cities/', + handler: getCity, + params: [ + DartnessParam( + name: 'id', + isQuery: false, + isPath: true, + isBody: false, + isNamed: false, + isPositional: true, + isOptional: false, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: null, + headers: {'content-type': 'application/json'}, + )); + return routes; + } +} + +class CityDartnessController extends DartnessController { + CityDartnessController(CityController controller) + : super( + controller, + controller.getRoutes(), + ); +} diff --git a/examples/dartness_simple/lib/src/controllers/city/city_module.dart b/examples/dartness_simple/lib/src/controllers/city/city_module.dart new file mode 100644 index 00000000..7db0e2cd --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/city/city_module.dart @@ -0,0 +1,19 @@ +import 'package:dartness_server/modules.dart'; + +import '../../services/city_service.dart'; +import 'city_controller.dart'; + +const cityModule = Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: CityController, + ), + ], + providers: [ + ProviderMetadata( + classType: CityService, + ), + ], + ), +); diff --git a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart b/examples/dartness_simple/lib/src/controllers/city_controller.g.dart deleted file mode 100644 index 72abd8fd..00000000 --- a/examples/dartness_simple/lib/src/controllers/city_controller.g.dart +++ /dev/null @@ -1,39 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'city_controller.dart'; - -// ************************************************************************** -// ControllerGenerator -// ************************************************************************** - -extension CityControllerRoutes on CityController { - List getRoutes() { - final routes = []; - routes.add(ControllerRoute( - 'GET', - '/cities', - getCities, - [ - DartnessParam('offset', true, false, false, true, false, true, int, - defaultValue: '100', fromJson: null) - ], - httpCode: 202, - headers: {})); - routes.add(ControllerRoute( - 'GET', - '/cities/', - getCity, - [ - DartnessParam('id', false, true, false, false, true, false, int, - defaultValue: null, fromJson: null) - ], - httpCode: null, - headers: {'content-type': 'application/json'})); - return routes; - } -} - -class CityDartnessController extends DartnessController { - CityDartnessController(CityController controller) - : super(controller, controller.getRoutes()); -} diff --git a/examples/dartness_simple/lib/src/controllers/health_controller.dart b/examples/dartness_simple/lib/src/controllers/health_controller.dart new file mode 100644 index 00000000..5fd59739 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/health_controller.dart @@ -0,0 +1,15 @@ +import 'dart:io'; + +import 'package:dartness_server/route.dart'; + +part 'health_controller.g.dart'; + +@Controller('/health') +@Header(HttpHeaders.contentTypeHeader, 'application/json') +class HealthController { + @HttpCode(202) + @Get() + bool getAlive() { + return true; + } +} diff --git a/examples/dartness_simple/lib/src/controllers/health_controller.g.dart b/examples/dartness_simple/lib/src/controllers/health_controller.g.dart new file mode 100644 index 00000000..26528a21 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/health_controller.g.dart @@ -0,0 +1,30 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'health_controller.dart'; + +// ************************************************************************** +// ControllerGenerator +// ************************************************************************** + +extension HealthControllerRoutes on HealthController { + List getRoutes() { + final routes = []; + routes.add(ControllerRoute( + method: 'GET', + path: '/health', + handler: getAlive, + params: [], + httpCode: 202, + headers: {'content-type': 'application/json'}, + )); + return routes; + } +} + +class HealthDartnessController extends DartnessController { + HealthDartnessController(HealthController controller) + : super( + controller, + controller.getRoutes(), + ); +} diff --git a/examples/dartness_simple/lib/src/controllers/user/user_controller.dart b/examples/dartness_simple/lib/src/controllers/user/user_controller.dart new file mode 100644 index 00000000..26968d2b --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/user/user_controller.dart @@ -0,0 +1,17 @@ +import 'dart:io'; + +import 'package:dartness_server/route.dart'; + +part 'user_controller.g.dart'; + +@Controller('/users') +@Header(HttpHeaders.contentTypeHeader, 'application/json') +class UserController { + @HttpCode(202) + @Get() + List getCities({ + @QueryParam() int? offset, + }) { + return ['user1', 'user2']; + } +} diff --git a/examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart b/examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart new file mode 100644 index 00000000..f90ea1c9 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/user/user_controller.g.dart @@ -0,0 +1,43 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'user_controller.dart'; + +// ************************************************************************** +// ControllerGenerator +// ************************************************************************** + +extension UserControllerRoutes on UserController { + List getRoutes() { + final routes = []; + routes.add(ControllerRoute( + method: 'GET', + path: '/users', + handler: getCities, + params: [ + DartnessParam( + name: 'offset', + isQuery: true, + isPath: false, + isBody: false, + isNamed: true, + isPositional: false, + isOptional: true, + type: int, + defaultValue: null, + fromJson: null, + ) + ], + httpCode: 202, + headers: {'content-type': 'application/json'}, + )); + return routes; + } +} + +class UserDartnessController extends DartnessController { + UserDartnessController(UserController controller) + : super( + controller, + controller.getRoutes(), + ); +} diff --git a/examples/dartness_simple/lib/src/controllers/user/user_module.dart b/examples/dartness_simple/lib/src/controllers/user/user_module.dart new file mode 100644 index 00000000..55d5dbd4 --- /dev/null +++ b/examples/dartness_simple/lib/src/controllers/user/user_module.dart @@ -0,0 +1,13 @@ +import 'package:dartness_server/modules.dart'; + +import '../user/user_controller.dart'; + +const userModule = Module( + metadata: ModuleMetadata( + controllers: [ + ProviderMetadata( + classType: UserController, + ), + ], + ), +); diff --git a/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart b/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart index dda11ba6..15abaaec 100644 --- a/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart +++ b/examples/dartness_simple/lib/src/error_handlers/example_error_handler.g.dart @@ -9,13 +9,18 @@ part of 'example_error_handler.dart'; extension ExampleErrorHandlerCatchers on ExampleErrorHandler { List getCatchErrors() { final catchErrorHandlers = []; - catchErrorHandlers - .add(DartnessCatchError([NotFoundException], handleNotFoundException)); + catchErrorHandlers.add(DartnessCatchError( + [NotFoundException], + handleNotFoundException, + )); return catchErrorHandlers; } } class ExampleDartnessErrorHandler extends DartnessErrorHandler { ExampleDartnessErrorHandler(ExampleErrorHandler errorHandler) - : super(errorHandler, errorHandler.getCatchErrors()); + : super( + errorHandler, + errorHandler.getCatchErrors(), + ); } diff --git a/examples/dartness_simple/pubspec.yaml b/examples/dartness_simple/pubspec.yaml index 9ed8a8dd..a3b830bd 100644 --- a/examples/dartness_simple/pubspec.yaml +++ b/examples/dartness_simple/pubspec.yaml @@ -9,10 +9,10 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - dartness_server: ^0.4.4-alpha + dartness_server: 0.5.0-alpha dev_dependencies: lints: ^2.1.1 - test: ^1.24.3 - build_runner: ^2.4.5 - dartness_generator: ^0.1.1-alpha + test: ^1.24.7 + build_runner: ^2.4.6 + dartness_generator: 0.5.0-alpha diff --git a/packages/dartness_generator/CHANGELOG.md b/packages/dartness_generator/CHANGELOG.md index d1cc010e..0556fc81 100644 --- a/packages/dartness_generator/CHANGELOG.md +++ b/packages/dartness_generator/CHANGELOG.md @@ -9,4 +9,8 @@ - ## 0.1.2-alpha -- Updated dart sdk to 3.0.0 \ No newline at end of file +- Updated dart sdk to 3.0.0 + +## 0.5.0-alpha + +- Easiest way of creating an app by `@Application` annotation and modules \ No newline at end of file diff --git a/packages/dartness_generator/README.md b/packages/dartness_generator/README.md index eedfa6d0..0c865a69 100644 --- a/packages/dartness_generator/README.md +++ b/packages/dartness_generator/README.md @@ -9,11 +9,11 @@ dartness_generator is used with dartness_server in order to provide the code gen ```yaml dependencies: - dartness_server: ^0.4.3-alpha + dartness_server: ^0.5.0-alpha dev_dependencies: build_runner: ^2.2.0 - dartness_generator: ^0.1.0-alpha + dartness_generator: ^0.4.6-alpha ``` 2. Add the corresponding `part '.g.dart'` to your classes, otherwise the new code won't be generated, you can find an diff --git a/packages/dartness_generator/build.yaml b/packages/dartness_generator/build.yaml index fa0b6273..614d21f3 100644 --- a/packages/dartness_generator/build.yaml +++ b/packages/dartness_generator/build.yaml @@ -1,17 +1,25 @@ builders: controller: target: ":controller_generator" - import: "package:dartness_generator/dartness_generator.dart" + import: "package:dartness_generator/builder.dart" builder_factories: [ "controller" ] - build_extensions: { ".dart": [ ".dartness.g.part" ] } + build_extensions: { ".dart": [ ".g.part" ] } auto_apply: dependents build_to: cache applies_builders: [ "source_gen|combining_builder" ] error_handler: target: ":error_handler_generator" - import: "package:dartness_generator/dartness_generator.dart" + import: "package:dartness_generator/builder.dart" builder_factories: [ "errorHandler" ] - build_extensions: { ".dart": [ ".dartness.g.part" ] } + build_extensions: { ".dart": [ ".g.part" ] } + auto_apply: dependents + build_to: cache + applies_builders: [ "source_gen|combining_builder" ] + application: + target: ":error_handler_generator" + import: "package:dartness_generator/builder.dart" + builder_factories: [ "application" ] + build_extensions: { ".dart": [ ".g.part" ] } auto_apply: dependents build_to: cache applies_builders: [ "source_gen|combining_builder" ] \ No newline at end of file diff --git a/packages/dartness_generator/doc/api/__404error.html b/packages/dartness_generator/doc/api/__404error.html index 2dae4d3a..cc5f1874 100644 --- a/packages/dartness_generator/doc/api/__404error.html +++ b/packages/dartness_generator/doc/api/__404error.html @@ -4,7 +4,7 @@ - + dartness_generator - Dart API docs @@ -65,20 +65,22 @@

404: Something's gone wrong :-(