diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 0bc1967..a61ef20 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -149,7 +149,7 @@ class UserController extends Controller } /** - * @OA\Put( + * @OA\Patch( * path="/api/users/{id}", * summary="Update an existing user (only admin)", * tags={"Users"}, @@ -209,14 +209,14 @@ class UserController extends Controller { $this->authorize('update', $user); $fields = $request->validate([ - 'username' => ['required', 'max:100', Rule::unique('users')->ignore($user->id)], - 'email' => ['required', 'max:100', Rule::unique('users')->ignore($user->id)], - 'password' => 'required|min:6', - 'type' => 'required|in:admin,user,creator,banned', - 'email_verified_at' => 'nullable|date', + 'username' => ['sometimes', 'max:100', Rule::unique('users')->ignore($user->id)], + 'email' => ['sometimes', 'max:100', Rule::unique('users')->ignore($user->id)], + 'password' => 'sometimes|min:6', + 'type' => 'sometimes|in:admin,user,creator,banned', + 'email_verified_at' => 'sometimes|date', ]); - if(!Hash::check($fields['password'], $user->password)) { + if (isset($fields['password'])) { $fields['password'] = Hash::make($fields['password']); } $user->update($fields); diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index 0b559bc..75e0b2d 100644 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -2162,12 +2162,50 @@ } ] }, - "put": { + "delete": { + "tags": [ + "Users" + ], + "summary": "Delete a user (only admin)", + "operationId": "fa56cffde745d3f152f95cbacd936c0b", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "User ID", + "required": true, + "schema": { + "type": "integer", + "example": 1 + } + } + ], + "responses": { + "204": { + "description": "User deleted successfully (no content)" + }, + "404": { + "description": "User not found" + }, + "403": { + "description": "Forbidden — only admins can delete users" + }, + "401": { + "description": "Unauthenticated" + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + }, + "patch": { "tags": [ "Users" ], "summary": "Update an existing user (only admin)", - "operationId": "b9091397c8b25f12c6adb74be6ce3a5a", + "operationId": "872a537e8eb13c26c5542c7d73269a80", "parameters": [ { "name": "id", @@ -2275,44 +2313,6 @@ "bearerAuth": [] } ] - }, - "delete": { - "tags": [ - "Users" - ], - "summary": "Delete a user (only admin)", - "operationId": "fa56cffde745d3f152f95cbacd936c0b", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "User ID", - "required": true, - "schema": { - "type": "integer", - "example": 1 - } - } - ], - "responses": { - "204": { - "description": "User deleted successfully (no content)" - }, - "404": { - "description": "User not found" - }, - "403": { - "description": "Forbidden — only admins can delete users" - }, - "401": { - "description": "Unauthenticated" - } - }, - "security": [ - { - "bearerAuth": [] - } - ] } }, "/api/user-tests/me": {