Skip to content

Feature/swagger api docs #28

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 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
130 changes: 130 additions & 0 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,94 @@

class UserController extends Controller
{
/**
* @OA\Get(
* path="/api/users",
* tags={"Users"},
* summary="Get all users with roles",
*
* @OA\Response(
* response=200,
* description="List of users",
*
* @OA\JsonContent(
* type="object",
*
* @OA\Property(
* property="data",
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="Shubham Belwal"),
* @OA\Property(property="email", type="string", example="[email protected]"),
* @OA\Property(
* property="roles",
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="admin")
* )
* )
* )
* )
* )
* )
* )
*/
public function index()
{
$users = User::with('roles')->paginate(10);

return response()->json($users);
}

/**
* @OA\Put(
* path="/api/users/{id}/roles",
* tags={"Users"},
* summary="Update user roles",
*
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="User ID",
*
* @OA\Schema(type="integer")
* ),
*
* @OA\RequestBody(
* required=true,
*
* @OA\JsonContent(
* required={"roles"},
*
* @OA\Property(
* property="roles",
* type="array",
*
* @OA\Items(type="string", example="admin")
* )
* )
* ),
*
* @OA\Response(
* response=200,
* description="Roles updated successfully",
*
* @OA\JsonContent(
*
* @OA\Property(property="message", type="string", example="Roles updated successfully")
* )
* )
* )
*/
public function updateRoles(Request $request, User $user)
{
$request->validate([
Expand All @@ -28,13 +109,62 @@ public function updateRoles(Request $request, User $user)
return response()->json(['message' => 'Roles updated successfully']);
}

/**
* @OA\Get(
* path="/api/roles",
* tags={"Users"},
* summary="Get all available roles",
*
* @OA\Response(
* response=200,
* description="List of roles",
*
* @OA\JsonContent(
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="name", type="string", example="editor")
* )
* )
* )
* )
*/
public function getRoles()
{
$roles = Role::all();

return response()->json($roles);
}

/**
* @OA\Delete(
* path="/api/users/{id}",
* tags={"Users"},
* summary="Delete a user",
*
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* description="User ID",
*
* @OA\Schema(type="integer")
* ),
*
* @OA\Response(
* response=200,
* description="User deleted successfully",
*
* @OA\JsonContent(
*
* @OA\Property(property="message", type="string", example="User deleted successfully")
* )
* )
* )
*/
public function destroy(User $user)
{
$user->delete();
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Controllers/SwaggerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers;

/**
* @OA\Info(
* title="Your Laravel API",
* version="1.0.0",
* description="Swagger documentation for Laravel APIs",
*
* @OA\Contact(
* email="[email protected]"
* )
* )
*
* @OA\Server(
* url="http://localhost:8000",
* description="Local API Server"
* )
*/
class SwaggerController {}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "MIT",
"require": {
"php": "^8.2",
"darkaonline/l5-swagger": "^9.0",
"laravel/framework": "^12.0",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.10.1",
Expand Down
Loading
Loading