-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from SouJunior/migracao-controllers-master-hyperf
Migracao controllers master hyperf
- Loading branch information
Showing
41 changed files
with
789 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class AuthController extends Controller | ||
{ | ||
|
||
public function login(Request $request) | ||
{ | ||
$request->validate([ | ||
|
||
'email' => ['required', 'email'], | ||
'password' => ['required'] | ||
|
||
], [ | ||
'email.required' => 'O campo e-mail é obrigatório.', | ||
'email.email' => 'O campo e-mail deve ser um endereço de e-mail válido.', | ||
'password.required' => 'O campo senha é obrigatório.', | ||
'password' => 'required|string|min:8' | ||
]); | ||
|
||
|
||
if (!auth()->attempt($request->only('email', 'password'))) { | ||
|
||
return response()->json([ | ||
'message' => 'Credenciais inválidas.', | ||
], 401); | ||
} | ||
|
||
$user = auth()->user(); | ||
$token = $user->createToken('auth_token')->plainTextToken; | ||
|
||
return response()->json(['token' => $token, 'user' => auth()->user()], 200); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Env; | ||
|
||
class IndexController extends Controller | ||
{ | ||
public function index(Request $request) | ||
{ | ||
$user = $request->input('user', 'Laravel'); | ||
$method = $request->getMethod(); | ||
|
||
return response()->json([ | ||
'method' => $method, | ||
'message' => "Hello bro, {$user}.", | ||
'env' => env('DB_DATABASE'), | ||
], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Member; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
use App\Models\Member; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class CreateMemberController extends Controller | ||
{ | ||
public function __invoke(Request $request, string $squadUuid) | ||
{ | ||
$member = new Member(); | ||
|
||
$member->uuid = Uuid::uuid4()->toString(); | ||
$member->name = $request->input('name'); | ||
$member->role = $request->input('role'); | ||
$member->squad_uuid = $request->input('squad_uuid'); | ||
$member->save(); | ||
|
||
return response()->json([ | ||
'message' => 'Membro criado com sucesso', | ||
'membro' => $member | ||
], 201); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Member; | ||
|
||
use App\Models\Member; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class DeleteMemberController extends Controller | ||
{ | ||
public function __invoke(string $uuid, string $memberUuid) | ||
{ | ||
$member = Member::query()->where(['uuid' => $memberUuid])->first(); | ||
|
||
if (!$member) { | ||
|
||
return response()->json(['error' => 'Membro não encontrado'], 404); | ||
} | ||
|
||
$member->delete(); | ||
|
||
return response()->json(['message' => 'Membro apagado com sucesso'], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Member; | ||
|
||
use App\Models\Member; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class EditMemberController extends Controller | ||
{ | ||
public function __invoke(request $request, string $uuid, string $memberUuid) | ||
{ | ||
$member = Member::query()->where(['squad_uuid' => $uuid, 'uuid' => $memberUuid])->first(); | ||
|
||
if (!$member) { | ||
|
||
return response()->json(['error' => 'Membro não encontrado'], 404); | ||
} | ||
|
||
$member->name = $request->input('name'); | ||
$member->role = $request->input('role'); | ||
$member->save(); | ||
|
||
return response()->json(['message' => 'Membro atualizado com sucesso'], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Member; | ||
|
||
use App\Models\Member; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class ListMemberController extends Controller | ||
{ | ||
public function __invoke(string $squadUuid) | ||
{ | ||
$member = Member::query()->where('squad_uuid', $squadUuid)->get(); | ||
|
||
return response()->json($member); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Member; | ||
|
||
use App\Models\Member; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class ShowMemberController extends Controller | ||
{ | ||
public function __invoke(string $uuid, string $memberUuid) | ||
{ | ||
$member = Member::query()->where('uuid', $memberUuid)->first(); | ||
|
||
if (!$member) { | ||
|
||
return response()->json(['error' => 'Membro não encontrada', 404]); | ||
} | ||
|
||
return response()->json($member, 200); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Product; | ||
|
||
use App\Models\Product; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class ActiveProductController extends Controller | ||
{ | ||
public function __invoke(Request $request, string $uuid) | ||
{ | ||
$user = auth()->user(); | ||
|
||
if ($user->permission !== 'admin') { | ||
|
||
return response()->json([ | ||
'erro' => 'Você não tem permissão para atualizar esse produto' | ||
], 403); | ||
} | ||
|
||
$product = Product::query()->where('uuid', $uuid)->first(); | ||
|
||
if (!$product) { | ||
|
||
return response()->json([ | ||
'erro' => 'Produto não encontrado' | ||
], 404); | ||
} | ||
|
||
$product->active = $request->input('active'); | ||
$product->save(); | ||
|
||
if ($product->active == 1) { | ||
|
||
return response()->json([ | ||
'message' => 'Produto ativado com sucesso' | ||
], 200); | ||
|
||
} | ||
|
||
if ($product->active == 0) { | ||
|
||
return response()->json([ | ||
'message' => 'Produto desativado com sucesso' | ||
], 200); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Product; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
use App\Models\Product; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class CreateProductController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$user = auth()->user(); | ||
|
||
$product = new Product(); | ||
|
||
$product->uuid = Uuid::uuid4()->toString(); | ||
$product->owner_uuid = $user->uuid; | ||
$product->name = $request->input('name'); | ||
$product->description = $request->input('description'); | ||
|
||
$product->save(); | ||
|
||
return response()->json([ | ||
'message' => 'Produto cadastrado com sucesso', | ||
'product' => $product | ||
], 201); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Product; | ||
|
||
use App\Models\Product; | ||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class DeleteProductController extends Controller | ||
{ | ||
public function __invoke(string $uuid) | ||
{ | ||
$product = Product::query()->where('uuid', $uuid)->first(); | ||
|
||
$user = auth()->user(); | ||
|
||
if (!$product) { | ||
|
||
return response()->json([ | ||
'error' => 'Produto não encontrado' | ||
], 404); | ||
} | ||
|
||
if ($user->uuid !== $product->owner_uuid) { | ||
|
||
return response()->json([ | ||
'error' => 'Você não tem permissão para atualizar esse produto' | ||
], 403); | ||
} | ||
|
||
$product->delete(); | ||
|
||
return response()->json([ | ||
'Message' => 'Produto deletado com sucesso' | ||
], 200); | ||
} | ||
} |
Oops, something went wrong.