Commit 30418788 authored by cygnet's avatar cygnet

Refactoring of blogs apis

parent 43e1260b
...@@ -23,9 +23,9 @@ class BlogsController extends APIController ...@@ -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) public function index(Request $request)
{ {
...@@ -39,9 +39,9 @@ class BlogsController extends APIController ...@@ -39,9 +39,9 @@ class BlogsController extends APIController
/** /**
* Return the specified resource. * Return the specified resource.
* *
* @param User $user * @param Blog blog
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
public function show(Blog $blog) public function show(Blog $blog)
{ {
...@@ -53,29 +53,32 @@ class BlogsController extends APIController ...@@ -53,29 +53,32 @@ class BlogsController extends APIController
* *
* @param Request $request * @param Request $request
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$validation = $this->validatingRequest($request); $validation = $this->validateBlog($request);
if ($validation->fails()) { if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first()); return $this->throwValidation($validation->messages()->first());
} }
$this->repository->create($request->all()); $this->repository->create($request->all());
return new BlogsResource(Blog::orderBy('created_at', 'desc')->first()); return new BlogsResource(Blog::orderBy('created_at', 'desc')->first());
} }
/** /**
* Update blog
*
* @param Blog $blog * @param Blog $blog
* @param UpdateBlogRequest $request * @param Request $request
* *
* @return mixed * @return \Illuminate\Http\JsonResponse
*/ */
public function update(Request $request, Blog $blog) public function update(Request $request, Blog $blog)
{ {
$validation = $this->validatingRequest($request, 'update'); $validation = $this->validateBlog($request, 'update');
if ($validation->fails()) { if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first()); return $this->throwValidation($validation->messages()->first());
...@@ -88,7 +91,31 @@ class BlogsController extends APIController ...@@ -88,7 +91,31 @@ class BlogsController extends APIController
return new BlogsResource($blog); 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' : ''; $featured_image = ($type == 'insert') ? 'required' : '';
...@@ -102,7 +129,11 @@ class BlogsController extends APIController ...@@ -102,7 +129,11 @@ class BlogsController extends APIController
return $validation; return $validation;
} }
/**
* validate message for validate blog.
*
* @return \Illuminate\Http\JsonResponse
*/
public function messages() public function messages()
{ {
return [ return [
...@@ -111,16 +142,4 @@ class BlogsController extends APIController ...@@ -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 ...@@ -25,7 +25,7 @@ class FaqsController extends APIController
/** /**
* Return the faqs. * Return the faqs.
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
public function index(Request $request) public function index(Request $request)
{ {
...@@ -41,7 +41,7 @@ class FaqsController extends APIController ...@@ -41,7 +41,7 @@ class FaqsController extends APIController
* *
* @param Faq $faq * @param Faq $faq
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
public function show(Faq $faq) public function show(Faq $faq)
{ {
...@@ -53,7 +53,7 @@ class FaqsController extends APIController ...@@ -53,7 +53,7 @@ class FaqsController extends APIController
* *
* @param Request $request * @param Request $request
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
public function store(Request $request) public function store(Request $request)
{ {
...@@ -73,7 +73,7 @@ class FaqsController extends APIController ...@@ -73,7 +73,7 @@ class FaqsController extends APIController
* @param Faq $faq * @param Faq $faq
* @param Request $request * @param Request $request
* *
* @return mixed * @return \Illuminate\Http\JsonResponse
*/ */
public function update(Request $request, Faq $faq) public function update(Request $request, Faq $faq)
{ {
...@@ -98,7 +98,7 @@ class FaqsController extends APIController ...@@ -98,7 +98,7 @@ class FaqsController extends APIController
* @param Faq $faq * @param Faq $faq
* @param Request $request * @param Request $request
* *
* @return mixed * @return \Illuminate\Http\JsonResponse
*/ */
public function destroy(Faq $faq, Request $request) 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