├── .gitignore ├── .vscode └── launch.json ├── CHANGELOG.md ├── Dockerfile ├── README.md ├── analysis_options.yaml ├── bin ├── backend.dart ├── backend_old.dart └── server ├── db ├── docker-compose.yml └── schema.prisma ├── lib ├── backend.dart └── src │ ├── app_module.dart │ ├── commons │ ├── commons_module.dart │ ├── enums │ │ └── role_enum.dart │ ├── extensions │ │ └── list_extension.dart │ ├── middlewares │ │ └── auth_guard.dart │ └── services │ │ ├── bcrypt │ │ ├── bcrypt_service_interface.dart │ │ └── implementation │ │ │ └── bcrypt_service.dart │ │ ├── database │ │ ├── models │ │ │ └── result_model.dart │ │ ├── mysql │ │ │ └── mysql_database.dart │ │ └── remote_database.dart │ │ ├── dotenv_service.dart │ │ ├── jwt │ │ ├── dart_jsonwebtoken │ │ │ └── jwt_service.dart │ │ └── jwt_service_interface.dart │ │ └── request_extractor │ │ ├── models │ │ └── login_credential.dart │ │ └── request_extractor.dart │ └── modules │ ├── auth │ ├── auth_module.dart │ ├── auth_resource.dart │ ├── controllers │ │ └── auth_controller.dart │ ├── domain │ │ ├── entities │ │ │ └── user_entity.dart │ │ └── repositories │ │ │ └── user_repository_interface.dart │ └── infra │ │ └── data │ │ └── user_repository.dart │ ├── swagger │ ├── swagger_handler.dart │ └── swagger_module.dart │ └── users │ ├── controller │ └── user_controller.dart │ ├── domain │ ├── entities │ │ └── user_enitity.dart │ └── repositories │ │ └── user_repository_interface.dart │ ├── infra │ └── data │ │ └── user_repository.dart │ ├── user_module.dart │ └── user_resource.dart ├── node_modules └── @prisma │ └── engines │ ├── LICENSE │ ├── README.md │ ├── dist │ ├── index.d.ts │ ├── index.js │ └── scripts │ │ ├── postinstall.d.ts │ │ └── postinstall.js │ ├── package.json │ └── scripts │ └── postinstall.js ├── package-lock.json ├── pubspec.lock ├── pubspec.yaml └── specs ├── postman.json ├── src └── user.yaml └── swagger.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | .env* 8 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "backend", 6 | "request": "launch", 7 | "type": "dart", 8 | "program": "bin/backend.dart" 9 | } 10 | ] 11 | } 12 | 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Specify the Dart SDK base image version using dart: (ex: dart:2.12) 2 | FROM dart:stable AS build 3 | 4 | # Resolve app dependencies. 5 | WORKDIR /app 6 | COPY pubspec.* ./ 7 | RUN dart pub get 8 | 9 | # Copy app source code and AOT compile it. 10 | COPY . . 11 | # Ensure packages are still up-to-date if anything has changed 12 | RUN dart pub get --offline 13 | RUN dart compile exe bin/backend.dart -o bin/server 14 | 15 | # Build minimal serving image from AOT-compiled `/server` and required system 16 | # libraries and configuration files stored in `/runtime/` from the build stage. 17 | FROM scratch 18 | COPY --from=build /runtime/ / 19 | COPY --from=build /app/bin/server / 20 | 21 | # Start server. 22 | EXPOSE 8080 23 | CMD ["/server"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Para iniciar o banco de dados rode o comando com o docker instalado 3 | ```bash 4 | cd db 5 | docker-compose up -d 6 | ``` 7 | Para criar as tabelas no banco de dados configure o arquivo `db/schema.prisma` na propriedade url, colocando o `usuario:senha@servidor:porta/nome_database` 8 | 9 | ```prisma 10 | datasource db { 11 | provider = "mysql" 12 | url = "mysql://root:123456@localhost:3306/dart_backend" 13 | } 14 | ``` 15 | Após a configuração rode em seu terminal 16 | 17 | ! Para instalação do prisma acesse https://www.prisma.io/ 18 | ```bash 19 | prisma db pull 20 | ``` 21 | 22 | Configure o `.env` com suas credenciais 23 | ```.env 24 | host=localhost 25 | port=3306 26 | user=root 27 | password=123456 28 | db=dart_backend 29 | ``` 30 | 31 | Para executar o serviço basta rodar 32 | ``` 33 | dart run bin/backend.dart 34 | ``` 35 | 36 | Para ler a documentação da API acesse `http://localhost:8080/swagger/`d 37 | 38 | Para compilar o serviço no docker basta rodar 39 | ```bash 40 | docker build -t backend-dart . 41 | docker run --rm -p 8080:8080 -v /C/projetos/dart/backend/.env-prod:/.env backend-dart 42 | ``` 43 | 44 | Ou para compilar o serviço pelo bash 45 | ```bash 46 | dart pub get --offline 47 | dart compile exe bin/backend.dart -o bin/server 48 | ./bin/server 49 | ``` -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /bin/backend.dart: -------------------------------------------------------------------------------- 1 | import 'package:backend/backend.dart'; 2 | import 'package:shelf/shelf_io.dart' as shelf_io; 3 | 4 | void main() async { 5 | final handler = await startShelfModular(); 6 | var server = await shelf_io.serve(handler, 'localhost', 8080); 7 | print('Serving at http://${server.address.host}:${server.port}'); 8 | } 9 | -------------------------------------------------------------------------------- /bin/backend_old.dart: -------------------------------------------------------------------------------- 1 | import 'package:shelf/shelf.dart'; 2 | import 'package:shelf/shelf_io.dart' as shelf_io; 3 | import 'package:shelf_router/shelf_router.dart'; 4 | 5 | void main() async { 6 | final app = Router(); 7 | app.get('/', _handleInitial); 8 | app.get('/user', _handleUser); 9 | app.post('/user', _handlePostUser); 10 | app.get('/teste', _handleTest); 11 | 12 | final pipeline = Pipeline() // 13 | .addMiddleware(logRequests()) 14 | .addMiddleware(addJsonType()) 15 | .addHandler(app); 16 | 17 | var server = await shelf_io.serve( 18 | pipeline, 19 | 'localhost', 20 | 8080, 21 | ); 22 | 23 | print('Serving at http://${server.address.host}:${server.port}'); 24 | } 25 | 26 | Middleware addJsonType() { 27 | return (handle) { 28 | return (request) async { 29 | var response = await handle(request); 30 | 31 | response = response.change(headers: { 32 | 'content-type': 'application/json', 33 | }); 34 | return response; 35 | }; 36 | }; 37 | } 38 | 39 | Response _handleInitial(Request request) { 40 | return Response.ok('''{ 41 | messagss: 'Rota inicial' 42 | }'''); 43 | } 44 | 45 | Response _handleUser(Request request) { 46 | return Response.ok('''{ 47 | messagss: 'Usuario' 48 | }'''); 49 | } 50 | 51 | Response _handlePostUser(Request request) { 52 | return Response(201, body: '''{ 53 | messagss: 'Criado' 54 | }'''); 55 | } 56 | 57 | Response _handleTest(Request request) { 58 | return Response.ok('''{ 59 | messagss: 'Teste' 60 | }'''); 61 | } 62 | -------------------------------------------------------------------------------- /bin/server: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toshiossada/dart_backend/db8f75039e6b7f602c78744371bd5d6db8a0b572/bin/server -------------------------------------------------------------------------------- /db/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | mysqlsrv: 5 | image: mysql:latest 6 | environment: 7 | MYSQL_ROOT_PASSWORD: "123456" 8 | MYSQL_DATABASE: "dart_backend" 9 | ports: 10 | - "3306:3306" 11 | 12 | networks: 13 | - mysql-compose-network 14 | 15 | 16 | 17 | networks: 18 | mysql-compose-network: 19 | driver: bridge 20 | -------------------------------------------------------------------------------- /db/schema.prisma: -------------------------------------------------------------------------------- 1 | datasource db { 2 | provider = "mysql" 3 | url = "mysql://root:123456@localhost:3306/dart_backend" 4 | } 5 | 6 | 7 | model User { 8 | id Int @id @default(autoincrement()) 9 | name String 10 | email String @unique 11 | password String 12 | role UserRole @default(user) 13 | } 14 | 15 | 16 | enum UserRole { 17 | admin 18 | user 19 | manager 20 | } -------------------------------------------------------------------------------- /lib/backend.dart: -------------------------------------------------------------------------------- 1 | import 'package:shelf/shelf.dart'; 2 | import 'package:shelf_modular/shelf_modular.dart'; 3 | 4 | import 'src/app_module.dart'; 5 | 6 | Future startShelfModular() async { 7 | final modularHandler = Modular( 8 | module: AppModule(), // Initial Module 9 | middlewares: [ 10 | logRequests(), // Middleware Pipeline 11 | addJsonType(), 12 | ], 13 | ); 14 | 15 | return modularHandler; 16 | } 17 | 18 | Middleware addJsonType() { 19 | return (handle) { 20 | return (request) async { 21 | //Before 22 | var response = await handle(request); 23 | //After 24 | 25 | response = response.change(headers: { 26 | 'content-type': 'application/json', 27 | ...response.headers, 28 | }); 29 | 30 | return response; 31 | }; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/app_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:shelf/shelf.dart'; 2 | import 'package:shelf_modular/shelf_modular.dart'; 3 | 4 | import 'commons/commons_module.dart'; 5 | import 'commons/services/bcrypt/bcrypt_service_interface.dart'; 6 | import 'commons/services/bcrypt/implementation/bcrypt_service.dart'; 7 | import 'commons/services/database/mysql/mysql_database.dart'; 8 | import 'commons/services/database/remote_database.dart'; 9 | import 'commons/services/dotenv_service.dart'; 10 | import 'commons/services/jwt/dart_jsonwebtoken/jwt_service.dart'; 11 | import 'commons/services/jwt/jwt_service_interface.dart'; 12 | import 'commons/services/request_extractor/request_extractor.dart'; 13 | import 'modules/auth/auth_module.dart'; 14 | import 'modules/swagger/swagger_module.dart'; 15 | import 'modules/users/user_module.dart'; 16 | 17 | class AppModule extends Module { 18 | @override 19 | // TODO: implement imports 20 | List get imports => [ 21 | CommonsModule(), 22 | ]; 23 | 24 | @override 25 | List get binds => [ 26 | Bind.singleton((i) => DotEnvService()), 27 | Bind.singleton( 28 | (i) => MysqlDatabase(dotenvService: i())), 29 | Bind.singleton((i) => BCryptService()), 30 | Bind.singleton((i) => JwtService(i())), 31 | Bind.singleton((i) => RequestExtractor()), 32 | ]; 33 | 34 | @override 35 | List get routes => [ 36 | Route.get('/', () => Response.ok('OK!')), 37 | Route.module('/auth', module: AuthModule()), 38 | Route.module('/user', module: UserModule()), 39 | Route.module('/swagger', module: SwaggerModule()), 40 | ]; 41 | } 42 | -------------------------------------------------------------------------------- /lib/src/commons/commons_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:backend/src/commons/services/dotenv_service.dart'; 2 | import 'package:shelf_modular/shelf_modular.dart'; 3 | 4 | import 'services/bcrypt/bcrypt_service_interface.dart'; 5 | import 'services/bcrypt/implementation/bcrypt_service.dart'; 6 | import 'services/database/mysql/mysql_database.dart'; 7 | import 'services/database/remote_database.dart'; 8 | import 'services/jwt/dart_jsonwebtoken/jwt_service.dart'; 9 | import 'services/jwt/jwt_service_interface.dart'; 10 | import 'services/request_extractor/request_extractor.dart'; 11 | 12 | class CommonsModule extends Module { 13 | @override 14 | List get binds => [ 15 | Bind.singleton((i) => DotEnvService(), export: true), 16 | Bind.singleton( 17 | (i) => MysqlDatabase(dotenvService: i()), 18 | export: true), 19 | Bind.singleton((i) => BCryptService(), export: true), 20 | Bind.singleton((i) => JwtService(i()), export: true), 21 | Bind.singleton((i) => RequestExtractor(), 22 | export: true), 23 | ]; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/commons/enums/role_enum.dart: -------------------------------------------------------------------------------- 1 | enum RoleEnum { 2 | admin, 3 | user, 4 | manager; 5 | 6 | @override 7 | String toString() { 8 | switch (this) { 9 | case RoleEnum.admin: 10 | return 'admin'; 11 | case RoleEnum.user: 12 | return 'user'; 13 | case RoleEnum.manager: 14 | return 'manager'; 15 | } 16 | } 17 | } 18 | 19 | RoleEnum toRoleEnum(String str) { 20 | switch (str) { 21 | case 'admin': 22 | return RoleEnum.admin; 23 | case 'user': 24 | return RoleEnum.user; 25 | case 'manager': 26 | default: 27 | return RoleEnum.manager; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/commons/extensions/list_extension.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | extension ListJson on List { 4 | toJson() => jsonEncode(map((e) => e.toMap()).toList()); 5 | } 6 | -------------------------------------------------------------------------------- /lib/src/commons/middlewares/auth_guard.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:shelf/shelf.dart'; 4 | import 'package:shelf_modular/shelf_modular.dart'; 5 | 6 | import '../services/jwt/dart_jsonwebtoken/jwt_service.dart'; 7 | import '../services/request_extractor/request_extractor.dart'; 8 | 9 | class AuthGuard extends ModularMiddleware { 10 | final List roles; 11 | final bool isRefreshToken; 12 | 13 | AuthGuard({this.roles = const [], this.isRefreshToken = false}); 14 | 15 | @override 16 | Handler call(Handler handler, [ModularRoute? route]) { 17 | final extrator = Modular.get(); 18 | final jwt = Modular.get(); 19 | 20 | return (request) { 21 | if (!request.headers.containsKey('authorization')) { 22 | return Response.forbidden( 23 | jsonEncode({'error': 'not authorization header'})); 24 | } 25 | 26 | final token = extrator.getAuthorizationBearer(request); 27 | if (token == null) { 28 | return Response.forbidden(jsonEncode({'error': 'Token invalido'})); 29 | } 30 | try { 31 | jwt.verifyToken(token, isRefreshToken ? 'refreshToken' : 'accessToken'); 32 | final payload = jwt.getPayload(token); 33 | final role = payload['role'] ?? 'user'; 34 | 35 | if (roles.isEmpty || roles.contains(role)) { 36 | return handler(request); 37 | } 38 | 39 | return Response.forbidden( 40 | jsonEncode({'error': 'role ($role) not allowed'})); 41 | } catch (e) { 42 | return Response.forbidden(jsonEncode({'error': e.toString()})); 43 | } 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/src/commons/services/bcrypt/bcrypt_service_interface.dart: -------------------------------------------------------------------------------- 1 | abstract class IBCryptService { 2 | String gernerateHase(String text); 3 | bool checkHash(String text, String hash); 4 | } 5 | -------------------------------------------------------------------------------- /lib/src/commons/services/bcrypt/implementation/bcrypt_service.dart: -------------------------------------------------------------------------------- 1 | import 'package:bcrypt/bcrypt.dart'; 2 | 3 | import '../bcrypt_service_interface.dart'; 4 | 5 | class BCryptService implements IBCryptService { 6 | @override 7 | String gernerateHase(String text) => BCrypt.hashpw(text, BCrypt.gensalt()); 8 | 9 | @override 10 | bool checkHash(String text, String hash) => BCrypt.checkpw(text, hash); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/commons/services/database/models/result_model.dart: -------------------------------------------------------------------------------- 1 | class ResultModel { 2 | final int? insertId; 3 | final int? affectedRows; 4 | final int? numOfRows; 5 | final List> rows; 6 | 7 | ResultModel({ 8 | this.insertId, 9 | this.affectedRows, 10 | this.numOfRows, 11 | required this.rows, 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/commons/services/database/mysql/mysql_database.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:mysql_client/mysql_client.dart'; 4 | import 'package:shelf_modular/shelf_modular.dart'; 5 | 6 | import '../../dotenv_service.dart'; 7 | import '../models/result_model.dart'; 8 | import '../remote_database.dart'; 9 | 10 | class MysqlDatabase implements RemoteDatabase, Disposable { 11 | final DotEnvService dotenvService; 12 | final completer = Completer(); 13 | 14 | MysqlDatabase({ 15 | required this.dotenvService, 16 | }) { 17 | _init(); 18 | } 19 | 20 | _init() async { 21 | final conn = await MySQLConnection.createConnection( 22 | host: dotenvService.host, 23 | port: dotenvService.port, 24 | userName: dotenvService.user, 25 | password: dotenvService.password, 26 | databaseName: dotenvService.db, 27 | ); 28 | await conn.connect(); 29 | completer.complete(conn); 30 | } 31 | 32 | @override 33 | Future query(String query, 34 | [Map? values]) async { 35 | try { 36 | final conn = await completer.future; 37 | 38 | var results = await conn.execute(query, values); 39 | 40 | final result = ResultModel( 41 | rows: results.rows.map((e) => e.typedAssoc()).toList(), 42 | affectedRows: results.affectedRows.toInt(), 43 | insertId: results.lastInsertID.toInt(), 44 | numOfRows: results.numOfRows, 45 | ); 46 | return result; 47 | } catch (e) { 48 | rethrow; 49 | } 50 | } 51 | 52 | @override 53 | Future dispose() async { 54 | final conn = await completer.future; 55 | conn.close(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lib/src/commons/services/database/remote_database.dart: -------------------------------------------------------------------------------- 1 | import 'models/result_model.dart'; 2 | 3 | abstract class RemoteDatabase { 4 | Future query( 5 | String query, [ 6 | Map? values, 7 | ]); 8 | } 9 | -------------------------------------------------------------------------------- /lib/src/commons/services/dotenv_service.dart: -------------------------------------------------------------------------------- 1 | import 'package:dotenv/dotenv.dart'; 2 | 3 | class DotEnvService { 4 | DotEnvService([Map? mocks]) { 5 | if (mocks == null) { 6 | dotEnv = DotEnv()..load(); 7 | _init(dotEnv: dotEnv); 8 | } else { 9 | _init(map: mocks); 10 | } 11 | } 12 | 13 | late final DotEnv dotEnv; 14 | 15 | _init({DotEnv? dotEnv, Map? map}) { 16 | if (dotEnv != null) { 17 | host = dotEnv['host'] ?? ''; 18 | port = int.parse(dotEnv['port'] ?? '0'); 19 | user = dotEnv['user'] ?? ''; 20 | password = dotEnv['password'] ?? ''; 21 | db = dotEnv['db'] ?? ''; 22 | jwtKey = dotEnv['JWT_KEY'] ?? ''; 23 | } else { 24 | host = map?['host'] ?? ''; 25 | port = int.parse(map?['port'] ?? '0'); 26 | user = map?['user'] ?? ''; 27 | password = map?['password'] ?? ''; 28 | db = map?['db'] ?? ''; 29 | jwtKey = map?['JWT_KEY'] ?? ''; 30 | } 31 | } 32 | 33 | late final String host; 34 | late final int port; 35 | late final String user; 36 | late final String password; 37 | late final String db; 38 | late final String jwtKey; 39 | } 40 | -------------------------------------------------------------------------------- /lib/src/commons/services/jwt/dart_jsonwebtoken/jwt_service.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart'; 3 | 4 | import '../../dotenv_service.dart'; 5 | import '../jwt_service_interface.dart'; 6 | 7 | class JwtService implements IJwtService { 8 | final DotEnvService dotEnvService; 9 | 10 | JwtService(this.dotEnvService); 11 | 12 | @override 13 | String generateToken(Map claims, String audiance) { 14 | final jwt = JWT(claims, audience: Audience.one(audiance),); 15 | final token = jwt.sign(SecretKey(dotEnvService.jwtKey)); 16 | return token; 17 | } 18 | 19 | @override 20 | void verifyToken(String token, String audiance) { 21 | JWT.verify( 22 | token, 23 | SecretKey(dotEnvService.jwtKey), 24 | audience: Audience.one(audiance), 25 | ); 26 | } 27 | 28 | @override 29 | Map getPayload(String token) { 30 | final jwt = JWT.verify( 31 | token, 32 | SecretKey(dotEnvService.jwtKey), 33 | checkExpiresIn: false, 34 | checkHeaderType: false, 35 | checkNotBefore: false, 36 | ); 37 | 38 | return jwt.payload; 39 | } 40 | } -------------------------------------------------------------------------------- /lib/src/commons/services/jwt/jwt_service_interface.dart: -------------------------------------------------------------------------------- 1 | abstract class IJwtService { 2 | String generateToken(Map claims, String audiance); 3 | void verifyToken(String token, String audiance); 4 | Map getPayload(String token); 5 | } 6 | -------------------------------------------------------------------------------- /lib/src/commons/services/request_extractor/models/login_credential.dart: -------------------------------------------------------------------------------- 1 | class LoginCredential { 2 | final String email; 3 | final String password; 4 | 5 | LoginCredential({required this.email, required this.password}); 6 | } 7 | -------------------------------------------------------------------------------- /lib/src/commons/services/request_extractor/request_extractor.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:shelf/shelf.dart'; 4 | 5 | import 'models/login_credential.dart'; 6 | 7 | class RequestExtractor { 8 | String? getAuthorizationBearer(Request request) { 9 | final authorization = request.headers['authorization'] ?? ''; 10 | 11 | final parts = authorization.split(' '); 12 | if (parts.length != 2 || parts[0].toLowerCase() != 'bearer') { 13 | return null; 14 | } 15 | return parts.last; 16 | } 17 | 18 | LoginCredential? getAuthorizationBasic(Request request) { 19 | var authorization = request.headers['authorization'] ?? ''; 20 | 21 | final parts = authorization.split(' '); 22 | if (parts.length != 2 || parts[0].toLowerCase() != 'basic') { 23 | return null; 24 | } 25 | authorization = authorization.split(' ').last; 26 | authorization = String.fromCharCodes(base64Decode(authorization)); 27 | final credential = authorization.split(':'); 28 | return LoginCredential( 29 | email: credential.first, 30 | password: credential.last, 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/modules/auth/auth_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:shelf_modular/shelf_modular.dart'; 2 | 3 | import 'auth_resource.dart'; 4 | import 'controllers/auth_controller.dart'; 5 | import 'domain/repositories/user_repository_interface.dart'; 6 | import 'infra/data/user_repository.dart'; 7 | 8 | class AuthModule extends Module { 9 | @override 10 | List get binds => [ 11 | Bind.factory((i) => AuthController( 12 | bCrypt: i(), 13 | jwtService: i(), 14 | requestExtractor: i(), 15 | userRepository: i(), 16 | )), 17 | Bind.factory((i) => UserRepository(database: i())) 18 | ]; 19 | 20 | @override 21 | List get routes => [ 22 | Route.resource(AuthResource()), 23 | ]; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/modules/auth/auth_resource.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:shelf/shelf.dart'; 4 | import 'package:shelf_modular/shelf_modular.dart'; 5 | 6 | import '../../commons/middlewares/auth_guard.dart'; 7 | import 'controllers/auth_controller.dart'; 8 | 9 | class AuthResource extends Resource { 10 | @override 11 | List get routes => [ 12 | Route.get('/login', _login), 13 | Route.get('/refresh_token', _refreshToken, 14 | middlewares: [AuthGuard(isRefreshToken: true)]), 15 | Route.get('/check_token', _checkToken, middlewares: [AuthGuard()]), 16 | ]; 17 | 18 | FutureOr _login(Request request, Injector injector) { 19 | final controller = injector.get(); 20 | 21 | return controller.login(request); 22 | } 23 | 24 | FutureOr _refreshToken(Request request, Injector injector) { 25 | final controller = injector.get(); 26 | 27 | return controller.refresh(request); 28 | } 29 | 30 | FutureOr _checkToken(Request request, Injector injector) { 31 | final controller = injector.get(); 32 | 33 | return controller.checkToken(request); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/modules/auth/controllers/auth_controller.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:convert'; 3 | 4 | import 'package:backend/src/commons/services/jwt/jwt_service_interface.dart'; 5 | import 'package:backend/src/commons/services/request_extractor/request_extractor.dart'; 6 | import 'package:shelf/shelf.dart'; 7 | 8 | import '../../../commons/services/bcrypt/implementation/bcrypt_service.dart'; 9 | import '../domain/entities/user_entity.dart'; 10 | import '../domain/repositories/user_repository_interface.dart'; 11 | 12 | class AuthController { 13 | final RequestExtractor _requestExtractor; 14 | final IJwtService _jwtService; 15 | final BCryptService _bCrypt; 16 | final IUserRepository _userRepository; 17 | 18 | const AuthController({ 19 | required RequestExtractor requestExtractor, 20 | required BCryptService bCrypt, 21 | required IUserRepository userRepository, 22 | required IJwtService jwtService, 23 | }) : _requestExtractor = requestExtractor, 24 | _bCrypt = bCrypt, 25 | _userRepository = userRepository, 26 | _jwtService = jwtService; 27 | 28 | FutureOr login(Request request) async { 29 | final credential = _requestExtractor.getAuthorizationBasic(request); 30 | if (credential == null) { 31 | return Response.forbidden(jsonEncode({'error': 'Token invalido'})); 32 | } 33 | final user = await _userRepository.getByEmail(credential.email); 34 | 35 | final error = jsonEncode( 36 | {'error': 'Email ou senha invalidos'}, 37 | ); 38 | if (user == null) { 39 | return Response.forbidden(error); 40 | } else if (!_bCrypt.checkHash(credential.password, user.password)) { 41 | return Response.forbidden(error); 42 | } else { 43 | return Response.ok(jsonEncode(_generateToken(user))); 44 | } 45 | } 46 | 47 | FutureOr checkToken(Request request) async { 48 | final token = _requestExtractor.getAuthorizationBearer(request); 49 | if (token == null) { 50 | return Response.forbidden(jsonEncode({'error': 'Token invalido'})); 51 | } 52 | final payload = _jwtService.getPayload(token); 53 | 54 | return Response.ok(jsonEncode(payload)); 55 | } 56 | 57 | FutureOr refresh(Request request) async { 58 | final token = _requestExtractor.getAuthorizationBearer(request); 59 | if (token == null) { 60 | return Response.forbidden(jsonEncode({'error': 'Token invalido'})); 61 | } 62 | final payload = _jwtService.getPayload(token); 63 | final user = await _userRepository.getById(payload['id']); 64 | if (user == null) { 65 | return Response.forbidden({'error': 'Email ou senha invalidos'}); 66 | } 67 | 68 | return Response.ok(jsonEncode(_generateToken(user))); 69 | } 70 | 71 | Map _generateToken(UserEntity user) { 72 | final claims = user.toMap(); 73 | claims['exp'] = _expiration(Duration(minutes: 10)); 74 | final accessToken = _jwtService.generateToken(claims, 'accessToken'); 75 | claims['exp'] = _expiration(Duration(days: 10)); 76 | final refreshToken = _jwtService.generateToken(claims, 'refreshToken'); 77 | 78 | return { 79 | 'accessToken': accessToken, 80 | 'refreshToken': refreshToken, 81 | }; 82 | } 83 | 84 | int _expiration(Duration duration) { 85 | final expiresDate = DateTime.now().add(duration); 86 | return Duration(milliseconds: expiresDate.millisecondsSinceEpoch).inSeconds; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lib/src/modules/auth/domain/entities/user_entity.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import '../../../../commons/enums/role_enum.dart'; 4 | 5 | class UserEntity { 6 | final int id; 7 | final String name; 8 | final String email; 9 | final String password; 10 | final RoleEnum _role; 11 | 12 | 13 | 14 | UserEntity({ 15 | required this.id, 16 | required this.name, 17 | required this.email, 18 | required this.password, 19 | required RoleEnum role, 20 | }) : _role = role; 21 | 22 | Map toMap() { 23 | return { 24 | 'id': id, 25 | 'name': name, 26 | 'email': email, 27 | 'role': _role.toString(), 28 | }; 29 | } 30 | 31 | factory UserEntity.fromMap(Map map) { 32 | return UserEntity( 33 | id: map['id']?.toInt() ?? 0, 34 | name: map['name'] ?? '', 35 | email: map['email'] ?? '', 36 | password: map['password'] ?? '', 37 | role: toRoleEnum(map['role'] ?? ''), 38 | ); 39 | } 40 | 41 | String toJson() => json.encode(toMap()); 42 | 43 | factory UserEntity.fromJson(String source) => 44 | UserEntity.fromMap(json.decode(source)); 45 | 46 | UserEntity copyWith({ 47 | int? id, 48 | String? name, 49 | String? email, 50 | String? password, 51 | RoleEnum? role, 52 | }) { 53 | return UserEntity( 54 | id: id ?? this.id, 55 | name: name ?? this.name, 56 | email: email ?? this.email, 57 | password: password ?? this.password, 58 | role: role ?? _role, 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/modules/auth/domain/repositories/user_repository_interface.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import '../entities/user_entity.dart'; 4 | 5 | abstract class IUserRepository { 6 | FutureOr getByEmail(String email); 7 | FutureOr getById(int id); 8 | } 9 | -------------------------------------------------------------------------------- /lib/src/modules/auth/infra/data/user_repository.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import '../../../../commons/services/database/remote_database.dart'; 4 | import '../../domain/entities/user_entity.dart'; 5 | import '../../domain/repositories/user_repository_interface.dart'; 6 | 7 | class UserRepository implements IUserRepository { 8 | final RemoteDatabase _database; 9 | 10 | UserRepository({ 11 | required RemoteDatabase database, 12 | }) : _database = database; 13 | 14 | @override 15 | FutureOr getByEmail(String email) async { 16 | var query = ''' 17 | SELECT 18 | id, 19 | name, 20 | email, 21 | password, 22 | role 23 | FROM User 24 | WHERE email = :email'''; 25 | 26 | final result = await _database.query( 27 | query, 28 | { 29 | "email": email, 30 | }, 31 | ); 32 | if (result.rows.isEmpty) return null; 33 | 34 | var row = result.rows.first; 35 | var user = UserEntity.fromMap(row); 36 | 37 | return user; 38 | } 39 | 40 | @override 41 | FutureOr getById(int id) async { 42 | var query = ''' 43 | SELECT 44 | id, 45 | name, 46 | email, 47 | password, 48 | role 49 | FROM User 50 | WHERE id = :id'''; 51 | 52 | final result = await _database.query( 53 | query, 54 | { 55 | "id": id, 56 | }, 57 | ); 58 | if (result.rows.isEmpty) return null; 59 | 60 | var row = result.rows.first; 61 | var user = UserEntity.fromMap(row); 62 | 63 | return user; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lib/src/modules/swagger/swagger_handler.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:shelf/shelf.dart'; 4 | import 'package:shelf_swagger_ui/shelf_swagger_ui.dart'; 5 | 6 | FutureOr swaggerHandler(Request request) { 7 | final path = 'specs/swagger.yaml'; 8 | final handler = SwaggerUI( 9 | path, 10 | title: 'Semana do Backend', 11 | deepLink: true, 12 | ); 13 | return handler(request); 14 | } 15 | -------------------------------------------------------------------------------- /lib/src/modules/swagger/swagger_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:shelf_modular/shelf_modular.dart'; 2 | 3 | import 'swagger_handler.dart'; 4 | 5 | class SwaggerModule extends Module { 6 | @override 7 | List get routes => [ 8 | Route.get('/**', swaggerHandler), 9 | ]; 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/modules/users/controller/user_controller.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:convert'; 3 | 4 | import 'package:backend/src/commons/extensions/list_extension.dart'; 5 | import 'package:backend/src/modules/users/domain/entities/user_enitity.dart'; 6 | import 'package:shelf/shelf.dart'; 7 | import 'package:shelf_modular/shelf_modular.dart'; 8 | 9 | import '../../../commons/services/bcrypt/bcrypt_service_interface.dart'; 10 | import '../../../commons/services/jwt/jwt_service_interface.dart'; 11 | import '../../../commons/services/request_extractor/request_extractor.dart'; 12 | import '../domain/repositories/user_repository_interface.dart'; 13 | 14 | class UserController { 15 | final IUserRepository _userRepository; 16 | final IBCryptService _bCryptService; 17 | final RequestExtractor _requestExtractor; 18 | final IJwtService _jwtService; 19 | 20 | UserController({ 21 | required IUserRepository userRepository, 22 | required IBCryptService bCryptService, 23 | required RequestExtractor requestExtractor, 24 | required IJwtService jwtService, 25 | }) : _userRepository = userRepository, 26 | _bCryptService = bCryptService, 27 | _requestExtractor = requestExtractor, 28 | _jwtService = jwtService; 29 | 30 | FutureOr getAllUser() async { 31 | final users = await _userRepository.getUsers(); 32 | 33 | return Response.ok(users.toJson()); 34 | } 35 | 36 | FutureOr getUser(ModularArguments args) async { 37 | final id = int.parse(args.params['id']); 38 | final user = await _userRepository.getUserById(id); 39 | if (user == null) return Response.notFound('Usuario nao encontrado'); 40 | 41 | return Response.ok(user.toJson()); 42 | } 43 | 44 | FutureOr delete(ModularArguments args) async { 45 | final id = int.parse(args.params['id']); 46 | final user = await _userRepository.getUserById(id); 47 | if (user == null) return Response.notFound('Usuario nao encontrado'); 48 | 49 | final deleted = await _userRepository.delete(id); 50 | if (!deleted) { 51 | return Response.internalServerError(); 52 | } else { 53 | return Response.ok('Usuario deletado com sucesso'); 54 | } 55 | } 56 | 57 | FutureOr update(ModularArguments args, Request request) async { 58 | final token = _requestExtractor.getAuthorizationBearer(request); 59 | if (token == null) { 60 | return Response.forbidden(jsonEncode({'error': 'Token invalido'})); 61 | } 62 | final payload = _jwtService.getPayload(token); 63 | 64 | final user = UserEntity.fromMap(args.data); 65 | final id = payload['id']; 66 | 67 | if (int.parse(args.params['id']) != id) { 68 | return Response.internalServerError(body: 'Id nao é o mesmo'); 69 | } 70 | 71 | final foundUserEmail = await _userRepository.getByEmail(user.email); 72 | if (foundUserEmail != null && foundUserEmail.id != id) { 73 | return Response.internalServerError( 74 | body: 'Email ja cadastrado em outro usuario', 75 | ); 76 | } 77 | final hashedUser = user.copyWith( 78 | password: _bCryptService.gernerateHase(user.password), 79 | id: id, 80 | ); 81 | final updated = await _userRepository.update(hashedUser); 82 | return Response.ok(updated.toJson()); 83 | } 84 | 85 | FutureOr updatePassword( 86 | ModularArguments args, Request request) async { 87 | final token = _requestExtractor.getAuthorizationBearer(request); 88 | if (token == null) { 89 | return Response.forbidden(jsonEncode({'error': 'Token invalido'})); 90 | } 91 | final payload = _jwtService.getPayload(token); 92 | 93 | final id = payload['id']; 94 | 95 | if (int.parse(args.params['id']) != id) { 96 | return Response.internalServerError(body: 'Id nao é o mesmo'); 97 | } 98 | 99 | final newPassword = args.data['password']; 100 | await _userRepository.updatePassword( 101 | id, _bCryptService.gernerateHase(newPassword)); 102 | return Response.ok('Senha alterada com sucesso'); 103 | } 104 | 105 | FutureOr createUser(ModularArguments args) async { 106 | final user = UserEntity.fromMap(args.data); 107 | final foundUser = await _userRepository.getByEmail(user.email); 108 | if (foundUser != null) { 109 | return Response.internalServerError( 110 | body: 'Email ja cadastrado', 111 | ); 112 | } 113 | 114 | final hashedUser = 115 | user.copyWith(password: _bCryptService.gernerateHase(user.password)); 116 | final inserted = await _userRepository.insert(hashedUser); 117 | 118 | if (inserted == null) { 119 | return Response.internalServerError(); 120 | } 121 | 122 | return Response.ok(inserted.toJson()); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /lib/src/modules/users/domain/entities/user_enitity.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import '../../../../commons/enums/role_enum.dart'; 4 | 5 | class UserEntity { 6 | final int id; 7 | final String name; 8 | final String password; 9 | final String email; 10 | final RoleEnum _role; 11 | 12 | UserEntity({ 13 | required this.id, 14 | required this.name, 15 | required this.password, 16 | required this.email, 17 | required RoleEnum role, 18 | }) : _role = role; 19 | 20 | Map toMap() { 21 | return { 22 | 'id': id, 23 | 'name': name, 24 | 'email': email, 25 | 'password': password, 26 | 'role': _role.toString(), 27 | }; 28 | } 29 | 30 | factory UserEntity.fromMap(Map map) { 31 | return UserEntity( 32 | id: map['id']?.toInt() ?? 0, 33 | name: map['name'] ?? '', 34 | email: map['email'] ?? '', 35 | password: map['password'] ?? '', 36 | role: toRoleEnum(map['role'] ?? ''), 37 | ); 38 | } 39 | 40 | String toJson() => json.encode(toMap()); 41 | 42 | factory UserEntity.fromJson(String source) => 43 | UserEntity.fromMap(json.decode(source)); 44 | 45 | UserEntity copyWith({ 46 | int? id, 47 | String? name, 48 | String? email, 49 | String? password, 50 | RoleEnum? role, 51 | }) { 52 | return UserEntity( 53 | id: id ?? this.id, 54 | name: name ?? this.name, 55 | password: password ?? this.password, 56 | email: email ?? this.email, 57 | role: role ?? _role, 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/src/modules/users/domain/repositories/user_repository_interface.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import '../../domain/entities/user_enitity.dart'; 4 | 5 | abstract class IUserRepository { 6 | FutureOr> getUsers(); 7 | FutureOr getUserById(int id); 8 | FutureOr delete(int id); 9 | FutureOr update(UserEntity user); 10 | FutureOr insert(UserEntity user); 11 | FutureOr getByEmail(String email); 12 | FutureOr updatePassword(int id, String password); 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/modules/users/infra/data/user_repository.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import '../../../../commons/services/database/remote_database.dart'; 4 | import '../../domain/entities/user_enitity.dart'; 5 | import '../../domain/repositories/user_repository_interface.dart'; 6 | 7 | class UserRepository implements IUserRepository { 8 | final RemoteDatabase _database; 9 | 10 | UserRepository({ 11 | required RemoteDatabase database, 12 | }) : _database = database; 13 | 14 | @override 15 | FutureOr> getUsers() async { 16 | var query = ''' 17 | SELECT 18 | id, 19 | name, 20 | email, 21 | password, 22 | role 23 | FROM User'''; 24 | 25 | final result = await _database.query(query); 26 | if (result.rows.isEmpty) return []; 27 | 28 | var users = result.rows.map((e) => UserEntity.fromMap(e)).toList(); 29 | 30 | return users; 31 | } 32 | 33 | @override 34 | FutureOr getUserById(int id) async { 35 | var query = ''' 36 | SELECT 37 | id, 38 | name, 39 | email, 40 | password, 41 | role 42 | FROM User 43 | WHERE id = :id'''; 44 | 45 | final result = await _database.query( 46 | query, 47 | {"id": id}, 48 | ); 49 | if (result.rows.isEmpty) return null; 50 | 51 | var row = result.rows.first; 52 | 53 | var user = UserEntity.fromMap(row); 54 | 55 | return user; 56 | } 57 | 58 | @override 59 | FutureOr getByEmail(String email) async { 60 | var query = ''' 61 | SELECT 62 | id, 63 | name, 64 | email, 65 | password, 66 | role 67 | FROM User 68 | WHERE email = :email'''; 69 | 70 | final result = await _database.query( 71 | query, 72 | {"email": email}, 73 | ); 74 | if (result.rows.isEmpty) return null; 75 | 76 | var row = result.rows.first; 77 | 78 | var user = UserEntity.fromMap(row); 79 | 80 | return user; 81 | } 82 | 83 | @override 84 | FutureOr delete(int id) async { 85 | var query = ''' 86 | DELETE FROM User 87 | WHERE id = :id'''; 88 | 89 | final result = await _database.query( 90 | query, 91 | {"id": id}, 92 | ); 93 | 94 | return (result.affectedRows ?? 0) > 0; 95 | } 96 | 97 | @override 98 | FutureOr update(UserEntity user) async { 99 | var query = ''' 100 | UPDATE User 101 | SET 102 | name = :name, 103 | email = :email, 104 | password = :password, 105 | role = :role 106 | WHERE id = :id'''; 107 | 108 | await _database.query( 109 | query, 110 | user.toMap(), 111 | ); 112 | 113 | final newUser = await getUserById(user.id); 114 | 115 | return newUser!; 116 | } 117 | 118 | @override 119 | FutureOr updatePassword(int id, String password) async { 120 | var query = ''' 121 | UPDATE User 122 | SET 123 | password = :password 124 | WHERE id = :id'''; 125 | 126 | final result = await _database.query( 127 | query, 128 | { 129 | "password": password, 130 | "id": id, 131 | }, 132 | ); 133 | 134 | return (result.affectedRows ?? 0) > 0; 135 | } 136 | 137 | @override 138 | FutureOr insert(UserEntity user) async { 139 | var query = ''' 140 | INSERT INTO `dart_backend`.`User` 141 | (name, 142 | email, 143 | password, 144 | role) 145 | VALUES 146 | (:name, 147 | :email, 148 | :password, 149 | :role); 150 | '''; 151 | 152 | var result = await _database.query( 153 | query, 154 | user.toMap(), 155 | ); 156 | 157 | if ((result.insertId ?? 0) > 0) { 158 | final newUser = await getUserById(result.insertId!); 159 | 160 | return newUser; 161 | } else { 162 | return null; 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /lib/src/modules/users/user_module.dart: -------------------------------------------------------------------------------- 1 | import 'package:backend/src/modules/users/user_resource.dart'; 2 | import 'package:shelf_modular/shelf_modular.dart'; 3 | 4 | import 'domain/repositories/user_repository_interface.dart'; 5 | import 'infra/data/user_repository.dart'; 6 | import 'controller/user_controller.dart'; 7 | 8 | class UserModule extends Module { 9 | @override 10 | List get binds => [ 11 | Bind.factory((i) => UserController( 12 | userRepository: i(), 13 | bCryptService: i(), 14 | jwtService: i(), 15 | requestExtractor: i(), 16 | )), 17 | Bind.factory((i) => UserRepository(database: i())), 18 | ]; 19 | 20 | @override 21 | List get routes => [ 22 | Route.resource(UserResource()), 23 | ]; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/modules/users/user_resource.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:shelf/shelf.dart'; 4 | import 'package:shelf_modular/shelf_modular.dart'; 5 | 6 | import '../../commons/middlewares/auth_guard.dart'; 7 | import 'controller/user_controller.dart'; 8 | 9 | class UserResource extends Resource { 10 | @override 11 | List get routes => [ 12 | Route.get('/', _getAllUser, middlewares: [AuthGuard()]), 13 | Route.post('/', _createUser), 14 | Route.get('/:id', _getUser, middlewares: [AuthGuard()]), 15 | Route.put('/:id', _update, middlewares: [AuthGuard()]), 16 | Route.delete('/:id', _delete, middlewares: [AuthGuard()]), 17 | Route.path('/:id/password', _updatePassword, 18 | middlewares: [AuthGuard()]), 19 | ]; 20 | 21 | FutureOr _getAllUser(Injector injector) { 22 | final controller = injector.get(); 23 | 24 | return controller.getAllUser(); 25 | } 26 | 27 | FutureOr _getUser(ModularArguments args, Injector injector) { 28 | final controller = injector.get(); 29 | 30 | return controller.getUser(args); 31 | } 32 | 33 | FutureOr _delete(ModularArguments args, Injector injector) { 34 | final controller = injector.get(); 35 | 36 | return controller.delete(args); 37 | } 38 | 39 | FutureOr _update( 40 | ModularArguments args, Injector injector, Request request) { 41 | final controller = injector.get(); 42 | 43 | return controller.update(args, request); 44 | } 45 | 46 | FutureOr _updatePassword( 47 | ModularArguments args, Injector injector, Request request) { 48 | final controller = injector.get(); 49 | 50 | return controller.updatePassword(args, request); 51 | } 52 | 53 | FutureOr _createUser(ModularArguments args, Injector injector) { 54 | final controller = injector.get(); 55 | 56 | return controller.createUser(args); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /node_modules/@prisma/engines/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /node_modules/@prisma/engines/README.md: -------------------------------------------------------------------------------- 1 | # `@prisma/engines` 2 | 3 | This package ships the Prisma Engines, namely the Query Engine, Migration Engine, Introspection Engine and Prisma Format. 4 | The postinstall hook of this package downloads all engines available for the current platform are from the Prisma CDN. 5 | The engines to be downloaded are directly determined by the version of its `@prisma/engines-version` dependency. 6 | 7 | You should probably not use this package directly, but instead use one of these: 8 | 9 | - [`prisma` CLI](https://www.npmjs.com/package/prisma) 10 | - [`@prisma/client`](https://www.npmjs.com/package/@prisma/client) 11 | -------------------------------------------------------------------------------- /node_modules/@prisma/engines/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import { BinaryType } from '@prisma/fetch-engine'; 2 | export declare function getEnginesPath(): string; 3 | export declare const DEFAULT_CLI_QUERY_ENGINE_BINARY_TYPE = BinaryType.libqueryEngine; 4 | /** 5 | * Checks if the env override `PRISMA_CLI_QUERY_ENGINE_TYPE` is set to `library` or `binary` 6 | * Otherwise returns the default 7 | */ 8 | export declare function getCliQueryEngineBinaryType(): BinaryType.libqueryEngine | BinaryType.queryEngine; 9 | export declare function ensureBinariesExist(): Promise; 10 | export { enginesVersion } from '@prisma/engines-version'; 11 | -------------------------------------------------------------------------------- /node_modules/@prisma/engines/dist/scripts/postinstall.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /node_modules/@prisma/engines/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_from": "@prisma/engines@4.1.0", 3 | "_id": "@prisma/engines@4.1.0", 4 | "_inBundle": false, 5 | "_integrity": "sha512-quqHXD3P83NBLVtRlts4SgKHmqgA8GMiyDTJ7af03Wg0gl6F5t65mBYvIuwmD+52vHm42JtIsp/fAO9YIV0JBA==", 6 | "_location": "/@prisma/engines", 7 | "_phantomChildren": {}, 8 | "_requested": { 9 | "type": "version", 10 | "registry": true, 11 | "raw": "@prisma/engines@4.1.0", 12 | "name": "@prisma/engines", 13 | "escapedName": "@prisma%2fengines", 14 | "scope": "@prisma", 15 | "rawSpec": "4.1.0", 16 | "saveSpec": null, 17 | "fetchSpec": "4.1.0" 18 | }, 19 | "_requiredBy": [ 20 | "/prisma" 21 | ], 22 | "_resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.1.0.tgz", 23 | "_shasum": "da8002d4b75c92e3fd564ba5b0bd04847ffb3c4c", 24 | "_spec": "@prisma/engines@4.1.0", 25 | "_where": "C:\\projetos\\dart\\backend\\node_modules\\prisma", 26 | "author": { 27 | "name": "Tim Suchanek", 28 | "email": "suchanek@prisma.io" 29 | }, 30 | "bugs": { 31 | "url": "https://github.com/prisma/prisma/issues" 32 | }, 33 | "bundleDependencies": false, 34 | "deprecated": false, 35 | "description": "This package ships the Prisma Engines, namely the Query Engine, Migration Engine, Introspection Engine and Prisma Format. The postinstall hook of this package downloads all engines available for the current platform are from the Prisma CDN. The engines to be downloaded are directly determined by the version of its `@prisma/engines-version` dependency.", 36 | "devDependencies": { 37 | "@prisma/debug": "4.1.0", 38 | "@prisma/engines-version": "4.1.0-48.8d8414deb360336e4698a65aa45a1fbaf1ce13d8", 39 | "@prisma/fetch-engine": "4.1.0", 40 | "@prisma/get-platform": "4.1.0", 41 | "@swc/core": "1.2.197", 42 | "@swc/jest": "0.2.21", 43 | "@types/jest": "28.1.5", 44 | "@types/node": "16.11.43", 45 | "execa": "5.1.1", 46 | "jest": "28.1.2", 47 | "typescript": "4.7.3" 48 | }, 49 | "files": [ 50 | "dist", 51 | "download", 52 | "scripts" 53 | ], 54 | "homepage": "https://github.com/prisma/prisma#readme", 55 | "license": "Apache-2.0", 56 | "main": "dist/index.js", 57 | "name": "@prisma/engines", 58 | "repository": { 59 | "type": "git", 60 | "url": "git+https://github.com/prisma/prisma.git", 61 | "directory": "packages/engines" 62 | }, 63 | "scripts": { 64 | "build": "node -r esbuild-register helpers/build.ts", 65 | "dev": "DEV=true node -r esbuild-register helpers/build.ts", 66 | "postinstall": "node scripts/postinstall.js", 67 | "test": "jest" 68 | }, 69 | "sideEffects": false, 70 | "types": "dist/index.d.ts", 71 | "version": "4.1.0" 72 | } 73 | -------------------------------------------------------------------------------- /node_modules/@prisma/engines/scripts/postinstall.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const path = require('path') 3 | 4 | // that's the normal path, when users get this package ready/installed 5 | if (fs.existsSync(path.join(__dirname, '../dist/scripts/postinstall.js'))) { 6 | require(path.join(__dirname, '../dist/scripts/postinstall.js')) 7 | } else { 8 | // that's when we develop in the monorepo, `dist` does not exist yet 9 | // so we compile postinstall script and trigger it immediately after 10 | const execa = require('execa') 11 | 12 | void execa.sync('node', ['-r', 'esbuild-register', path.join(__dirname, '../helpers/build.ts')], { 13 | stdio: 'inherit', 14 | cwd: path.join(__dirname, '..'), 15 | env: { 16 | DEV: true, 17 | }, 18 | }) 19 | 20 | require(path.join(__dirname, '../dist/scripts/postinstall.js')) 21 | } 22 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": true, 3 | "lockfileVersion": 1, 4 | "dependencies": { 5 | "@prisma/engines": { 6 | "version": "4.1.0", 7 | "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.1.0.tgz", 8 | "integrity": "sha512-quqHXD3P83NBLVtRlts4SgKHmqgA8GMiyDTJ7af03Wg0gl6F5t65mBYvIuwmD+52vHm42JtIsp/fAO9YIV0JBA==" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "41.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "4.2.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.1" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.9.0" 32 | bcrypt: 33 | dependency: "direct main" 34 | description: 35 | name: bcrypt 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.3" 39 | boolean_selector: 40 | dependency: transitive 41 | description: 42 | name: boolean_selector 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "2.1.0" 46 | buffer: 47 | dependency: transitive 48 | description: 49 | name: buffer 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.1.1" 53 | characters: 54 | dependency: transitive 55 | description: 56 | name: characters 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.2.1" 60 | collection: 61 | dependency: transitive 62 | description: 63 | name: collection 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "1.16.0" 67 | convert: 68 | dependency: transitive 69 | description: 70 | name: convert 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "3.0.2" 74 | coverage: 75 | dependency: transitive 76 | description: 77 | name: coverage 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "1.5.0" 81 | crypto: 82 | dependency: transitive 83 | description: 84 | name: crypto 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "3.0.2" 88 | dart_jsonwebtoken: 89 | dependency: "direct main" 90 | description: 91 | name: dart_jsonwebtoken 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "2.4.1" 95 | dotenv: 96 | dependency: "direct main" 97 | description: 98 | name: dotenv 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "4.0.1" 102 | file: 103 | dependency: transitive 104 | description: 105 | name: file 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "6.1.2" 109 | frontend_server_client: 110 | dependency: transitive 111 | description: 112 | name: frontend_server_client 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "2.1.3" 116 | glob: 117 | dependency: transitive 118 | description: 119 | name: glob 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "2.1.0" 123 | http_methods: 124 | dependency: transitive 125 | description: 126 | name: http_methods 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.1.0" 130 | http_multi_server: 131 | dependency: transitive 132 | description: 133 | name: http_multi_server 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "3.2.1" 137 | http_parser: 138 | dependency: transitive 139 | description: 140 | name: http_parser 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "4.0.1" 144 | io: 145 | dependency: transitive 146 | description: 147 | name: io 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.3" 151 | js: 152 | dependency: transitive 153 | description: 154 | name: js 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "0.6.4" 158 | lints: 159 | dependency: "direct dev" 160 | description: 161 | name: lints 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "2.0.0" 165 | logging: 166 | dependency: transitive 167 | description: 168 | name: logging 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.0.2" 172 | matcher: 173 | dependency: transitive 174 | description: 175 | name: matcher 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "0.12.12" 179 | meta: 180 | dependency: transitive 181 | description: 182 | name: meta 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "1.8.0" 186 | mime: 187 | dependency: transitive 188 | description: 189 | name: mime 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "1.0.2" 193 | modular_core: 194 | dependency: transitive 195 | description: 196 | name: modular_core 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "2.0.3+1" 200 | modular_interfaces: 201 | dependency: transitive 202 | description: 203 | name: modular_interfaces 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "2.0.2" 207 | mysql_client: 208 | dependency: "direct main" 209 | description: 210 | name: mysql_client 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "0.0.24" 214 | node_preamble: 215 | dependency: transitive 216 | description: 217 | name: node_preamble 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "2.0.1" 221 | package_config: 222 | dependency: transitive 223 | description: 224 | name: package_config 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "2.1.0" 228 | path: 229 | dependency: transitive 230 | description: 231 | name: path 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.8.2" 235 | pointycastle: 236 | dependency: transitive 237 | description: 238 | name: pointycastle 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "3.6.1" 242 | pool: 243 | dependency: transitive 244 | description: 245 | name: pool 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "1.5.1" 249 | pub_semver: 250 | dependency: transitive 251 | description: 252 | name: pub_semver 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "2.1.1" 256 | quiver: 257 | dependency: transitive 258 | description: 259 | name: quiver 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "3.1.0" 263 | shelf: 264 | dependency: "direct main" 265 | description: 266 | name: shelf 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.3.1" 270 | shelf_modular: 271 | dependency: "direct main" 272 | description: 273 | name: shelf_modular 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "2.0.0" 277 | shelf_packages_handler: 278 | dependency: transitive 279 | description: 280 | name: shelf_packages_handler 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "3.0.1" 284 | shelf_router: 285 | dependency: "direct main" 286 | description: 287 | name: shelf_router 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "1.1.3" 291 | shelf_static: 292 | dependency: transitive 293 | description: 294 | name: shelf_static 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "1.1.1" 298 | shelf_swagger_ui: 299 | dependency: "direct main" 300 | description: 301 | name: shelf_swagger_ui 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.0.0+2" 305 | shelf_web_socket: 306 | dependency: transitive 307 | description: 308 | name: shelf_web_socket 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "1.0.2" 312 | source_map_stack_trace: 313 | dependency: transitive 314 | description: 315 | name: source_map_stack_trace 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "2.1.0" 319 | source_maps: 320 | dependency: transitive 321 | description: 322 | name: source_maps 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "0.10.10" 326 | source_span: 327 | dependency: transitive 328 | description: 329 | name: source_span 330 | url: "https://pub.dartlang.org" 331 | source: hosted 332 | version: "1.9.0" 333 | stack_trace: 334 | dependency: transitive 335 | description: 336 | name: stack_trace 337 | url: "https://pub.dartlang.org" 338 | source: hosted 339 | version: "1.10.0" 340 | stream_channel: 341 | dependency: transitive 342 | description: 343 | name: stream_channel 344 | url: "https://pub.dartlang.org" 345 | source: hosted 346 | version: "2.1.0" 347 | string_scanner: 348 | dependency: transitive 349 | description: 350 | name: string_scanner 351 | url: "https://pub.dartlang.org" 352 | source: hosted 353 | version: "1.1.1" 354 | term_glyph: 355 | dependency: transitive 356 | description: 357 | name: term_glyph 358 | url: "https://pub.dartlang.org" 359 | source: hosted 360 | version: "1.2.1" 361 | test: 362 | dependency: "direct dev" 363 | description: 364 | name: test 365 | url: "https://pub.dartlang.org" 366 | source: hosted 367 | version: "1.21.4" 368 | test_api: 369 | dependency: transitive 370 | description: 371 | name: test_api 372 | url: "https://pub.dartlang.org" 373 | source: hosted 374 | version: "0.4.12" 375 | test_core: 376 | dependency: transitive 377 | description: 378 | name: test_core 379 | url: "https://pub.dartlang.org" 380 | source: hosted 381 | version: "0.4.16" 382 | tuple: 383 | dependency: transitive 384 | description: 385 | name: tuple 386 | url: "https://pub.dartlang.org" 387 | source: hosted 388 | version: "2.0.0" 389 | typed_data: 390 | dependency: transitive 391 | description: 392 | name: typed_data 393 | url: "https://pub.dartlang.org" 394 | source: hosted 395 | version: "1.3.1" 396 | vm_service: 397 | dependency: transitive 398 | description: 399 | name: vm_service 400 | url: "https://pub.dartlang.org" 401 | source: hosted 402 | version: "9.0.0" 403 | watcher: 404 | dependency: transitive 405 | description: 406 | name: watcher 407 | url: "https://pub.dartlang.org" 408 | source: hosted 409 | version: "1.0.1" 410 | web_socket_channel: 411 | dependency: transitive 412 | description: 413 | name: web_socket_channel 414 | url: "https://pub.dartlang.org" 415 | source: hosted 416 | version: "2.2.0" 417 | webkit_inspection_protocol: 418 | dependency: transitive 419 | description: 420 | name: webkit_inspection_protocol 421 | url: "https://pub.dartlang.org" 422 | source: hosted 423 | version: "1.1.0" 424 | yaml: 425 | dependency: transitive 426 | description: 427 | name: yaml 428 | url: "https://pub.dartlang.org" 429 | source: hosted 430 | version: "3.1.1" 431 | sdks: 432 | dart: ">=2.17.5 <3.0.0" 433 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: backend 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: '>=2.17.5 <3.0.0' 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^2.0.0 14 | test: ^1.16.0 15 | dependencies: 16 | shelf: ^1.3.1 17 | shelf_router: ^1.1.3 18 | shelf_modular: ^2.0.0 19 | dotenv: ^4.0.1 20 | mysql_client: ^0.0.24 21 | shelf_swagger_ui: ^1.0.0+2 22 | bcrypt: ^1.1.3 23 | dart_jsonwebtoken: ^2.4.1 24 | -------------------------------------------------------------------------------- /specs/postman.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "db7d124f-daab-4cd8-9506-42a48394cb1d", 4 | "name": "Dart Backend", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", 6 | "_exporter_id": "1084476" 7 | }, 8 | "item": [ 9 | { 10 | "name": "Auth", 11 | "item": [ 12 | { 13 | "name": "Login", 14 | "request": { 15 | "auth": { 16 | "type": "basic", 17 | "basic": [ 18 | { 19 | "key": "password", 20 | "value": "123456", 21 | "type": "string" 22 | }, 23 | { 24 | "key": "username", 25 | "value": "toshiossada@gmail.com", 26 | "type": "string" 27 | } 28 | ] 29 | }, 30 | "method": "GET", 31 | "header": [], 32 | "url": { 33 | "raw": "localhost:8080/auth/login", 34 | "host": [ 35 | "localhost" 36 | ], 37 | "port": "8080", 38 | "path": [ 39 | "auth", 40 | "login" 41 | ] 42 | } 43 | }, 44 | "response": [] 45 | } 46 | ] 47 | }, 48 | { 49 | "name": "User", 50 | "item": [ 51 | { 52 | "name": "Criar usuario", 53 | "request": { 54 | "method": "POST", 55 | "header": [], 56 | "body": { 57 | "mode": "raw", 58 | "raw": "{\r\n \"name\": \"Ossada123\",\r\n \"email\": \"toshiossada11112111@gmail.com\",\r\n \"password\": \"123456\",\r\n \"role\": \"admin\"\r\n}", 59 | "options": { 60 | "raw": { 61 | "language": "json" 62 | } 63 | } 64 | }, 65 | "url": { 66 | "raw": "localhost:8080/user/", 67 | "host": [ 68 | "localhost" 69 | ], 70 | "port": "8080", 71 | "path": [ 72 | "user", 73 | "" 74 | ] 75 | } 76 | }, 77 | "response": [] 78 | }, 79 | { 80 | "name": "Listar Usuario", 81 | "request": { 82 | "method": "GET", 83 | "header": [], 84 | "url": { 85 | "raw": "localhost:8080/user/", 86 | "host": [ 87 | "localhost" 88 | ], 89 | "port": "8080", 90 | "path": [ 91 | "user", 92 | "" 93 | ] 94 | } 95 | }, 96 | "response": [] 97 | }, 98 | { 99 | "name": "Recuperar Usuario por id", 100 | "request": { 101 | "method": "GET", 102 | "header": [], 103 | "url": { 104 | "raw": "localhost:8080/user/1", 105 | "host": [ 106 | "localhost" 107 | ], 108 | "port": "8080", 109 | "path": [ 110 | "user", 111 | "1" 112 | ] 113 | } 114 | }, 115 | "response": [] 116 | }, 117 | { 118 | "name": "Deletar Usuario", 119 | "request": { 120 | "method": "DELETE", 121 | "header": [], 122 | "url": { 123 | "raw": "localhost:8080/user/8", 124 | "host": [ 125 | "localhost" 126 | ], 127 | "port": "8080", 128 | "path": [ 129 | "user", 130 | "8" 131 | ] 132 | } 133 | }, 134 | "response": [] 135 | }, 136 | { 137 | "name": "Atualizar usuario", 138 | "request": { 139 | "method": "PUT", 140 | "header": [], 141 | "body": { 142 | "mode": "raw", 143 | "raw": "{\r\n \"name\": \"Ossada122223\",\r\n \"email\": \"toshiossada@gmail.com\",\r\n \"password\": \"123456\",\r\n \"role\": \"admin\"\r\n}", 144 | "options": { 145 | "raw": { 146 | "language": "json" 147 | } 148 | } 149 | }, 150 | "url": { 151 | "raw": "localhost:8080/user/1", 152 | "host": [ 153 | "localhost" 154 | ], 155 | "port": "8080", 156 | "path": [ 157 | "user", 158 | "1" 159 | ] 160 | } 161 | }, 162 | "response": [] 163 | } 164 | ] 165 | } 166 | ] 167 | } -------------------------------------------------------------------------------- /specs/src/user.yaml: -------------------------------------------------------------------------------- 1 | components: 2 | schemas: 3 | User: 4 | type: object 5 | properties: 6 | id: 7 | type: integer 8 | name: 9 | type: string 10 | email: 11 | type: string 12 | role: 13 | type: string 14 | default: user 15 | enum: 16 | - 'dev' 17 | - 'admin' 18 | - 'manager' 19 | UserCreate: 20 | type: object 21 | properties: 22 | name: 23 | type: string 24 | email: 25 | type: string 26 | password: 27 | type: string 28 | role: 29 | type: string 30 | default: user 31 | enum: 32 | - 'dev' 33 | - 'admin' 34 | - 'manager' 35 | UserCrud: 36 | get: 37 | tags: 38 | - 'user' 39 | summary: get all user 40 | security: 41 | - bearerAuth: [] 42 | responses: 43 | '200': 44 | description: '' 45 | content: 46 | application/json: 47 | schema: 48 | type: array 49 | items: 50 | $ref: '#/components/schemas/User' 51 | '404': 52 | description: '' 53 | content: 54 | application/json: 55 | schema: 56 | $ref: '../swagger.yaml#/components/schemas/BackendException' 57 | post: 58 | tags: 59 | - 'user' 60 | summary: create new user 61 | 62 | requestBody: 63 | content: 64 | application/json: 65 | schema: 66 | $ref: '#/components/schemas/UserCreate' 67 | responses: 68 | '200': 69 | description: '' 70 | content: 71 | application/json: 72 | schema: 73 | type: array 74 | items: 75 | $ref: '#/components/schemas/User' 76 | '404': 77 | description: '' 78 | content: 79 | application/json: 80 | schema: 81 | $ref: '../swagger.yaml#/components/schemas/BackendException' 82 | GetOneOrDelete: 83 | get: 84 | tags: 85 | - 'user' 86 | security: 87 | - bearerAuth: [] 88 | summary: get user by id 89 | parameters: 90 | - in: path 91 | name: id 92 | required: true 93 | schema: 94 | type: integer 95 | responses: 96 | '200': 97 | description: '' 98 | content: 99 | application/json: 100 | schema: 101 | $ref: '#/components/schemas/User' 102 | '404': 103 | description: '' 104 | content: 105 | application/json: 106 | schema: 107 | $ref: '../swagger.yaml#/components/schemas/BackendException' 108 | delete: 109 | tags: 110 | - 'user' 111 | summary: delete user by id 112 | security: 113 | - bearerAuth: [] 114 | parameters: 115 | - in: path 116 | name: id 117 | required: true 118 | schema: 119 | type: integer 120 | responses: 121 | '200': 122 | description: '' 123 | content: 124 | application/json: 125 | schema: 126 | type: object 127 | properties: 128 | message: 129 | type: string 130 | '404': 131 | description: '' 132 | content: 133 | application/json: 134 | schema: 135 | $ref: '../swagger.yaml#/components/schemas/BackendException' 136 | put: 137 | tags: 138 | - 'user' 139 | summary: Update user 140 | security: 141 | - bearerAuth: [] 142 | requestBody: 143 | content: 144 | application/json: 145 | schema: 146 | $ref: '#/components/schemas/User' 147 | responses: 148 | '200': 149 | description: '' 150 | content: 151 | application/json: 152 | schema: 153 | type: array 154 | items: 155 | $ref: '#/components/schemas/User' 156 | '404': 157 | description: '' 158 | content: 159 | application/json: 160 | schema: 161 | $ref: '../swagger.yaml#/components/schemas/BackendException' 162 | -------------------------------------------------------------------------------- /specs/swagger.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | description: 'API da semana do backend' 4 | version: '1.0.0' 5 | title: 'Semana do Backend' 6 | servers: 7 | - url: http://localhost:8080 8 | description: Local server 9 | - url: http://146.190.226.218:4466 10 | description: Remote server 11 | tags: 12 | - name: 'user' 13 | description: 'Access to User' 14 | 15 | paths: 16 | # user 17 | /user/{id}: 18 | $ref: 'src/user.yaml#/components/GetOneOrDelete' 19 | /user: 20 | $ref: 'src/user.yaml#/components/UserCrud' 21 | 22 | components: 23 | securitySchemes: 24 | basicAuth: 25 | type: http 26 | scheme: basic 27 | bearerAuth: 28 | type: http 29 | scheme: bearer 30 | bearerFormat: JWT 31 | description: 'Auth header (Authorization) Access Token' 32 | bearerRefreshAuth: 33 | type: http 34 | scheme: bearer 35 | bearerFormat: JWT 36 | description: 'RefreshToken' 37 | schemas: 38 | BackendException: 39 | type: object 40 | properties: 41 | error: 42 | type: string 43 | --------------------------------------------------------------------------------