api code global jain
This commit is contained in:
121
app/Http/Controllers/PostController.php
Normal file
121
app/Http/Controllers/PostController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Http\Requests\Api\Post\StorePostRequest;
|
||||
use App\Http\Requests\Api\Post\UpdatePostRequest;
|
||||
use App\Repositories\Api\Access\Post\PostInterface as PostRepo;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Http\Controllers\Api\ApiController;
|
||||
|
||||
class PostController extends ApiController
|
||||
{
|
||||
/**
|
||||
* @param PostRepo $userRepo
|
||||
* PostController constructor.
|
||||
*/
|
||||
public function __construct(PostRepo $postRepo)
|
||||
{
|
||||
$this->postRepo = $postRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$response = $this->postRepo->getAllPosts();
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\StorePostRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StorePostRequest $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->postRepo->storePost($request->all());
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Post $post
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Post $post)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Post $post
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Post $post)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\UpdatePostRequest $request
|
||||
* @param \App\Models\Post $post
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdatePostRequest $request, Post $post)
|
||||
{
|
||||
try {
|
||||
$response = $this->postRepo->updatePost($request->all(), $post);
|
||||
$this->updateStatusCode($response);
|
||||
|
||||
return $this->respond($response);
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->respondInternalError(trans('api.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Post $post
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Post $post)
|
||||
{ //
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user