mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Apply fixes from StyleCI
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Api\ListingResponseBuilder;
|
||||
use BookStack\Http\Controllers\Controller;
|
||||
@ -7,7 +9,6 @@ use Illuminate\Http\JsonResponse;
|
||||
|
||||
abstract class ApiController extends Controller
|
||||
{
|
||||
|
||||
protected $rules = [];
|
||||
|
||||
/**
|
||||
@ -17,6 +18,7 @@ abstract class ApiController extends Controller
|
||||
protected function apiListingResponse(Builder $query, array $fields): JsonResponse
|
||||
{
|
||||
$listing = new ListingResponseBuilder($query, request(), $fields);
|
||||
|
||||
return $listing->toResponse();
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Api\ApiDocsGenerator;
|
||||
|
||||
class ApiDocsController extends ApiController
|
||||
{
|
||||
|
||||
/**
|
||||
* Load the docs page for the API.
|
||||
*/
|
||||
@ -12,6 +13,7 @@ class ApiDocsController extends ApiController
|
||||
{
|
||||
$docs = ApiDocsGenerator::generateConsideringCache();
|
||||
$this->setPageTitle(trans('settings.users_api_tokens_docs'));
|
||||
|
||||
return view('api-docs.index', [
|
||||
'docs' => $docs,
|
||||
]);
|
||||
@ -23,6 +25,7 @@ class ApiDocsController extends ApiController
|
||||
public function json()
|
||||
{
|
||||
$docs = ApiDocsGenerator::generateConsideringCache();
|
||||
|
||||
return response()->json($docs);
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,26 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Repos\BookRepo;
|
||||
use BookStack\Exceptions\NotifyException;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class BookApiController extends ApiController
|
||||
{
|
||||
|
||||
protected $bookRepo;
|
||||
|
||||
protected $rules = [
|
||||
'create' => [
|
||||
'name' => 'required|string|max:255',
|
||||
'name' => 'required|string|max:255',
|
||||
'description' => 'string|max:1000',
|
||||
'tags' => 'array',
|
||||
'tags' => 'array',
|
||||
],
|
||||
'update' => [
|
||||
'name' => 'string|min:1|max:255',
|
||||
'name' => 'string|min:1|max:255',
|
||||
'description' => 'string|max:1000',
|
||||
'tags' => 'array',
|
||||
'tags' => 'array',
|
||||
],
|
||||
];
|
||||
|
||||
@ -36,6 +35,7 @@ class BookApiController extends ApiController
|
||||
public function list()
|
||||
{
|
||||
$books = Book::visible();
|
||||
|
||||
return $this->apiListingResponse($books, [
|
||||
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by', 'image_id',
|
||||
]);
|
||||
@ -43,6 +43,7 @@ class BookApiController extends ApiController
|
||||
|
||||
/**
|
||||
* Create a new book in the system.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function create(Request $request)
|
||||
@ -51,6 +52,7 @@ class BookApiController extends ApiController
|
||||
$requestData = $this->validate($request, $this->rules['create']);
|
||||
|
||||
$book = $this->bookRepo->create($requestData);
|
||||
|
||||
return response()->json($book);
|
||||
}
|
||||
|
||||
@ -60,11 +62,13 @@ class BookApiController extends ApiController
|
||||
public function read(string $id)
|
||||
{
|
||||
$book = Book::visible()->with(['tags', 'cover', 'createdBy', 'updatedBy', 'ownedBy'])->findOrFail($id);
|
||||
|
||||
return response()->json($book);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the details of a single book.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
@ -81,6 +85,7 @@ class BookApiController extends ApiController
|
||||
/**
|
||||
* Delete a single book.
|
||||
* This will typically send the book to the recycle bin.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(string $id)
|
||||
@ -89,6 +94,7 @@ class BookApiController extends ApiController
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
|
||||
$this->bookRepo->destroy($book);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Tools\ExportFormatter;
|
||||
@ -15,23 +17,27 @@ class BookExportApiController extends ApiController
|
||||
|
||||
/**
|
||||
* Export a book as a PDF file.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function exportPdf(int $id)
|
||||
{
|
||||
$book = Book::visible()->findOrFail($id);
|
||||
$pdfContent = $this->exportFormatter->bookToPdf($book);
|
||||
|
||||
return $this->downloadResponse($pdfContent, $book->slug . '.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a book as a contained HTML file.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function exportHtml(int $id)
|
||||
{
|
||||
$book = Book::visible()->findOrFail($id);
|
||||
$htmlContent = $this->exportFormatter->bookToContainedHtml($book);
|
||||
|
||||
return $this->downloadResponse($htmlContent, $book->slug . '.html');
|
||||
}
|
||||
|
||||
@ -42,6 +48,7 @@ class BookExportApiController extends ApiController
|
||||
{
|
||||
$book = Book::visible()->findOrFail($id);
|
||||
$textContent = $this->exportFormatter->bookToPlainText($book);
|
||||
|
||||
return $this->downloadResponse($textContent, $book->slug . '.txt');
|
||||
}
|
||||
|
||||
@ -52,6 +59,7 @@ class BookExportApiController extends ApiController
|
||||
{
|
||||
$book = Book::visible()->findOrFail($id);
|
||||
$markdown = $this->exportFormatter->bookToMarkdown($book);
|
||||
|
||||
return $this->downloadResponse($markdown, $book->slug . '.md');
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Entities\Repos\BookshelfRepo;
|
||||
use BookStack\Entities\Models\Bookshelf;
|
||||
use BookStack\Entities\Repos\BookshelfRepo;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Http\Request;
|
||||
@ -9,7 +11,6 @@ use Illuminate\Validation\ValidationException;
|
||||
|
||||
class BookshelfApiController extends ApiController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var BookshelfRepo
|
||||
*/
|
||||
@ -17,14 +18,14 @@ class BookshelfApiController extends ApiController
|
||||
|
||||
protected $rules = [
|
||||
'create' => [
|
||||
'name' => 'required|string|max:255',
|
||||
'name' => 'required|string|max:255',
|
||||
'description' => 'string|max:1000',
|
||||
'books' => 'array',
|
||||
'books' => 'array',
|
||||
],
|
||||
'update' => [
|
||||
'name' => 'string|min:1|max:255',
|
||||
'name' => 'string|min:1|max:255',
|
||||
'description' => 'string|max:1000',
|
||||
'books' => 'array',
|
||||
'books' => 'array',
|
||||
],
|
||||
];
|
||||
|
||||
@ -42,6 +43,7 @@ class BookshelfApiController extends ApiController
|
||||
public function list()
|
||||
{
|
||||
$shelves = Bookshelf::visible();
|
||||
|
||||
return $this->apiListingResponse($shelves, [
|
||||
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by', 'image_id',
|
||||
]);
|
||||
@ -51,6 +53,7 @@ class BookshelfApiController extends ApiController
|
||||
* Create a new shelf in the system.
|
||||
* An array of books IDs can be provided in the request. These
|
||||
* will be added to the shelf in the same order as provided.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function create(Request $request)
|
||||
@ -73,8 +76,9 @@ class BookshelfApiController extends ApiController
|
||||
'tags', 'cover', 'createdBy', 'updatedBy', 'ownedBy',
|
||||
'books' => function (BelongsToMany $query) {
|
||||
$query->visible()->get(['id', 'name', 'slug']);
|
||||
}
|
||||
},
|
||||
])->findOrFail($id);
|
||||
|
||||
return response()->json($shelf);
|
||||
}
|
||||
|
||||
@ -83,6 +87,7 @@ class BookshelfApiController extends ApiController
|
||||
* An array of books IDs can be provided in the request. These
|
||||
* will be added to the shelf in the same order as provided and overwrite
|
||||
* any existing book assignments.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
@ -94,14 +99,14 @@ class BookshelfApiController extends ApiController
|
||||
$bookIds = $request->get('books', null);
|
||||
|
||||
$shelf = $this->bookshelfRepo->update($shelf, $requestData, $bookIds);
|
||||
|
||||
return response()->json($shelf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Delete a single shelf.
|
||||
* This will typically send the shelf to the recycle bin.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete(string $id)
|
||||
@ -110,6 +115,7 @@ class BookshelfApiController extends ApiController
|
||||
$this->checkOwnablePermission('bookshelf-delete', $shelf);
|
||||
|
||||
$this->bookshelfRepo->destroy($shelf);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Actions\ActivityType;
|
||||
use BookStack\Entities\Models\Book;
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Repos\ChapterRepo;
|
||||
use BookStack\Facades\Activity;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@ -14,16 +14,16 @@ class ChapterApiController extends ApiController
|
||||
|
||||
protected $rules = [
|
||||
'create' => [
|
||||
'book_id' => 'required|integer',
|
||||
'name' => 'required|string|max:255',
|
||||
'book_id' => 'required|integer',
|
||||
'name' => 'required|string|max:255',
|
||||
'description' => 'string|max:1000',
|
||||
'tags' => 'array',
|
||||
'tags' => 'array',
|
||||
],
|
||||
'update' => [
|
||||
'book_id' => 'integer',
|
||||
'name' => 'string|min:1|max:255',
|
||||
'book_id' => 'integer',
|
||||
'name' => 'string|min:1|max:255',
|
||||
'description' => 'string|max:1000',
|
||||
'tags' => 'array',
|
||||
'tags' => 'array',
|
||||
],
|
||||
];
|
||||
|
||||
@ -41,6 +41,7 @@ class ChapterApiController extends ApiController
|
||||
public function list()
|
||||
{
|
||||
$chapters = Chapter::visible();
|
||||
|
||||
return $this->apiListingResponse($chapters, [
|
||||
'id', 'book_id', 'name', 'slug', 'description', 'priority',
|
||||
'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by',
|
||||
@ -59,6 +60,7 @@ class ChapterApiController extends ApiController
|
||||
$this->checkOwnablePermission('chapter-create', $book);
|
||||
|
||||
$chapter = $this->chapterRepo->create($request->all(), $book);
|
||||
|
||||
return response()->json($chapter->load(['tags']));
|
||||
}
|
||||
|
||||
@ -70,6 +72,7 @@ class ChapterApiController extends ApiController
|
||||
$chapter = Chapter::visible()->with(['tags', 'createdBy', 'updatedBy', 'ownedBy', 'pages' => function (HasMany $query) {
|
||||
$query->visible()->get(['id', 'name', 'slug']);
|
||||
}])->findOrFail($id);
|
||||
|
||||
return response()->json($chapter);
|
||||
}
|
||||
|
||||
@ -82,6 +85,7 @@ class ChapterApiController extends ApiController
|
||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
||||
|
||||
$updatedChapter = $this->chapterRepo->update($chapter, $request->all());
|
||||
|
||||
return response()->json($updatedChapter->load(['tags']));
|
||||
}
|
||||
|
||||
@ -95,6 +99,7 @@ class ChapterApiController extends ApiController
|
||||
$this->checkOwnablePermission('chapter-delete', $chapter);
|
||||
|
||||
$this->chapterRepo->destroy($chapter);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Entities\Models\Chapter;
|
||||
use BookStack\Entities\Tools\ExportFormatter;
|
||||
@ -18,23 +20,27 @@ class ChapterExportApiController extends ApiController
|
||||
|
||||
/**
|
||||
* Export a chapter as a PDF file.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function exportPdf(int $id)
|
||||
{
|
||||
$chapter = Chapter::visible()->findOrFail($id);
|
||||
$pdfContent = $this->exportFormatter->chapterToPdf($chapter);
|
||||
|
||||
return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a chapter as a contained HTML file.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function exportHtml(int $id)
|
||||
{
|
||||
$chapter = Chapter::visible()->findOrFail($id);
|
||||
$htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter);
|
||||
|
||||
return $this->downloadResponse($htmlContent, $chapter->slug . '.html');
|
||||
}
|
||||
|
||||
@ -45,6 +51,7 @@ class ChapterExportApiController extends ApiController
|
||||
{
|
||||
$chapter = Chapter::visible()->findOrFail($id);
|
||||
$textContent = $this->exportFormatter->chapterToPlainText($chapter);
|
||||
|
||||
return $this->downloadResponse($textContent, $chapter->slug . '.txt');
|
||||
}
|
||||
|
||||
@ -55,6 +62,7 @@ class ChapterExportApiController extends ApiController
|
||||
{
|
||||
$chapter = Chapter::visible()->findOrFail($id);
|
||||
$markdown = $this->exportFormatter->chapterToMarkdown($chapter);
|
||||
|
||||
return $this->downloadResponse($markdown, $chapter->slug . '.md');
|
||||
}
|
||||
}
|
||||
|
@ -16,20 +16,20 @@ class PageApiController extends ApiController
|
||||
|
||||
protected $rules = [
|
||||
'create' => [
|
||||
'book_id' => 'required_without:chapter_id|integer',
|
||||
'book_id' => 'required_without:chapter_id|integer',
|
||||
'chapter_id' => 'required_without:book_id|integer',
|
||||
'name' => 'required|string|max:255',
|
||||
'html' => 'required_without:markdown|string',
|
||||
'markdown' => 'required_without:html|string',
|
||||
'tags' => 'array',
|
||||
'name' => 'required|string|max:255',
|
||||
'html' => 'required_without:markdown|string',
|
||||
'markdown' => 'required_without:html|string',
|
||||
'tags' => 'array',
|
||||
],
|
||||
'update' => [
|
||||
'book_id' => 'required|integer',
|
||||
'book_id' => 'required|integer',
|
||||
'chapter_id' => 'required|integer',
|
||||
'name' => 'string|min:1|max:255',
|
||||
'html' => 'string',
|
||||
'markdown' => 'string',
|
||||
'tags' => 'array',
|
||||
'name' => 'string|min:1|max:255',
|
||||
'html' => 'string',
|
||||
'markdown' => 'string',
|
||||
'tags' => 'array',
|
||||
],
|
||||
];
|
||||
|
||||
@ -44,6 +44,7 @@ class PageApiController extends ApiController
|
||||
public function list()
|
||||
{
|
||||
$pages = Page::visible();
|
||||
|
||||
return $this->apiListingResponse($pages, [
|
||||
'id', 'book_id', 'chapter_id', 'name', 'slug', 'priority',
|
||||
'draft', 'template',
|
||||
@ -89,6 +90,7 @@ class PageApiController extends ApiController
|
||||
public function read(string $id)
|
||||
{
|
||||
$page = $this->pageRepo->getById($id, []);
|
||||
|
||||
return response()->json($page->forJsonDisplay());
|
||||
}
|
||||
|
||||
@ -107,12 +109,13 @@ class PageApiController extends ApiController
|
||||
$parent = null;
|
||||
if ($request->has('chapter_id')) {
|
||||
$parent = Chapter::visible()->findOrFail($request->get('chapter_id'));
|
||||
} else if ($request->has('book_id')) {
|
||||
} elseif ($request->has('book_id')) {
|
||||
$parent = Book::visible()->findOrFail($request->get('book_id'));
|
||||
}
|
||||
|
||||
if ($parent && !$parent->matches($page->getParent())) {
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
|
||||
try {
|
||||
$this->pageRepo->move($page, $parent->getType() . ':' . $parent->id);
|
||||
} catch (Exception $exception) {
|
||||
@ -125,6 +128,7 @@ class PageApiController extends ApiController
|
||||
}
|
||||
|
||||
$updatedPage = $this->pageRepo->update($page, $request->all());
|
||||
|
||||
return response()->json($updatedPage->forJsonDisplay());
|
||||
}
|
||||
|
||||
@ -138,6 +142,7 @@ class PageApiController extends ApiController
|
||||
$this->checkOwnablePermission('page-delete', $page);
|
||||
|
||||
$this->pageRepo->destroy($page);
|
||||
|
||||
return response('', 204);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace BookStack\Http\Controllers\Api;
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers\Api;
|
||||
|
||||
use BookStack\Entities\Models\Page;
|
||||
use BookStack\Entities\Tools\ExportFormatter;
|
||||
@ -15,23 +17,27 @@ class PageExportApiController extends ApiController
|
||||
|
||||
/**
|
||||
* Export a page as a PDF file.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function exportPdf(int $id)
|
||||
{
|
||||
$page = Page::visible()->findOrFail($id);
|
||||
$pdfContent = $this->exportFormatter->pageToPdf($page);
|
||||
|
||||
return $this->downloadResponse($pdfContent, $page->slug . '.pdf');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export a page as a contained HTML file.
|
||||
*
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function exportHtml(int $id)
|
||||
{
|
||||
$page = Page::visible()->findOrFail($id);
|
||||
$htmlContent = $this->exportFormatter->pageToContainedHtml($page);
|
||||
|
||||
return $this->downloadResponse($htmlContent, $page->slug . '.html');
|
||||
}
|
||||
|
||||
@ -42,6 +48,7 @@ class PageExportApiController extends ApiController
|
||||
{
|
||||
$page = Page::visible()->findOrFail($id);
|
||||
$textContent = $this->exportFormatter->pageToPlainText($page);
|
||||
|
||||
return $this->downloadResponse($textContent, $page->slug . '.txt');
|
||||
}
|
||||
|
||||
@ -52,6 +59,7 @@ class PageExportApiController extends ApiController
|
||||
{
|
||||
$page = Page::visible()->findOrFail($id);
|
||||
$markdown = $this->exportFormatter->pageToMarkdown($page);
|
||||
|
||||
return $this->downloadResponse($markdown, $page->slug . '.md');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user