Merge remote-tracking branch 'origin/master'
commit
d4cb9921c7
|
|
@ -5,14 +5,11 @@ namespace App\Http\Controllers\Api\Publications;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Pages\Page;
|
use App\Models\Pages\Page;
|
||||||
use App\Models\Publications\Publication;
|
use App\Models\Publications\Publication;
|
||||||
use App\Models\Publications\PublicationType;
|
|
||||||
use App\Services\Filters\FiltersService;
|
use App\Services\Filters\FiltersService;
|
||||||
use App\Transformers\Publications\PublicationTransformer;
|
use App\Transformers\Publications\PublicationTransformer;
|
||||||
use App\Transformers\Registries\RegistryTransformer;
|
use App\Transformers\Registries\RegistryTransformer;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Date;
|
|
||||||
|
|
||||||
class PublicationsController extends Controller {
|
class PublicationsController extends Controller {
|
||||||
protected Publication $model;
|
protected Publication $model;
|
||||||
|
|
@ -29,9 +26,17 @@ class PublicationsController extends Controller {
|
||||||
public function index(Request $request): JsonResponse {
|
public function index(Request $request): JsonResponse {
|
||||||
$filters = collect($request->has('filters') ? json_decode($request->get('filters'), true) : [])->filter(function($val) {return $val;});
|
$filters = collect($request->has('filters') ? json_decode($request->get('filters'), true) : [])->filter(function($val) {return $val;});
|
||||||
$query = $this->model->query()->orderBy('published_at', 'desc');
|
$query = $this->model->query()->orderBy('published_at', 'desc');
|
||||||
|
if ($page = Page::byUuid($request->get('page_id'))->first()) {
|
||||||
|
$query->where(['page_id' => $page->id]);
|
||||||
|
} elseif ($page = Page::query()->where(['sub_type' => 'publication-' . $request->get('type')])->first()) {
|
||||||
|
$query->where('page_id', $page->id);
|
||||||
|
}
|
||||||
$service = FiltersService::getService('publications');
|
$service = FiltersService::getService('publications');
|
||||||
$service->applyFilters($query, $filters);
|
$service->applyFilters($query, $filters);
|
||||||
$paginator = $query->paginate(config('app.pagination_limit'));
|
$paginator = $query->paginate($request->get('limit', config('app.pagination_limit')));
|
||||||
|
if ($request->has('limit')) {
|
||||||
|
$paginator->appends('limit', $request->get('limit'));
|
||||||
|
}
|
||||||
return fractal($paginator, new PublicationTransformer())->respond();
|
return fractal($paginator, new PublicationTransformer())->respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,10 +61,9 @@ class PublicationsController extends Controller {
|
||||||
|
|
||||||
public function published(Request $request, $uuid): JsonResponse {
|
public function published(Request $request, $uuid): JsonResponse {
|
||||||
$model = $this->model->byUuid($uuid)->firstOrFail();
|
$model = $this->model->byUuid($uuid)->firstOrFail();
|
||||||
$data = [
|
if ($request->has('publish')) {
|
||||||
'is_published' => $request->get('publish')
|
$model->update(['is_published' => $request->get('publish')]);
|
||||||
];
|
}
|
||||||
$model->update($data);
|
|
||||||
return fractal($model, new PublicationTransformer())->respond();
|
return fractal($model, new PublicationTransformer())->respond();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@ class PagesTableSeeder extends Seeder
|
||||||
'Консультационные услуги' => [],
|
'Консультационные услуги' => [],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'ТК 465 “Строительство”' => [
|
'ТК 465 «Строительство»' => [
|
||||||
'children' => [
|
'children' => [
|
||||||
'Руководство' => [],
|
'Руководство' => [],
|
||||||
'Структура' => ['type' => PageType::TK_STRUCTURE],
|
'Структура' => ['type' => PageType::TK_STRUCTURE],
|
||||||
'Состав' => [],
|
'Состав' => [],
|
||||||
'Документы' => ['type' => PageType::REGISTRY, 'registry_type' => RegistryType::CATEGORIZED],
|
'Документы' => ['type' => PageType::REGISTRY, 'registry_type' => RegistryType::CATEGORIZED],
|
||||||
'АИС ТК 465 “Строительство”' => []
|
'АИС ТК 465 «Строительство»' => []
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'Реестр требований ФЗ-63' => [],
|
'Реестр требований ФЗ-63' => [],
|
||||||
|
|
@ -60,7 +60,7 @@ class PagesTableSeeder extends Seeder
|
||||||
'Международная деятельность' => [
|
'Международная деятельность' => [
|
||||||
'children' => [
|
'children' => [
|
||||||
'ISO' => [],
|
'ISO' => [],
|
||||||
'МТК 465 “Строительство”' => [],
|
'МТК 465 «Строительство»' => [],
|
||||||
'Межправительственный совет' => [],
|
'Межправительственный совет' => [],
|
||||||
'Базовая организация СНГ' => [],
|
'Базовая организация СНГ' => [],
|
||||||
'Разработка ТР ЕАЭС' => [],
|
'Разработка ТР ЕАЭС' => [],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue