|
@@ -0,0 +1,96 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: Administrator
|
|
|
+ * Date: 2019-06-12
|
|
|
+ * Time: 9:35
|
|
|
+ */
|
|
|
+
|
|
|
+namespace App\Http\Controllers\V2;
|
|
|
+
|
|
|
+
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use App\Repositories\V2\VideoGroupRepository;
|
|
|
+use App\Transformers\DetailVideoGroupTansformer;
|
|
|
+use App\Transformers\VideoGroupTransformer;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
+use League\Fractal\Manager;
|
|
|
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
+use League\Fractal\Resource\Collection;
|
|
|
+use League\Fractal\Resource\Item;
|
|
|
+
|
|
|
+class VideoGroupController extends Controller {
|
|
|
+
|
|
|
+ public function __construct(VideoGroupRepository $videoGroupRepository) {
|
|
|
+ $this->videoGroupRepository = $videoGroupRepository;
|
|
|
+ }
|
|
|
+ //列表
|
|
|
+ public function index(Request $request){
|
|
|
+ $topicGroup = $this->videoGroupRepository->index($request->all());
|
|
|
+ $fractal = new Manager();
|
|
|
+ $resource = new Collection($topicGroup, new VideoGroupTransformer());
|
|
|
+ $resource->setPaginator(new IlluminatePaginatorAdapter($topicGroup));
|
|
|
+ $data = $fractal->createData($resource)->toArray();
|
|
|
+ $data['extra'] = [
|
|
|
+ 'filters' => [
|
|
|
+ 'name',
|
|
|
+ ],
|
|
|
+ 'columns' => [
|
|
|
+ 'id',
|
|
|
+ 'name',
|
|
|
+ 'video_count',
|
|
|
+ 'created_at',
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ //创建
|
|
|
+ public function create(Request $request){
|
|
|
+ $data = $request->only('name');
|
|
|
+ $validator = Validator::make($data, [
|
|
|
+ 'name' => 'required|string|max:12',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->videoGroupRepository->create($data);
|
|
|
+ }
|
|
|
+ //详情
|
|
|
+ public function view(Request $request){
|
|
|
+ $data = $request->only('id');
|
|
|
+ $validator = Validator::make($data, [
|
|
|
+ 'id' => 'required|integer|max:12',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ $info = $this->videoGroupRepository->view($data);
|
|
|
+ return $this->response->item($info, new DetailVideoGroupTansformer());
|
|
|
+ }
|
|
|
+ //设置排序
|
|
|
+ public function edit(Request $request){
|
|
|
+ $data = $request->only('name','name','info');
|
|
|
+ $validator = Validator::make($data, [
|
|
|
+ 'id' => 'required|integer|max:12',
|
|
|
+ 'name' => 'required|string|max:12',
|
|
|
+ 'info' => 'string'
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->videoGroupRepository->edit($data);
|
|
|
+ }
|
|
|
+ //添加分组内容
|
|
|
+ public function addVideoInfo(Request $request){
|
|
|
+ $data = $request->only('video_group_id','post_id');
|
|
|
+ $validator = Validator::make($data, [
|
|
|
+ 'video_group_id' => 'required|integer|max:12',
|
|
|
+ 'post_id' => 'required|integer|max:12',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
+ }
|
|
|
+ return $this->videoGroupRepository->addVideoInfo($data);
|
|
|
+ }
|
|
|
+}
|