From ea17ae5c5a5429d30e8a0fa77200cdcc856019be Mon Sep 17 00:00:00 2001 From: Rodrigo Rahman Date: Fri, 31 Mar 2023 08:39:20 -0300 Subject: [PATCH] Bugfix (issue https://github.com/rodrigorahman/json_rest_server/issues/7) json_rest_server status version error --- CHANGELOG.md | 6 ++++ backend/database.json | 16 ++++++++++ lib/src/commands/version_command.dart | 30 +++++++++++++++---- lib/src/core/middlewares/auth_middleware.dart | 9 +++++- lib/src/core/templates/templates.dart | 16 ++++++++++ pubspec.yaml | 5 ++-- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41e5856..468d410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.4.1 +- Bugfix (issue https://github.com/rodrigorahman/json_rest_server/issues/7) json_rest_server status version error + +## 1.4.0 +- Support for WebSocket and adding login to another collection to support a possible administrator." + ## 1.3.2 - patch method correction and added options method with cors support diff --git a/backend/database.json b/backend/database.json index 0ff8c6e..cc1ee3d 100644 --- a/backend/database.json +++ b/backend/database.json @@ -13,6 +13,22 @@ "password": "1234" } ], + "adm_users": [ + { + "id": 0, + "name": "Rodrigo Rahman", + "email": "rodrigorahman@academiadoflutter.com.br", + "password": "123", + "profile": "ADMIN" + }, + { + "id": 1, + "name": "Guilherme", + "email": "Guilherme@gmail.com", + "password": "1234", + "profile": "SUPORTE" + } + ], "products": [ { "id": 0, diff --git a/lib/src/commands/version_command.dart b/lib/src/commands/version_command.dart index e69d7ac..2a39ecd 100644 --- a/lib/src/commands/version_command.dart +++ b/lib/src/commands/version_command.dart @@ -1,8 +1,9 @@ +import 'dart:convert'; +import 'dart:io'; + import 'package:args/command_runner.dart'; class VersionCommand extends Command { - final _version = '1.2.2'; - @override String get description => 'Show json rest server version'; @@ -11,16 +12,35 @@ class VersionCommand extends Command { @override void run() { + final result = Process.runSync('dart', ['pub', 'global', 'list']); + final packages = _parsePackagesVersion(result.stdout.toString()); + final version = packages['json_rest_server']; + print(''); print(''' - ██╗███████╗ ██████╗ ███╗ ██╗ ██████╗ ███████╗███████╗████████╗ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗ + ██╗███████╗ ██████╗ ███╗ ██╗ ██████╗ ███████╗███████╗████████╗ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗ ██║██╔════╝██╔═══██╗████╗ ██║ ██╔══██╗██╔════╝██╔════╝╚══██╔══╝ ██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗ ██║███████╗██║ ██║██╔██╗ ██║ ██████╔╝█████╗ ███████╗ ██║ ███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝ ██ ██║╚════██║██║ ██║██║╚██╗██║ ██╔══██╗██╔══╝ ╚════██║ ██║ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗ ╚█████╔╝███████║╚██████╔╝██║ ╚████║ ██║ ██║███████╗███████║ ██║ ███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║ - ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ + ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ '''); print(''); - print('Version: $_version'); + print('Version: $version'); + } + + Map _parsePackagesVersion(String output) { + final lines = LineSplitter.split(output); + final packages = {}; + + for (final line in lines) { + final parts = line.split(' '); + if (parts.length >= 2) { + final packageName = parts[0]; + final packageVersion = parts[1]; + packages[packageName] = packageVersion; + } + } + return packages; } } diff --git a/lib/src/core/middlewares/auth_middleware.dart b/lib/src/core/middlewares/auth_middleware.dart index d5b1e2b..d280e84 100644 --- a/lib/src/core/middlewares/auth_middleware.dart +++ b/lib/src/core/middlewares/auth_middleware.dart @@ -40,7 +40,14 @@ class AuthMiddleware extends Middlewares { final body = await request.readAsString(); final bodyData = jsonDecode(body); - final users = _database.getAll('users'); + List> users; + final adminLogin = bodyData['admin'] ?? false; + // ADM Suporte + if (adminLogin) { + users = _database.getAll('adm_users'); + } else { + users = _database.getAll('users'); + } if (users.isEmpty) { return Response(500, diff --git a/lib/src/core/templates/templates.dart b/lib/src/core/templates/templates.dart index b035e3e..934e15d 100644 --- a/lib/src/core/templates/templates.dart +++ b/lib/src/core/templates/templates.dart @@ -23,6 +23,22 @@ const String _database = r''' "password": "1234" } ], + "adm_users": [ + { + "id": 1, + "name": "Rodrigo Rahman", + "email": "rodrigorahman@academiadoflutter.com.br", + "password": "123", + "profile": "ADMIN" + }, + { + "id": 2, + "name": "Guilherme", + "email": "Guilherme@gmail.com", + "password": "1234", + "profile": "SUPORTE" + } + ], "products": [ { "id": 0, diff --git a/pubspec.yaml b/pubspec.yaml index 5346145..1e97066 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,8 @@ name: json_rest_server description: A RESTful server based on JSON With this package you can have a fully functional RESTful server with auth, pagination and all the necessaries services do build an application -version: 1.3.1 -homepage: https://github.com/rodrigorahman/json_rest_server +version: 1.4.1 +repository: https://github.com/rodrigorahman/json_rest_server +issue_tracker: https://github.com/rodrigorahman/json_rest_server/issues environment: sdk: '>=2.17.6 <3.0.0'