103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
|
|
<?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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|