Skip to content

Commit

Permalink
hide some fields (#45)
Browse files Browse the repository at this point in the history
* hide some fields

* hide some fields
  • Loading branch information
qunabu authored Jun 22, 2021
1 parent 1338905 commit 874a09f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Http/Controllers/ContentApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public function __construct(HeadlessH5PServiceContract $hh5pService, H5PContentR
$this->hh5pService = $hh5pService;
$this->contentRepository = $contentRepository;
}

public function index(Request $request): JsonResponse
{
$list = $this->contentRepository->list($request->get('per_page'));
$columns = ['title', 'id', 'library_id'];
$list = $request->get('per_page') !== null && $request->get('per_page') == 0 ? $this->contentRepository->unpaginatedList($columns) : $this->contentRepository->list($request->get('per_page'), $columns);
return response()->json($list, 200);
}

Expand All @@ -41,7 +42,7 @@ public function update(ContentStoreRequest $request, int $id): JsonResponse
'error' => $error->getMessage()
], 422);
}

return response()->json([
'id' => $contentId
], 200);
Expand All @@ -56,7 +57,7 @@ public function store(ContentStoreRequest $request): JsonResponse
'error' => $error->getMessage()
], 422);
}

return response()->json([
'id' => $contentId
], 200);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Swagger/ContentApiSwagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function update(ContentStoreRequest $request, int $id): JsonResponse;
* ),
* @OA\Parameter(
* name="per_page",
* description="items per page",
* description="items per page. If set to 0, returns ALL contents ",
* in="query",
* required=false,
* @OA\Schema(
Expand Down
4 changes: 3 additions & 1 deletion src/Repositories/Contracts/H5PContentRepositoryContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public function create(string $title, string $library, string $params, string $n

public function edit(int $id, string $title, string $library, string $params, string $nonce):int;

public function list($per_page = 15):LengthAwarePaginator;
public function list($per_page = 15, array $columns = ['*']):LengthAwarePaginator;

public function unpaginatedList(array $columns = ['*']):Collection;

public function delete(int $id):int;
}
34 changes: 29 additions & 5 deletions src/Repositories/H5PContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use EscolaLms\HeadlessH5P\Exceptions\H5PException;
use Illuminate\Pagination\LengthAwarePaginator;
use EscolaLms\HeadlessH5P\Helpers\Helpers;
use Illuminate\Support\Collection;

class H5PContentRepository implements H5PContentRepositoryContract
{
Expand All @@ -33,7 +34,7 @@ public function create(string $title, string $library, string $params, string $n
if ($libDb === null) {
throw new H5PException(H5PException::LIBRARY_NOT_FOUND);
}

$json = json_decode($params);

if ($json === null) {
Expand Down Expand Up @@ -66,7 +67,7 @@ public function edit(int $id, string $title, string $library, string $params, st
if ($libDb === null) {
throw new H5PException(H5PException::LIBRARY_NOT_FOUND);
}

$json = json_decode($params);

if ($json === null) {
Expand All @@ -88,7 +89,7 @@ public function edit(int $id, string $title, string $library, string $params, st
//'nonce'=>$nonce
], $id);


$this->moveTmpFilesToContentFolders($nonce, $id);

return $id;
Expand Down Expand Up @@ -119,9 +120,32 @@ private function moveTmpFilesToContentFolders($nonce, $contentId):bool
return true;
}

public function list($per_page = 15):LengthAwarePaginator
public function list($per_page = 15, array $columns = ['*']):LengthAwarePaginator
{
$paginator = H5PContent::with(
['library']
)->select($columns)->paginate(intval($per_page));
$paginator->getCollection()->transform(function ($content) {
// Your code here
$content->library->makeHidden(['semantics']);
$content->library->setAppends([]);
return $content;
});
return $paginator;
}

public function unpaginatedList(array $columns = ['*']):Collection
{
return H5PContent::with(['library'])->paginate(intval($per_page));
$list = H5PContent::with(
['library']
)->select($columns)->get();
$list->transform(function ($content) {
// Your code here
$content->library->makeHidden(['semantics']);
$content->library->setAppends([]);
return $content;
});
return $list;
}

public function delete(int $id):int
Expand Down

0 comments on commit 874a09f

Please sign in to comment.