You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

5 years ago
<?php
namespace App\Http\Controllers\Manager;
use App\Models\Training;
class TrainingController extends CommonController
{
/**
* @OA\Get(
* path="/manager/get-videos",
5 years ago
* summary="V2-获取视频列表",
5 years ago
* description="获取视频列表",
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=false, description="查询关键词"),
* @OA\Parameter(name="page", in="query", @OA\Schema(type="integer"), required=false, description="当前页码默认为1"),
5 years ago
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="integer"), required=false, description="每页数量默认为3"),
5 years ago
* @OA\Response(
* response="200",
* description="获取视频列表"
* )
* )
*/
public function index()
{
$data = (new Training());
if (request()->keyword) {
$keyword = request()->keyword;
$data = $data->where(function ($query) use ($keyword) {
$query
->where("title", "like", "%{$keyword}%")
->orWhereHas("type", function ($query) use ($keyword) {
$query->where("name", "like", "%{$keyword}%");
});
});
}
5 years ago
$page_size = request()->page_size ? (int)request()->page_size : 3;
5 years ago
$data = $data->with(["type" => function ($query) {
$query->select("id", "name");
5 years ago
}])->select("id", "type_id", "title", "poster", "video as video_stopped", "published_at")->orderBy("published_at","desc")->paginate($page_size);
5 years ago
return response()->json($data->toArray());
}
5 years ago
/**
* @OA\Get(
* path="/manager/get-video/{id}",
* summary="V2-获取单条视频数据",
* description="获取单条视频数据",
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="视频内容ID"),
* @OA\Response(
* response="200",
* description="获取单条视频数据"
* )
* )
*/
public function getVideo($id)
{
$video = Training::with(["type" => function ($query) {
$query->select("id", "name");
5 years ago
}])->select("id", "type_id", "title", "poster", "video as video_stopped", "published_at")->find($id);
5 years ago
return response()->json($video->toArray());
}
5 years ago
}