diff --git a/app/Actions/UserAction.php b/app/Actions/UserAction.php new file mode 100644 index 0000000..3851bf2 --- /dev/null +++ b/app/Actions/UserAction.php @@ -0,0 +1,38 @@ +create($params); + } + + public function show($id): User + { + return User::query()->find($id); + } + + public function update(array $params, $id): int + { + return User::query()->find($id)->update($params); + } + + public function delete($id) + { + // TODO: Implement delete() method. + } +} diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php new file mode 100644 index 0000000..e2f9405 --- /dev/null +++ b/app/Http/Controllers/Auth/AuthController.php @@ -0,0 +1,60 @@ +only('email', 'password'); + + if (!auth()->attempt($credentials)) + { + abort(401, 'Inavalid Credentials'); + } + + $user = auth()->user(); + $token = $user->createToken('API Token'); + + return response()->json([ + 'token' => $token->plainTextToken, + 'user' => $user + ], 200); + + } + + public function login2(LoginResquest $request): JsonResponse + { + $credentials = $request->only('email', 'password'); + + if (!auth()->attempt($credentials)) + { + abort(401, 'Inavalid Credentials'); + } + + $request->session()->regenerate(); + + return response()->json([], 200); + + } + + public function logout(Request $request): JsonResponse + { + $requestToken = $request->header('authorization'); + + $token = (new PersonalAccessToken()) + ->findToken(str_replace('Bearer ','', $requestToken)); + + $token->delete(); + + return response()->json([ + 'message' => 'Roken Revoked.' + ], 200); + } +} diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php new file mode 100644 index 0000000..82bd411 --- /dev/null +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -0,0 +1,14 @@ +limit(10)->get(); + + return response()->json($result, 200); + + } + +} diff --git a/app/Http/Controllers/FaqController.php b/app/Http/Controllers/FaqController.php new file mode 100644 index 0000000..2748405 --- /dev/null +++ b/app/Http/Controllers/FaqController.php @@ -0,0 +1,10 @@ +list(); + return response()->json($list, 200); + }catch (\Exception $ex){ + return response()->json(['message' => $ex->getMessage()], 500); + } + + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show($id) + { + // + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id) + { + // + } +} diff --git a/app/Http/Requests/LoginResquest.php b/app/Http/Requests/LoginResquest.php new file mode 100644 index 0000000..a6d9906 --- /dev/null +++ b/app/Http/Requests/LoginResquest.php @@ -0,0 +1,31 @@ + + */ + public function rules() + { + return [ + 'email' => 'required|string|email', + 'password' => 'required|string|min:6', + ]; + } +} diff --git a/app/Http/Requests/RegisterUserResquest.php b/app/Http/Requests/RegisterUserResquest.php new file mode 100644 index 0000000..2363cc6 --- /dev/null +++ b/app/Http/Requests/RegisterUserResquest.php @@ -0,0 +1,30 @@ + + */ + public function rules() + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/UserLoginRequest.php b/app/Http/Requests/UserLoginRequest.php new file mode 100644 index 0000000..98d9e23 --- /dev/null +++ b/app/Http/Requests/UserLoginRequest.php @@ -0,0 +1,30 @@ + + */ + public function rules() + { + return [ + // + ]; + } +} diff --git a/app/Interface/ActionInterface.php b/app/Interface/ActionInterface.php new file mode 100644 index 0000000..907f6d7 --- /dev/null +++ b/app/Interface/ActionInterface.php @@ -0,0 +1,13 @@ +belongsToMany(Permission::class); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 8996368..2950e0a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,15 +2,18 @@ namespace App\Models; -use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; +use OwenIt\Auditing\Contracts\Auditable as Auditing; +use OwenIt\Auditing\Auditable; -class User extends Authenticatable +class User extends Authenticatable implements Auditing { - use HasApiTokens, HasFactory, Notifiable; + use HasApiTokens, HasFactory, Notifiable, SoftDeletes, Auditable; /** * The attributes that are mass assignable. @@ -21,6 +24,9 @@ class User extends Authenticatable 'name', 'email', 'password', + 'created_at', + 'updated_at', + 'deleted_at', ]; /** @@ -41,4 +47,10 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + public function roles(): BelongsToMany + { + return $this->belongsToMany(Role::class); + } + } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 51b351b..8a3491a 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -21,10 +21,12 @@ class AuthServiceProvider extends ServiceProvider * * @return void */ - public function boot() + public function boot(): void { $this->registerPolicies(); - // + Gate::define('teste-index', function ($user){ + return false; + }); } } diff --git a/composer.json b/composer.json index 164c94b..3bac7c7 100644 --- a/composer.json +++ b/composer.json @@ -5,15 +5,16 @@ "keywords": ["framework", "laravel"], "license": "MIT", "require": { - "php": "^8.0.2", + "php": "^8.1", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.11", "laravel/sanctum": "^2.14.1", - "laravel/tinker": "^2.7" + "laravel/tinker": "^2.7", + "owen-it/laravel-auditing": "^13.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", - "laravel/sail": "^1.0.1", + "laravel/sail": "^1.14.2", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", "phpunit/phpunit": "^9.5.10", diff --git a/composer.lock b/composer.lock index 4a1fdd6..006f6e2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1abc7822bd9f28e9a62986817bf04f76", + "content-hash": "8d22be6a885e9930e292c80a7eee9a14", "packages": [ { "name": "brick/math", @@ -895,16 +895,16 @@ }, { "name": "laravel/framework", - "version": "v9.12.1", + "version": "v9.12.2", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "7c8bf052ef4919b8ffa7f25ec6f8648c4a36fc57" + "reference": "b5b5c635f1a93f277b5248725a1f7ffc97e20810" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/7c8bf052ef4919b8ffa7f25ec6f8648c4a36fc57", - "reference": "7c8bf052ef4919b8ffa7f25ec6f8648c4a36fc57", + "url": "https://api.github.com/repos/laravel/framework/zipball/b5b5c635f1a93f277b5248725a1f7ffc97e20810", + "reference": "b5b5c635f1a93f277b5248725a1f7ffc97e20810", "shasum": "" }, "require": { @@ -1070,7 +1070,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-05-10T19:32:47+00:00" + "time": "2022-05-11T13:38:26+00:00" }, { "name": "laravel/sanctum", @@ -2002,6 +2002,94 @@ }, "time": "2021-11-30T19:35:32+00:00" }, + { + "name": "owen-it/laravel-auditing", + "version": "v13.0.3", + "source": { + "type": "git", + "url": "https://github.com/owen-it/laravel-auditing.git", + "reference": "332d136a7d67a2c06ee85aa17efeafb3ba25c972" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/owen-it/laravel-auditing/zipball/332d136a7d67a2c06ee85aa17efeafb3ba25c972", + "reference": "332d136a7d67a2c06ee85aa17efeafb3ba25c972", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^7.0|^8.0|^9.0", + "illuminate/database": "^7.0|^8.0|^9.0", + "illuminate/filesystem": "^7.0|^8.0|^9.0", + "php": "^7.3|^8.0" + }, + "require-dev": { + "laravel/legacy-factories": "*", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^5.0|^6.0|^7.0", + "phpunit/phpunit": "^9.0" + }, + "suggest": { + "laravelista/lumen-vendor-publish": "Needed to publish the package configuration in Lumen" + }, + "type": "package", + "extra": { + "branch-alias": { + "dev-master": "v13-dev" + }, + "laravel": { + "providers": [ + "OwenIt\\Auditing\\AuditingServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "OwenIt\\Auditing\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Antério Vieira", + "email": "anteriovieira@gmail.com" + }, + { + "name": "Raphael França", + "email": "raphaelfrancabsb@gmail.com" + }, + { + "name": "Morten D. Hansen", + "email": "morten@visia.dk" + } + ], + "description": "Audit changes of your Eloquent models in Laravel/Lumen", + "homepage": "http://laravel-auditing.com", + "keywords": [ + "Accountability", + "Audit", + "auditing", + "changes", + "eloquent", + "history", + "laravel", + "log", + "logging", + "lumen", + "observer", + "record", + "revision", + "tracking" + ], + "support": { + "issues": "https://github.com/owen-it/laravel-auditing/issues", + "source": "https://github.com/owen-it/laravel-auditing" + }, + "time": "2022-04-20T14:28:57+00:00" + }, { "name": "phpoption/phpoption", "version": "1.8.1", @@ -5400,16 +5488,16 @@ }, { "name": "laravel/sail", - "version": "v1.14.2", + "version": "v1.14.4", "source": { "type": "git", "url": "https://github.com/laravel/sail.git", - "reference": "cee088fbe57432dd15678e3f7b6a8259f3073c46" + "reference": "0e0e51f19c758c79acbda11e3870641fbad5b7d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/sail/zipball/cee088fbe57432dd15678e3f7b6a8259f3073c46", - "reference": "cee088fbe57432dd15678e3f7b6a8259f3073c46", + "url": "https://api.github.com/repos/laravel/sail/zipball/0e0e51f19c758c79acbda11e3870641fbad5b7d9", + "reference": "0e0e51f19c758c79acbda11e3870641fbad5b7d9", "shasum": "" }, "require": { @@ -5456,7 +5544,7 @@ "issues": "https://github.com/laravel/sail/issues", "source": "https://github.com/laravel/sail" }, - "time": "2022-05-10T12:58:49+00:00" + "time": "2022-05-12T12:53:10+00:00" }, { "name": "mockery/mockery", @@ -7463,16 +7551,16 @@ }, { "name": "spatie/flare-client-php", - "version": "1.1.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/spatie/flare-client-php.git", - "reference": "ceab058852a1278d9f57a7b95f1c348e4956d866" + "reference": "1059fd8f229fa016b11063c6be9d1922d036adb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/ceab058852a1278d9f57a7b95f1c348e4956d866", - "reference": "ceab058852a1278d9f57a7b95f1c348e4956d866", + "url": "https://api.github.com/repos/spatie/flare-client-php/zipball/1059fd8f229fa016b11063c6be9d1922d036adb7", + "reference": "1059fd8f229fa016b11063c6be9d1922d036adb7", "shasum": "" }, "require": { @@ -7493,6 +7581,11 @@ "spatie/phpunit-snapshot-assertions": "^4.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.1.x-dev" + } + }, "autoload": { "files": [ "src/helpers.php" @@ -7515,7 +7608,7 @@ ], "support": { "issues": "https://github.com/spatie/flare-client-php/issues", - "source": "https://github.com/spatie/flare-client-php/tree/1.1.0" + "source": "https://github.com/spatie/flare-client-php/tree/1.1.1" }, "funding": [ { @@ -7523,20 +7616,20 @@ "type": "github" } ], - "time": "2022-03-11T13:21:28+00:00" + "time": "2022-05-11T09:43:07+00:00" }, { "name": "spatie/ignition", - "version": "1.2.10", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/spatie/ignition.git", - "reference": "dd8c3a21170b1d0f4d15048b2f4fa4a1a3a92a64" + "reference": "6aa8f1c8c46aff30c9bd4c354dc865eeee2ed59f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/ignition/zipball/dd8c3a21170b1d0f4d15048b2f4fa4a1a3a92a64", - "reference": "dd8c3a21170b1d0f4d15048b2f4fa4a1a3a92a64", + "url": "https://api.github.com/repos/spatie/ignition/zipball/6aa8f1c8c46aff30c9bd4c354dc865eeee2ed59f", + "reference": "6aa8f1c8c46aff30c9bd4c354dc865eeee2ed59f", "shasum": "" }, "require": { @@ -7557,6 +7650,11 @@ "symfony/process": "^5.4|^6.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.2.x-dev" + } + }, "autoload": { "psr-4": { "Spatie\\Ignition\\": "src" @@ -7593,7 +7691,7 @@ "type": "github" } ], - "time": "2022-05-10T12:21:27+00:00" + "time": "2022-05-12T08:19:04+00:00" }, { "name": "spatie/laravel-ignition", diff --git a/config/app.php b/config/app.php index ef76a7e..9f60a27 100644 --- a/config/app.php +++ b/config/app.php @@ -56,6 +56,8 @@ return [ 'url' => env('APP_URL', 'http://localhost'), + 'frontend_url' => env('FRONTEND_URL', 'http://localhost:3000'), + 'asset_url' => env('ASSET_URL'), /* @@ -195,6 +197,11 @@ return [ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, + /* + * Laravel Auditing + */ + OwenIt\Auditing\AuditingServiceProvider::class, + ], /* diff --git a/database/factories/DadosCadastraisFactory.php b/database/factories/DadosCadastraisFactory.php new file mode 100644 index 0000000..464a80c --- /dev/null +++ b/database/factories/DadosCadastraisFactory.php @@ -0,0 +1,23 @@ + + */ +class DadosCadastraisFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/DadosTeFactory.php b/database/factories/DadosTeFactory.php new file mode 100644 index 0000000..3790d2b --- /dev/null +++ b/database/factories/DadosTeFactory.php @@ -0,0 +1,23 @@ + + */ +class DadosTeFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/EconomyFactory.php b/database/factories/EconomyFactory.php new file mode 100644 index 0000000..88bc738 --- /dev/null +++ b/database/factories/EconomyFactory.php @@ -0,0 +1,23 @@ + + */ +class EconomyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/FaqFactory.php b/database/factories/FaqFactory.php new file mode 100644 index 0000000..d58bae7 --- /dev/null +++ b/database/factories/FaqFactory.php @@ -0,0 +1,23 @@ + + */ +class FaqFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/Med5minFactory.php b/database/factories/Med5minFactory.php new file mode 100644 index 0000000..55dc75d --- /dev/null +++ b/database/factories/Med5minFactory.php @@ -0,0 +1,23 @@ + + */ +class Med5minFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/NewsFactory.php b/database/factories/NewsFactory.php new file mode 100644 index 0000000..33fbd9e --- /dev/null +++ b/database/factories/NewsFactory.php @@ -0,0 +1,23 @@ + + */ +class NewsFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/NotificationsFactory.php b/database/factories/NotificationsFactory.php new file mode 100644 index 0000000..1ee91f2 --- /dev/null +++ b/database/factories/NotificationsFactory.php @@ -0,0 +1,23 @@ + + */ +class NotificationsFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/ParametersFactory.php b/database/factories/ParametersFactory.php new file mode 100644 index 0000000..dcdb6dc --- /dev/null +++ b/database/factories/ParametersFactory.php @@ -0,0 +1,23 @@ + + */ +class ParametersFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/PermissionFactory.php b/database/factories/PermissionFactory.php new file mode 100644 index 0000000..47b6db6 --- /dev/null +++ b/database/factories/PermissionFactory.php @@ -0,0 +1,23 @@ + + */ +class PermissionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/PldFactory.php b/database/factories/PldFactory.php new file mode 100644 index 0000000..9390127 --- /dev/null +++ b/database/factories/PldFactory.php @@ -0,0 +1,23 @@ + + */ +class PldFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/factories/RoleFactory.php b/database/factories/RoleFactory.php new file mode 100644 index 0000000..718b50a --- /dev/null +++ b/database/factories/RoleFactory.php @@ -0,0 +1,23 @@ + + */ +class RoleFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index cf6b776..374f804 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -21,6 +21,7 @@ return new class extends Migration $table->string('password'); $table->rememberToken(); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index fd235f8..b786fc8 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -21,6 +21,7 @@ return new class extends Migration $table->text('abilities')->nullable(); $table->timestamp('last_used_at')->nullable(); $table->timestamps(); + $table->softDeletes(); }); } diff --git a/database/migrations/2022_05_12_021354_create_news_table.php b/database/migrations/2022_05_12_021354_create_news_table.php new file mode 100644 index 0000000..760bd24 --- /dev/null +++ b/database/migrations/2022_05_12_021354_create_news_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('title', 255); + $table->text('text'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('news'); + } +}; diff --git a/database/migrations/2022_05_12_022040_create_faqs_table.php b/database/migrations/2022_05_12_022040_create_faqs_table.php new file mode 100644 index 0000000..4cab10b --- /dev/null +++ b/database/migrations/2022_05_12_022040_create_faqs_table.php @@ -0,0 +1,32 @@ +id(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('faqs'); + } +}; diff --git a/database/migrations/2022_05_12_023459_create_audits_table.php b/database/migrations/2022_05_12_023459_create_audits_table.php new file mode 100644 index 0000000..1040c4e --- /dev/null +++ b/database/migrations/2022_05_12_023459_create_audits_table.php @@ -0,0 +1,44 @@ +bigIncrements('id'); + $table->string('user_type')->nullable(); + $table->unsignedBigInteger('user_id')->nullable(); + $table->string('event'); + $table->morphs('auditable'); + $table->text('old_values')->nullable(); + $table->text('new_values')->nullable(); + $table->text('url')->nullable(); + $table->ipAddress('ip_address')->nullable(); + $table->string('user_agent', 1023)->nullable(); + $table->string('tags')->nullable(); + $table->timestamps(); + $table->softDeletes(); + + $table->index(['user_id', 'user_type']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('audits'); + } +} diff --git a/database/migrations/2022_05_12_025316_create_roles_table.php b/database/migrations/2022_05_12_025316_create_roles_table.php new file mode 100644 index 0000000..75c00cd --- /dev/null +++ b/database/migrations/2022_05_12_025316_create_roles_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('name'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('roles'); + } +}; diff --git a/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php b/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php new file mode 100644 index 0000000..44e402b --- /dev/null +++ b/database/migrations/2022_05_12_171300_create_dados_cadastrais_table.php @@ -0,0 +1,41 @@ +bigIncrements('cod_smart_unidade'); + $table->text('cliente'); + $table->text('unidade'); + $table->text('codigo_scde'); + $table->decimal('demanda_p'); + $table->decimal('demanda_fp'); + $table->text('status_empresa'); + $table->text('status_unidade'); + $table->decimal('data_de_migracao'); + $table->bigInteger('cod_smart_cliente'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('dados_cadastrais'); + } +}; diff --git a/database/migrations/2022_05_12_173518_create_economia_table.php b/database/migrations/2022_05_12_173518_create_economia_table.php new file mode 100644 index 0000000..a424853 --- /dev/null +++ b/database/migrations/2022_05_12_173518_create_economia_table.php @@ -0,0 +1,43 @@ +bigIncrements('cod_econ'); + $table->bigInteger('cod_smart_unidade'); + $table->text('mes text'); + $table->decimal('custo_cativo'); + $table->decimal('custo_livre'); + $table->decimal('economia_mensal'); + $table->decimal('economia_acumulada'); + $table->decimal('custo_unit'); + $table->boolean('dad_estimado'); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('cod_smart_unidade', 'economia_cod_smart_unidade_fkey') + ->references('cod_smart_unidade')->on('dados_cadastrais'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('economia'); + } +}; diff --git a/database/migrations/2022_05_12_174204_create_pld_table.php b/database/migrations/2022_05_12_174204_create_pld_table.php new file mode 100644 index 0000000..9038f24 --- /dev/null +++ b/database/migrations/2022_05_12_174204_create_pld_table.php @@ -0,0 +1,38 @@ +integerIncrements('id'); + $table->decimal('dia_num')->nullable(); + $table->decimal('hora')->nullable(); + $table->text('submercado')->nullable(); + $table->decimal('valor')->nullable(); + $table->string('mes_ref')->nullable(); + $table->decimal('dia_da_semana')->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('pld'); + } +}; diff --git a/database/migrations/2022_05_12_174614_create_med5min_table.php b/database/migrations/2022_05_12_174614_create_med5min_table.php new file mode 100644 index 0000000..bb8035b --- /dev/null +++ b/database/migrations/2022_05_12_174614_create_med5min_table.php @@ -0,0 +1,40 @@ +bigIncrements('id'); + $table->text('origem'); + $table->decimal('dia_num'); + $table->integer('minuto'); + $table->decimal('ativa_consumo'); + $table->decimal('ativa_geracao'); + $table->decimal('reativa_consumo'); + $table->decimal('reativa_geracao'); + $table->text('ponto'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('med_5min'); + } +}; diff --git a/database/migrations/2022_05_12_175125_create_dados_te_table.php b/database/migrations/2022_05_12_175125_create_dados_te_table.php new file mode 100644 index 0000000..0ebfcb4 --- /dev/null +++ b/database/migrations/2022_05_12_175125_create_dados_te_table.php @@ -0,0 +1,43 @@ +bigIncrements('cod_te'); + $table->bigInteger('cod_smart_unidade')->nullable(); + $table->text('mes')->nullable();; + $table->text('operacao')->nullable(); + $table->text('tipo')->nullable(); + $table->decimal('montante_nf')->nullable(); + $table->decimal('preco_nf')->nullable(); + $table->decimal('nf_c_icms')->nullable(); + $table->text('perfil_contr')->nullable(); + $table->timestamps(); + $table->softDeletes(); + + $table->foreign('cod_smart_unidade', 'dados_te_cod_smart_unidade_fkey') + ->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('dados_te'); + } +}; diff --git a/database/migrations/2022_05_13_013002_create_permissions_table.php b/database/migrations/2022_05_13_013002_create_permissions_table.php new file mode 100644 index 0000000..526d0a3 --- /dev/null +++ b/database/migrations/2022_05_13_013002_create_permissions_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('permissions'); + } +}; diff --git a/database/migrations/2022_05_13_015040_create_role_user_pivot_table.php b/database/migrations/2022_05_13_015040_create_role_user_pivot_table.php new file mode 100644 index 0000000..14ae76f --- /dev/null +++ b/database/migrations/2022_05_13_015040_create_role_user_pivot_table.php @@ -0,0 +1,33 @@ +unsignedInteger('user_id'); + $table->foreign('user_id', 'user_id_fk_2220802')->references('id')->on('users')->onDelete('cascade'); + $table->unsignedInteger('role_id'); + $table->foreign('role_id', 'role_id_fk_2220802')->references('id')->on('roles')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('role_user'); + } +}; diff --git a/database/migrations/2022_05_13_015432_create_permission_role_pivot_table.php b/database/migrations/2022_05_13_015432_create_permission_role_pivot_table.php new file mode 100644 index 0000000..b63f625 --- /dev/null +++ b/database/migrations/2022_05_13_015432_create_permission_role_pivot_table.php @@ -0,0 +1,33 @@ +unsignedInteger('role_id'); + $table->foreign('role_id', 'role_id_fk_2220793')->references('id')->on('roles')->onDelete('cascade'); + $table->unsignedInteger('permission_id'); + $table->foreign('permission_id', 'permission_id_fk_2220793')->references('id')->on('permissions')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('permission_role'); + } +}; diff --git a/database/migrations/2022_05_13_155256_create_notifications_table.php b/database/migrations/2022_05_13_155256_create_notifications_table.php new file mode 100644 index 0000000..07a224b --- /dev/null +++ b/database/migrations/2022_05_13_155256_create_notifications_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('cliente_id'); + $table->text('texto'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('notificacoes'); + } +}; diff --git a/database/migrations/2022_05_13_161015_create_parameters_table.php b/database/migrations/2022_05_13_161015_create_parameters_table.php new file mode 100644 index 0000000..dd0f1a9 --- /dev/null +++ b/database/migrations/2022_05_13_161015_create_parameters_table.php @@ -0,0 +1,33 @@ +integerIncrements('codigo'); + $table->string('argumento'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('parametros'); + } +}; diff --git a/database/seeders/DadosCadastraisSeeder.php b/database/seeders/DadosCadastraisSeeder.php new file mode 100644 index 0000000..14bb18c --- /dev/null +++ b/database/seeders/DadosCadastraisSeeder.php @@ -0,0 +1,19 @@ +create(); - - // \App\Models\User::factory()->create([ - // 'name' => 'Test User', - // 'email' => 'test@example.com', - // ]); + $this->call([ + UserTableSeeder::class, + RoleTableSeeder::class, + RoleUserTableSeeder::class + ]); } } diff --git a/database/seeders/EconomySeeder.php b/database/seeders/EconomySeeder.php new file mode 100644 index 0000000..bc9809f --- /dev/null +++ b/database/seeders/EconomySeeder.php @@ -0,0 +1,19 @@ +create([ + 'name' => 'Admin' + ]); + + Role::query()->create([ + 'name' => 'Client' + ]); + } +} diff --git a/database/seeders/RoleUserTableSeeder.php b/database/seeders/RoleUserTableSeeder.php new file mode 100644 index 0000000..26cc044 --- /dev/null +++ b/database/seeders/RoleUserTableSeeder.php @@ -0,0 +1,14 @@ +roles()->sync(1); + } +} diff --git a/database/seeders/UserTableSeeder.php b/database/seeders/UserTableSeeder.php new file mode 100644 index 0000000..61bcff7 --- /dev/null +++ b/database/seeders/UserTableSeeder.php @@ -0,0 +1,32 @@ +create([ + 'name' => 'Admin', + 'email' => 'admin@admin.com', + 'password' => bcrypt('password'), + 'remember_token' => null, + ]); + + User::query()->create([ + 'name' => 'Client', + 'email' => 'client@client.com', + 'password' => bcrypt('password'), + 'remember_token' => null, + ]); + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d21d912 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +# For more information: https://laravel.com/docs/sail +version: '3' +services: + laravel.test: + build: + context: ./docker/8.1 + dockerfile: Dockerfile + args: + WWWGROUP: '${WWWGROUP}' + image: sail-8.1/app + extra_hosts: + - 'host.docker.internal:host-gateway' + ports: + - '${APP_PORT:-80}:80' + - '${HMR_PORT:-8080}:8080' + environment: + WWWUSER: '${WWWUSER}' + LARAVEL_SAIL: 1 + XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' + XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' + volumes: + - '.:/var/www/html' + networks: + - sail + depends_on: + - pgsql + pgsql: + image: 'postgres:14' + ports: + - '${FORWARD_DB_PORT:-5432}:5432' + environment: + PGPASSWORD: '${DB_PASSWORD:-secret}' + POSTGRES_DB: '${DB_DATABASE}' + POSTGRES_USER: '${DB_USERNAME}' + POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}' + volumes: + - 'sail-pgsql:/var/lib/postgresql/data' + - './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql' + networks: + - sail + healthcheck: + test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"] + retries: 3 + timeout: 5s +networks: + sail: + driver: bridge +volumes: + sail-pgsql: + driver: local diff --git a/docker/8.1/Dockerfile b/docker/8.1/Dockerfile new file mode 100644 index 0000000..f6f32d2 --- /dev/null +++ b/docker/8.1/Dockerfile @@ -0,0 +1,61 @@ +FROM ubuntu:22.04 + +LABEL maintainer="Taylor Otwell" + +ARG WWWGROUP +ARG NODE_VERSION=16 +ARG POSTGRES_VERSION=14 + +WORKDIR /var/www/html + +ENV DEBIAN_FRONTEND noninteractive +ENV TZ=UTC + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apt-get update \ + && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \ + && mkdir -p ~/.gnupg \ + && chmod 600 ~/.gnupg \ + && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \ + && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x14AA40EC0831756756D7F66C4F4EA0AAE5267A6C \ + && echo "deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \ + && apt-get update \ + && apt-get install -y php8.1-cli php8.1-dev \ + php8.1-pgsql php8.1-sqlite3 php8.1-gd \ + php8.1-curl \ + php8.1-imap php8.1-mysql php8.1-mbstring \ + php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \ + php8.1-intl php8.1-readline \ + php8.1-ldap \ + php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \ + php8.1-memcached php8.1-pcov php8.1-xdebug \ + && php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \ + && curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \ + && apt-get install -y nodejs \ + && npm install -g npm \ + && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ + && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \ + && echo "deb http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ + && curl --silent -o - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ + && apt-get update \ + && apt-get install -y yarn \ + && apt-get install -y mysql-client \ + && apt-get install -y postgresql-client-$POSTGRES_VERSION \ + && apt-get -y autoremove \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1 + +RUN groupadd --force -g $WWWGROUP sail +RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail + +COPY start-container /usr/local/bin/start-container +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini +RUN chmod +x /usr/local/bin/start-container + +EXPOSE 8000 + +ENTRYPOINT ["start-container"] diff --git a/docker/8.1/php.ini b/docker/8.1/php.ini new file mode 100644 index 0000000..66d04d5 --- /dev/null +++ b/docker/8.1/php.ini @@ -0,0 +1,4 @@ +[PHP] +post_max_size = 100M +upload_max_filesize = 100M +variables_order = EGPCS diff --git a/docker/8.1/start-container b/docker/8.1/start-container new file mode 100644 index 0000000..b99ddd0 --- /dev/null +++ b/docker/8.1/start-container @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +if [ ! -z "$WWWUSER" ]; then + usermod -u $WWWUSER sail +fi + +if [ ! -d /.composer ]; then + mkdir /.composer +fi + +chmod -R ugo+rw /.composer + +if [ $# -gt 0 ]; then + exec gosu $WWWUSER "$@" +else + /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf +fi diff --git a/docker/8.1/supervisord.conf b/docker/8.1/supervisord.conf new file mode 100644 index 0000000..9d28479 --- /dev/null +++ b/docker/8.1/supervisord.conf @@ -0,0 +1,14 @@ +[supervisord] +nodaemon=true +user=root +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid + +[program:php] +command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80 +user=sail +environment=LARAVEL_SAIL="1" +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/phpunit.xml b/phpunit.xml index 2ac86a1..49661e5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,8 +21,7 @@ - - + diff --git a/routes/api.php b/routes/api.php index eb6fa48..558d08e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -14,6 +14,15 @@ use Illuminate\Support\Facades\Route; | */ -Route::middleware('auth:sanctum')->get('/user', function (Request $request) { - return $request->user(); +Route::prefix('auth')->group(function (){ + Route::post('login', [\App\Http\Controllers\Auth\AuthController::class, 'login']); + Route::post('logout', [\App\Http\Controllers\Auth\AuthController::class, 'logout']); + Route::post('register', [\App\Http\Controllers\Auth\RegisterController::class, 'store']); }); + +Route::middleware(['auth:sanctum', 'verified'])->group(function () { + Route::get('teste', [\App\Http\Controllers\EconomyController::class, 'index']); + Route::apiResource('user', \App\Http\Controllers\UserController::class); +}); + +