Commit 30418788 authored by cygnet's avatar cygnet

Refactoring of blogs apis

parent 43e1260b
......@@ -23,9 +23,9 @@ class BlogsController extends APIController
}
/**
* Return the users.
* Return the blogs.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
......@@ -39,9 +39,9 @@ class BlogsController extends APIController
/**
* Return the specified resource.
*
* @param User $user
* @param Blog blog
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function show(Blog $blog)
{
......@@ -53,11 +53,12 @@ class BlogsController extends APIController
*
* @param Request $request
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
$validation = $this->validatingRequest($request);
$validation = $this->validateBlog($request);
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
}
......@@ -68,14 +69,16 @@ class BlogsController extends APIController
}
/**
* Update blog
*
* @param Blog $blog
* @param UpdateBlogRequest $request
* @param Request $request
*
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function update(Request $request, Blog $blog)
{
$validation = $this->validatingRequest($request, 'update');
$validation = $this->validateBlog($request, 'update');
if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first());
......@@ -88,7 +91,31 @@ class BlogsController extends APIController
return new BlogsResource($blog);
}
public function validatingRequest(Request $request, $type = 'insert')
/**
* Delete Blog
*
* @param Blog $blog
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(Blog $blog, Request $request)
{
$this->repository->delete($blog);
return $this->respond([
'message' => trans('alerts.backend.blogs.deleted'),
]);
}
/**
* validate Blog.
*
* @param $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function validateBlog(Request $request, $type = 'insert')
{
$featured_image = ($type == 'insert') ? 'required' : '';
......@@ -102,7 +129,11 @@ class BlogsController extends APIController
return $validation;
}
/**
* validate message for validate blog.
*
* @return \Illuminate\Http\JsonResponse
*/
public function messages()
{
return [
......@@ -111,16 +142,4 @@ class BlogsController extends APIController
];
}
/**
* @param Blog $blog
* @param DeleteBlogRequest $request
*
* @return mixed
*/
public function destroy(Blog $blog, Request $request)
{
$this->repository->delete($blog);
return ['message'=>'success'];
}
}
......@@ -25,7 +25,7 @@ class FaqsController extends APIController
/**
* Return the faqs.
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
......@@ -41,7 +41,7 @@ class FaqsController extends APIController
*
* @param Faq $faq
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function show(Faq $faq)
{
......@@ -53,7 +53,7 @@ class FaqsController extends APIController
*
* @param Request $request
*
* @return \Illuminate\Http\Response
* @return \Illuminate\Http\JsonResponse
*/
public function store(Request $request)
{
......@@ -73,7 +73,7 @@ class FaqsController extends APIController
* @param Faq $faq
* @param Request $request
*
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function update(Request $request, Faq $faq)
{
......@@ -98,7 +98,7 @@ class FaqsController extends APIController
* @param Faq $faq
* @param Request $request
*
* @return mixed
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(Faq $faq, Request $request)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment