<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2017/11/20
 * Time: 16:17
 */

namespace App\Http\Controllers\Channel\Promotion;

use App\Http\Controllers\Channel\BaseController;
use App\Http\Controllers\Channel\Promotion\Transformers\HeadlinelTransformer;
use App\Modules\Promotion\Services\PromotionService;
use DB;
use Illuminate\Http\Request;

class HeadlineController extends BaseController
{
    /**
     * @apiDefine promotion 推广
     */

    /**
     * @apiVersion 1.0.0
     * @api {GET} promotion/headlines 获取推广标题列表
     * @apiGroup promotion
     * @apiName getPromotionHeadlines
     * @apiParam{String}type 类型(1:男频、2:女频)
     *
     * @apiSuccess {Number}  id 标题ID.
     * @apiSuccess {String}  title 标题内容.
     * @apiSuccessExample {json} Success-Response:
     *
     *     {
     *         "code": 0,
     *         "msg": "",
     *
     *         "data": [
     *           {
     *              "id": 1,
     *              "title": "sfsd"
     *            },
     *           {
     *              "id": 2,
     *              "title": "sfsd"
     *            }
     *        ]
     *     }
     */

    function getPromotionHeadlines(Request $request)
    {
        $type = $request->has('type') ? $request->input('type') : '';
        if (empty($type)) {
            return response()->error("PARAM_EMPTY");
        }
        $promotionHeadlinesResult = PromotionService::getAllHeadlines($type);
        return response()->collection(new HeadlinelTransformer(), $promotionHeadlinesResult);
    }
}