Skip to content

feature/refactoring-test #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2dfd2a2
fix(makefile): addicionado condicionar caso nao encontre o docker-com…
caiquebispo Aug 3, 2024
53f1e76
refactor(composer): atuaizando laravel para versão 11.x
caiquebispo Aug 3, 2024
eeeeb0b
feat(passport) adicionando drive passport
caiquebispo Aug 3, 2024
94308f7
refactor(swagger): subistituindo as annotations do metodo index para …
caiquebispo Aug 3, 2024
631b961
refactor(swagger): subistituindo as annotations do metodoshowx para a…
caiquebispo Aug 3, 2024
3375edb
refactor(swagger): subistituindo as annotations do metodo store para…
caiquebispo Aug 3, 2024
2529a2f
refactor(swagger): subistituindo as annotations do metodo stoupdate a…
caiquebispo Aug 3, 2024
50e8626
refactor(swagger): subistituindo as annotations do metodo delete para…
caiquebispo Aug 3, 2024
33043fb
refactor(UserController) adicionando formRequest Validator no metodo …
caiquebispo Aug 3, 2024
744d749
feat(UserService): Criando classe user Serivice para abstrair regar d…
caiquebispo Aug 3, 2024
5fcb639
refactor(UserController): criando regra de validacao no metodo store,…
caiquebispo Aug 3, 2024
9795c2c
refactor(UserController): fazendo validação caso usúario que deseja B…
caiquebispo Aug 3, 2024
91bb477
refactor(UserController): fazendo validação caso usúario que deseja B…
caiquebispo Aug 3, 2024
85df5bb
refactor(UserController): fazendo validação caso usúario que deseja B…
caiquebispo Aug 3, 2024
4a2a1f2
feat(Authenticate): criando rotas de autenticação
caiquebispo Aug 3, 2024
b5112aa
feat(passport): publicando as migrate
caiquebispo Aug 3, 2024
c32da1b
Merge pull request #1 from CaiqueDeveloper/feature/refactoring
caiquebispo Aug 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions app/Api/Swagger/Auth/AuthSwagger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace App\Api\Swagger\Auth;

use Illuminate\Http\Response;
use OpenApi\Attributes as OA;

trait AuthSwagger
{
#[
OA\Post(
path: "/auth/login",
summary: "Login User",
tags: ["Authenticate"],
requestBody: new OA\RequestBody(
required: true,
content: new OA\MediaType(
mediaType: "application/json",
schema: new OA\Schema(
required: ["email", "password"],
properties: [
new OA\Property(property: 'email', description: "User email", type: "string"),
new OA\Property(property: 'password', description: "User password", type: "string"),
]
),
example: [
'email' => '[email protected]',
'password' => 'password'
]
)
),

responses: [
new OA\Response(
response: Response::HTTP_ACCEPTED,
description: "Login success.",
content: new OA\JsonContent(
properties: [
new OA\Property(property: 'data', type: 'object', example: [
"success" => true,
"statusCode" => Response::HTTP_ACCEPTED,
"message" => "User has been logged successfully.",
"data" => [
"id" => 1,
"name" => "User Teste",
"email" => "[email protected]",
"created_at" => "2024-07-27T15:39:28.000000Z",
"updated_at" => "2024-07-28T21:49:06.000000Z",
"bearer_token" => "17|QJmAJPmZPxxcAFCp8XgfgQf6GzEghBvTEgkgEHrAf7040d89"
]
])
]
)
),
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized", content: new OA\JsonContent(
properties: [
new OA\Property(property: 'data', type: 'object', example: [
"meta" => [
"code" => Response::HTTP_UNAUTHORIZED,
"status" => "fails",
"message" => "The provided credentials are incorrect.!"
],
"user" => [],
"access_token" => [
"token" => '',
"type" => "Bearer"
]
])
]
)),
]
)
]
private function swagger_login()
{
}
#[
OA\Post(
path: '/auth/logout',
summary: 'Logout User',
tags: ['Authenticate'],
security: [
[
'bearerAuth' => []
]
],
responses: [
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthenticated', content: new OA\JsonContent(
properties: [
new OA\Property(property: 'data', type: 'object', example: [
"message" => "Unauthenticated."
])
]
)),
new OA\Response(response: Response::HTTP_ACCEPTED, description: 'Successfully logged out', content: new OA\JsonContent(
properties: [
new OA\Property(property: 'data', type: 'object', example: [
'meta' => [
'code' => Response::HTTP_ACCEPTED,
'status' => 'success',
'message' => 'Successfully logged out',
],
'data' => [],
])
]
)),
]
)
]
private function swagger_logout(): void
{
}
}
179 changes: 179 additions & 0 deletions app/Api/Swagger/User/UserSwagger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace App\Api\Swagger\User;

use Illuminate\Http\Response;
use OpenApi\Annotations\JsonContent;
use OpenApi\Annotations\Property;
use OpenApi\Attributes as OA;

