change strcture controller becuse repet some code in 3 file and get same code in model
This commit is contained in:
@@ -42,178 +42,100 @@ class HarimOfficeController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function rejectRequest(RejectRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::NO->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_TAVASOT_MOAVEN->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::NO->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_TAVASOT_MOAVEN->value,
|
||||
'state_name' => HarimStates::BARESI_TAVASOT_MOAVEN->label(),
|
||||
'is_possible' => false,
|
||||
]);
|
||||
});
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function referRequest(ReferRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::REFER->value;
|
||||
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_EDARE_SHAHRESTAN->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::REFER->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_EDARE_SHAHRESTAN->value,
|
||||
'state_name' => HarimStates::BARESI_EDARE_SHAHRESTAN->label(),
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function needRoadAccess(NeedRoadAccessRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::YES->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_TAVASOT_MOAVEN->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::YES->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_TAVASOT_MOAVEN->value,
|
||||
'state_name' => HarimStates::BARESI_TAVASOT_MOAVEN->label(),
|
||||
'is_possible' => true,
|
||||
'need_access_road' => true,
|
||||
'need_payment' => $request->need_payment,
|
||||
]);
|
||||
});
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function withoutRoadAccess(WithoutRoadAccessRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::YES->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_TAVASOT_MOAVEN->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::YES->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_TAVASOT_MOAVEN->value,
|
||||
'state_name' => HarimStates::BARESI_TAVASOT_MOAVEN->label(),
|
||||
'is_possible' => true,
|
||||
'need_access_road' => false,
|
||||
'need_payment' => $request->need_payment,
|
||||
]);
|
||||
});
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function fileAccepted(FileAcceptedRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::YES->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::YES->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->value,
|
||||
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->label(),
|
||||
'access_road_allowed' => true,
|
||||
]);
|
||||
});
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function fileRejected(FileRejectedRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::NO->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->value;
|
||||
|
||||
$harim->update([
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::YES->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->value,
|
||||
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_MOAVEN->label(),
|
||||
'access_road_allowed' => false,
|
||||
]);
|
||||
});
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
|
||||
public function show(ShowRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
return $this->successResponse($harim->load('histories'));
|
||||
@@ -230,34 +152,21 @@ class HarimOfficeController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function computingPayment(ComputingPaymentRequest $request, Harim $harim): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($request, $harim) {
|
||||
$action = HarimAction::CONFIRM->value;
|
||||
$harim->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $harim->state_id,
|
||||
'previous_state_name' => $harim->state_name,
|
||||
'expert_description' => $request->expert_description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$state = HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MOAVEN->value;
|
||||
|
||||
$harim->update([
|
||||
$harim->updateStateWithHistory(
|
||||
action:HarimAction::CONFIRM->value,
|
||||
description: $request->expert_description,
|
||||
data: [
|
||||
'state_id' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MOAVEN->value,
|
||||
'state_name' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MOAVEN->label(),
|
||||
'traffic' => $request->traffic,
|
||||
'position' => $request->position,
|
||||
'final_plan_space' => $request->final_plan_space,
|
||||
'road_type' => $request->road_type,
|
||||
'payment_amount' => $request->payment_amount,
|
||||
'state_id' => $state,
|
||||
'state_name' => HarimStates::name($state),
|
||||
]);
|
||||
});
|
||||
]
|
||||
);
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user