Skip to content

Commit

Permalink
refactor(api): Improve code style + API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
gnovaro committed Mar 9, 2024
1 parent 3538ce3 commit 2baad84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
25 changes: 7 additions & 18 deletions app/Http/Controllers/Api/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
Expand Down Expand Up @@ -34,10 +33,8 @@ class LoginController extends Controller
* description="Unauthorized or wrong credentials"
* )
* )
*
* @return \Illuminate\Http\JsonResponse
*/
public function login(Request $request)
public function login(Request $request): \Illuminate\Http\JsonResponse
{
$request->validate([
'email' => 'required|string|email',
Expand All @@ -47,7 +44,7 @@ public function login(Request $request)
$credentials = request(['email', 'password']);
$token = auth('api')->attempt($credentials);

if (! $token) {
if (empty($token)) {
return response()->json(['error' => 'Unauthorized'], 401);
}

Expand All @@ -56,20 +53,16 @@ public function login(Request $request)

/**
* Get the authenticated User.
*
* @return \Illuminate\Http\JsonResponse
*/
public function me()
public function me(): \Illuminate\Http\JsonResponse
{
return response()->json(auth('api')->user());
}

/**
* Log the user out (Invalidate the token).
*
* @return \Illuminate\Http\JsonResponse
*/
public function logout()
public function logout(): \Illuminate\Http\JsonResponse
{
auth('api')->logout();

Expand All @@ -78,25 +71,21 @@ public function logout()

/**
* Refresh a token.
*
* @return \Illuminate\Http\JsonResponse
*/
public function refresh()
public function refresh(): \Illuminate\Http\JsonResponse
{
return $this->respondWithToken(auth('api')->refresh());
}

/**
* Get the token array structure.
*
* @return \Illuminate\Http\JsonResponse
*/
protected function respondWithToken(string $token)
protected function respondWithToken(string $token): \Illuminate\Http\JsonResponse
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60,
'expires_in' => auth('api')->factory()->getTTL() * 120,
]);
}
}
11 changes: 11 additions & 0 deletions app/Http/Controllers/Api/Contact/ContactCreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public function __construct(ContactRepository $contactRepository)
* summary="Create a contact",
* tags={"Contact"},
* security={{"bearerAuth": {} }},
* @OA\RequestBody(
* required=true,
* description="Contact data",
* @OA\JsonContent(
* required={"contact_first_name", "lead_id", "contact_email", "contact_phone"},
* @OA\Property(property="contact_first_name", type="string", maxLength=50, example="John"),
* @OA\Property(property="lead_id", type="integer", example=123),
* @OA\Property(property="contact_email", type="string", maxLength=254, format="email", example="john@example.com"),
* @OA\Property(property="contact_phone", type="string", maxLength=15, example="123-456-7890")
* ),
* ),
* @OA\Response(response="400", description="Bad request: Please review required params"),
* @OA\Response(response="201", description="Contact created successfully")
* )
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

const APP_VERSION = '3.7.4';
const APP_VERSION = '3.7.5';

0 comments on commit 2baad84

Please sign in to comment.