api code global jain
This commit is contained in:
10
app/Repositories/Api/Access/Jati/JatiInterface.php
Normal file
10
app/Repositories/Api/Access/Jati/JatiInterface.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Api\Access\Jati;
|
||||
|
||||
interface JatiInterface
|
||||
{
|
||||
public function getJatiDetail(array $data);
|
||||
|
||||
public function storeJati(array $data);
|
||||
}
|
||||
102
app/Repositories/Api/Access/Jati/JatiRepository.php
Normal file
102
app/Repositories/Api/Access/Jati/JatiRepository.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Api\Access\Jati;
|
||||
|
||||
use App\Models\Jati;
|
||||
use App\Constant\Constant;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Repositories\Api\Access\Jati\JatiInterface;
|
||||
|
||||
class JatiRepository implements JatiInterface
|
||||
{
|
||||
/**
|
||||
* @var Jati
|
||||
*/
|
||||
protected $jati;
|
||||
|
||||
/**
|
||||
* @param Jati $jati
|
||||
* JatiRepository constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct(Jati $jati)
|
||||
{
|
||||
$this->jati = $jati;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getJatiDetail(array $data)
|
||||
{
|
||||
$response = [];
|
||||
|
||||
try {
|
||||
$user = loggedInUser();
|
||||
|
||||
$jatiData = $this->jati->with('dharma')->where('status', Constant::STATUS_ONE);
|
||||
|
||||
if (isset($data['dharma_id']) && !empty($data['dharma_id'])) {
|
||||
$jatiData = $jatiData->where('dharma_id', $data['dharma_id']);
|
||||
}
|
||||
|
||||
$jatiData = $jatiData->get()->toArray();
|
||||
|
||||
if ($user && $jatiData) {
|
||||
$response['data'] = $jatiData;
|
||||
$response['status'] = Constant::CODE_200;
|
||||
|
||||
} else {
|
||||
$response['data'] = [];
|
||||
$response['status'] = Constant::CODE_401;
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
$response['message'] = trans('auth.something_went_wrong');
|
||||
$response['status'] = Constant::CODE_403;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function storeJati(array $data)
|
||||
{
|
||||
$response = [];
|
||||
|
||||
try {
|
||||
$user = loggedInUser();
|
||||
|
||||
$jati = $this->jati->query()->where([
|
||||
'name' => $data['name']
|
||||
])->first();
|
||||
|
||||
if ($jati) {
|
||||
$response['message'] = trans('auth.jati.exist');
|
||||
$response['status'] = Constant::CODE_403;
|
||||
|
||||
} else {
|
||||
$this->jati->create([
|
||||
'name' => $data['name'],
|
||||
'status' => Constant::STATUS_ZERO,
|
||||
'created_by' => $user->id
|
||||
]);
|
||||
|
||||
$response['message'] = trans('auth.jati.jati_in_review');
|
||||
$response['status'] = Constant::CODE_200;
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
$response['message'] = trans('auth.something_went_wrong');
|
||||
$response['status'] = Constant::CODE_403;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user