140 lines
4.0 KiB
PHP
140 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Access;
|
|
|
|
use App\Http\Requests\Api\Vihar\UpdateViharRequest;
|
|
use App\Http\Requests\Api\Vihar\StoreViharRequest;
|
|
use App\Repositories\Api\Access\Vihar\ViharInterface as ViharRepository;
|
|
use App\Models\Vihar;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Http\Controllers\Api\ApiController;
|
|
use App\Http\Requests\Api\Vihar\DeleteViharRequest;
|
|
use App\Http\Requests\Api\Vihar\GetViharRequest;
|
|
use Exception;
|
|
|
|
class ViharController extends ApiController
|
|
{
|
|
|
|
/**
|
|
* @param ViharRepository $viharRepository
|
|
* ViharController constructor.
|
|
*/
|
|
public function __construct(ViharRepository $viharRepository)
|
|
{
|
|
$this->viharRepository = $viharRepository;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(GetViharRequest $request)
|
|
{
|
|
try {
|
|
$response = $this->viharRepository->getViharList($request->all());
|
|
$this->updateStatusCode($response);
|
|
|
|
return $this->respond($response);
|
|
} catch (Exception $ex) {
|
|
Log::error($ex);
|
|
return $this->respondInternalError(trans('api.something_went_wrong'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function getPastViharList(GetViharRequest $request)
|
|
{
|
|
try {
|
|
$response = $this->viharRepository->getPastViharList($request->all());
|
|
$this->updateStatusCode($response);
|
|
|
|
return $this->respond($response);
|
|
} catch (Exception $ex) {
|
|
Log::error($ex);
|
|
return $this->respondInternalError(trans('api.something_went_wrong'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param App\Http\Requests\Api\Vihar\StoreViharRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StoreViharRequest $request)
|
|
{
|
|
try {
|
|
$response = $this->viharRepository->storeVihar($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\Vihar $vihar
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Vihar $vihar)
|
|
{
|
|
try {
|
|
$response = $this->viharRepository->showVihar($vihar);
|
|
$this->updateStatusCode($response);
|
|
|
|
return $this->respond($response);
|
|
} catch (Exception $ex) {
|
|
Log::error($ex);
|
|
return $this->respondInternalError(trans('api.something_went_wrong'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param App\Http\Requests\Api\Vihar\UpdateViharRequest $request
|
|
* @param \App\Models\Vihar $vihar
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(UpdateViharRequest $request, Vihar $vihar)
|
|
{
|
|
try {
|
|
$response = $this->viharRepository->updateVihar($request->all(), $vihar);
|
|
$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\Vihar $vihar
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(DeleteViharRequest $request, Vihar $vihar)
|
|
{
|
|
try {
|
|
$response = $this->viharRepository->destroyVihar($vihar);
|
|
$this->updateStatusCode($response);
|
|
|
|
return $this->respond($response);
|
|
} catch (\Exception $ex) {
|
|
Log::error($ex);
|
|
return $this->respondInternalError(trans('api.something_went_wrong'));
|
|
}
|
|
}
|
|
}
|