trait UserSwagger
{
#[
OA\Get(
path: '/users',
operationId: 'getUsersList',
summary: 'Get List of users',
description: 'Returns list of users',
tags: ['Users'],
security: [
[
'bearerAuth' => []
]
],
requestBody: new OA\RequestBody(
content: new OA\MediaType(
mediaType: 'application/json',

)
),
responses: [

new OA\Response(response: Response::HTTP_OK, description: 'Successful operation'),
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthenticated'),
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden'),
]
)
]
private function all(): void
{
}

#[
OA\Get(
path: '/users/{id}',
operationId: 'showUser',
summary: 'Show a specific user',
description: 'Returns a specific user',
tags: ['Users'],
security: [
[
'bearerAuth' => []
]
],
parameters: [new OA\Parameter(name: 'id', in: 'path', required: true, description: 'User ID')],
responses: [
new OA\Response(response: Response::HTTP_OK, description: 'Successful operation'),
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthenticated'),
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden'),
]
)
]
private function swagger_show(): void
{
}

#[
OA\Post(
path: 'users',
operationId: 'storeUser',
summary: 'Store a new user',
description: 'Stores a new user',
tags: ['Users'],
security: [
[
'bearerAuth' => []
]
],
requestBody: new OA\RequestBody(
required: true,
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
required: ['name', 'email', 'password', 'password_confirmation'],
properties: [
new OA\Property(property: 'name', type: 'string'),
new OA\Property(property: 'email', type: 'string'),
new OA\Property(property: 'password', type: 'string'),
new OA\Property(property: 'password_confirmation', type: 'string'),
]
),
example: [
"name" => "John Doe",
"email" => "[email protected]",
"password" => "password",
"password_confirmation" => "password",
]
)
),
responses: [
new OA\Response(response: Response::HTTP_OK, description: 'Successful operation'),
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthenticated'),
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden'),
]
)
]
private function swagger_store(): void
{
}
#[
OA\Put(
path: 'users/{id}',
operationId: 'updateUser',
summary: 'Update a specific user',
description: "Updates a specific user",
tags: ['Users'],
security: [
[
'bearerAuth' => []
]
],
parameters: [new OA\Parameter(name: 'id', in: 'path', required: true, description: 'User ID')],
requestBody: new OA\RequestBody(
required: true,
content: new OA\MediaType(
mediaType: 'application/json',
schema: new OA\Schema(
required: ['name', 'email'],
properties: [
new OA\Property(property: 'name', type: 'string'),
new OA\Property(property: 'email', type: 'string'),
new OA\Property(property: 'password', type: 'string'),
new OA\Property(property: 'password_confirmation', type: 'string'),
]
),
example: [
"name" => "John Doe",
"email" => "[email protected]",
"password" => "password",
"password_confirmation" => "password",
]
)


),
responses: [
new OA\Response(response: Response::HTTP_OK, description: 'Successful operation'),
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthenticated'),
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden'),
]
)
]
private function swagger_update(): void
{
}

#[
OA\Delete(
path: '/users/{id}',
operationId: 'deleteUser',
summary: 'Delete a specific user',
description: 'Deletes a specific user',
tags: ['Users'],
security: [
[
'bearerAuth' => []
]
],
parameters: [new OA\Parameter(name: 'id', in: 'path', required: true, description: 'User ID')],
responses: [
new OA\Response(response: Response::HTTP_OK, description: 'Successful operation'),
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthenticated'),
new OA\Response(response: Response::HTTP_FORBIDDEN, description: 'Forbidden'),
]
)
]
private function swagger_delete(): void
{
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\LoginRequest;
use App\Services\AuthService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Api\Swagger\Auth\AuthSwagger;

class AuthController extends Controller
{
use AuthSwagger;

public function login(LoginRequest $request): JsonResponse
{
$credentials = $request->validated();

return (new AuthService)->attempt($credentials);
}
public function logout(): JsonResponse
{
return (new AuthService)->logout();
}
}
48 changes: 24 additions & 24 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use OpenApi\Attributes as OA;

/**
* @OA\Info(
* version="1.0.0",
* title="E11 - Swagger",
* description="L5 Swagger OpenApi description",
* @OA\Contact(
* email="[email protected]"
* )
* )
*
* @OA\SecurityScheme(
* securityScheme="bearerAuth",
* in="header",
* name="bearerAuth",
* type="http",
* scheme="bearer",
* bearerFormat="JWT",
* ),
*
* @OA\Server(
* url=L5_SWAGGER_CONST_HOST,
* description="API Server"
* )
*/
#[
OA\Info(
version: "1.0.0",
title: "E11 - Swagger",
description: "L5 Swagger OpenApi description",
),
OA\Contact(email: "[email protected]"),

OA\SecurityScheme(
securityScheme: 'bearerAuth',
in: 'header',
name: 'bearerAuth',
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT'
),

OA\Server(
url: L5_SWAGGER_CONST_HOST,
description: ' API SErve'
)

]
class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
Expand Down
Loading