<?php

namespace Tet\Test\Http\Controllers;

use App\Http\Controllers\PublicController as CMSPublicController;
use Tet\Test\Interfaces\NewsRepositoryInterface;

class NewsPublicController extends CMSPublicController
{
    /**
     * Constructor.
     *
     * @param type \Tet\News\Interfaces\NewsRepositoryInterface $news
     *
     * @return type
     */
    public function __construct(NewsRepositoryInterface $news)
    {
        $this->repository = $news;
        parent::__construct();
    }

    /**
     * Show news's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $news = $this->repository->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();

        return $this->theme->of('test::public.news.index', compact('news'))->render();
    }

    /**
     * Show news.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show($slug)
    {
        $news = $this->repository->scopeQuery(function($query) use ($slug) {
            return $query->orderBy('id','DESC')
                         ->where('slug', $slug);
        })->first(['*']);

        return $this->theme->of('test::public.news.show', compact('news'))->render();
    }
}