<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use JiGuang\JSMS as JSMS;
use Illuminate\Support\Facades\Redis;
use Dingo\Api\Http\Response;
use Validator;
use DB;
use App\Models\User;
use App\Services\SystemService;
use App\Models\UserAddress;
use App\Models\Doctors;
use App\Models\Article;

/**
 * 
* Copyright: Copyright (c) 2019 
* 
* @Description: 
* @version: v1.0.0
* @author: fengyichao
* @date: 2019年10月12日 下午4:22:09 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* 2019年10月12日     fengyichao           v1.0.0               修改原因
 */
class ArticleController extends ApiController {
	// 利用 Laravel 的自动解析功能注入 CartService 类
	public function __construct(SystemService $systemService) {
		$this->systemService = $systemService;
	}
	public function list(Request $request) {
		$page = $request->input ( 'page', 1 );
		$queryBuild = Doctors::select ( [ 
				'id',
				'title',
				'image',
				'good_at'
		] );
		$products = $queryBuild->orderBy ( 'id', 'desc' )->paginate ( 15, [ 
				'id',
				'title',
				'image',
				'good_at'
		], 'page', $page );
		$resultData = $products;
		return $this->success ( $resultData );
	}
	/**
	 *
	 * @api {post} article/detail 文章-文章详情
	 * @apiName article/detail
	 * @apiGroup article
	 * @apiParam {int} article_id 文章id
	 * @apiSuccess  {string} title 标题
	 * @apiSuccess  {string} head_img 头图
	 * @apiSuccess  {string} content 内容 html格式
	 * @apiParamExample {curl} Example usage:
	 * http://59.110.137.245:8080/api/doctor/detail?doctor_id=1
	 */
	public function detail(Request $request) {
		$rules = [
				'article_id' => [
						'required'
				]
		];
		
		$validator = app ( 'validator' )->make ( $request->all (), $rules );
		if ($validator->fails ()) {
			return $this->throwErrors ( $validator );
		}
		$item = Article::find ( $request->article_id );
		
		return $this->success ( $item );
	}
}
