Skip to content

Commit

Permalink
Bugfix (issue #7) json_rest_server status version error
Browse files Browse the repository at this point in the history
  • Loading branch information
repoadf committed Mar 31, 2023
1 parent dda0501 commit ea17ae5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 16 additions & 0 deletions backend/database.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 25 additions & 5 deletions lib/src/commands/version_command.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:convert';
import 'dart:io';

import 'package:args/command_runner.dart';

class VersionCommand extends Command<dynamic> {
final _version = '1.2.2';

@override
String get description => 'Show json rest server version';

Expand All @@ -11,16 +12,35 @@ class VersionCommand extends Command<dynamic> {

@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<String, String> _parsePackagesVersion(String output) {
final lines = LineSplitter.split(output);
final packages = <String, String>{};

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;
}
}
9 changes: 8 additions & 1 deletion lib/src/core/middlewares/auth_middleware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ class AuthMiddleware extends Middlewares {
final body = await request.readAsString();
final bodyData = jsonDecode(body);

final users = _database.getAll('users');
List<Map<String, dynamic>> 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,
Expand Down
16 changes: 16 additions & 0 deletions lib/src/core/templates/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit ea17ae5

Please sign in to comment.