Skip to content

Commit

Permalink
commit for article 3
Browse files Browse the repository at this point in the history
  • Loading branch information
MalikSh96 committed Nov 24, 2021
1 parent a29a313 commit 7b317d2
Show file tree
Hide file tree
Showing 7 changed files with 838 additions and 57 deletions.
19 changes: 19 additions & 0 deletions app/DTOs/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* @OA\Schema(
* schema="User",
* required={
* "name",
* "email"
* }
* )
*/
class User {

/** @OA\Property() */
public string $name;

/** @OA\Property() */
public string $email;
}
43 changes: 15 additions & 28 deletions app/Forms/UserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,34 @@

namespace App\Forms;

use OpenApi\Generator;
use Illuminate\Foundation\Http\FormRequest;
use App\Models\User;

/**
* @OA\Schema(
* schema="User",
* required={
* "name",
* "email"
* }
* )
*/
class UserForm extends FormRequest {

/** @OA\Property() */
public string $name;
/** @OA\Property() */
public string $email;

public function authorize()
{

return true;
}

public function rules()
{
return [
'name' => 'required|string',
'email' => 'required|string',
];
return [
'name' => 'required|string',
'email' => 'required|string|email',
];
}

public function save()
{
$user = new User();
$user->name = $this->name;
$user->email = $this->email;
$user->save();
return [
'name' = $user->name,
'email' => $user->email
]
$user = new User();
$user->name = $this->name;
$user->email = $this->email;
$user->password = bcrypt("asd");
$user->save();
return [
'name' => $user->name,
'email' => $user->email,
];
}
}
52 changes: 25 additions & 27 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@
*/
class UserController extends Controller
{
/**
* @OA\Get(path="/api/users", description="Get all users", operationId="",
* @OA\Response(response=200, description="OK",
* @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/User"))
* ),
* @OA\Response(response=401, description="Unauthorized"),
* @OA\Response(response=404, description="Not Found")
* )
*/
public function index(Request $request)
{
return User::all();
}
/**
* @OA\Get(path="/api/users", description="Get all users", operationId="",
* @OA\Response(response=200, description="OK",
* @OA\JsonContent(type="array", @OA\Items(ref="#/components/schemas/User"))
* ),
* @OA\Response(response=404, description="Not Found")
* )
*/
public function index(Request $request)
{
return User::all();
}

/**
* @OA\Post(path="/api/create", description="Create user", operationId="",
* @OA\RequestBody(@OA\JsonContent(ref="#/components/schemas/User"), required=true,description="The creation of a user"),
* @OA\Response(response=201, description="Created",
* @OA\JsonContent(ref="#/components/schemas/User")
* ),
* @OA\Response(response=401, description="Unauthorized"),
* @OA\Response(response=422, description="Unprocessable Entity / Validation Failed")
* )
*/
public function store(Form $request)
{
return $request->save();
}
/**
* @OA\Post(path="/api/users", description="Create user", operationId="",
* @OA\RequestBody(@OA\JsonContent(ref="#/components/schemas/User"), required=true,description="The creation of a user"),
* @OA\Response(response=200, description="OK",
* @OA\JsonContent(ref="#/components/schemas/User")
* ),
* @OA\Response(response=422, description="Unprocessable Entity / Validation Failed")
* )
*/
public function store(Form $request)
{
return $request->save();
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"laravel/framework": "^8.65",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"league/openapi-psr7-validator": "^0.16.4",
"zircote/swagger-php": "^3.3"
},
"require-dev": {
Expand Down
Loading

0 comments on commit 7b317d2

Please sign in to comment.