残り親のAPIの追加又は修正

このコミットが含まれているのは:
守矢諏訪子 2021-11-04 13:28:58 +09:00
コミット 561bbd920a
2個のファイルの変更50行の追加3行の削除

ファイルの表示

@ -9,12 +9,43 @@ use Illuminate\Support\Facades\Log;
use App\Models\FatherRelation;
class FatherRelationsController extends Controller {
public function register (Register $r) {
if (!isset($r->father_id) || !isset($r->identity)) {
return ['status_code' => 400, 'error_messages' => ['子の追加に失敗しました。']];
}
if (null === ($child = Child::select('id')->where('identity', $r->identity)->first())) {
return ['status_code' => 400, 'error_messages' => ['子の追加に失敗しました。']];
}
$create = [
'father_id' => $r->father_id,
'child_id' => $child->id,
'hire_at' => date('Y-m-d H:i:s', time()),
];
try {
FatherRelation::create($create);
} catch (\Throwable $e) {
// 失敗
Log::critical($e->getMessage());
return ['status_code' => 400, 'error_messages' => ['子の追加に失敗しました。']];
}
return ['status_code' => 200, 'success_messages' => ['子の追加に成功しました。'], 'params' => ['child_id' => $child_id]];
// 1.POSTで受け取ったidentityと紐づくchildrenのデータのidを取得。
// 2.1で取得したidとPOSTで受け取ったfather_idをfather_relatoinsに登録。(hire_atはPOST時の日時)
}
public function updateHireDate (Request $r, $child_id) {
if (!isset($child_id) || !isset($r->father_id) || !isset($r->hire_at)) {
return ['status_code' => 400, 'success_messages' => ['子の入社日の更新に失敗しました。']];
}
$update = ['hire_at' => date('Y-m-d H:i:s', strtotime($r->hire_at))];
$update = [
'hire_at' => date('Y-m-d H:i:s', strtotime($r->hire_at)),
];
try {
FatherRelation::where('father_id', $r->father_id)->where('child_id', $child_id)->update($update);
@ -26,4 +57,20 @@ class FatherRelationsController extends Controller {
return ['status_code' => 200, 'success_messages' => ['子の入社日の更新に成功しました。']];
}
public function deleteRelationChild ($child_id) {
if (!isset($child_id)) {
return ['status_code' => 400, 'success_messages' => ['子の削除に失敗しました。']];
}
try {
FatherRelation::where('father_id', $r->session()->get('fathers')->id)->where('child_id', $child_id)->delete();
} catch (\Throwable $e) {
// 失敗
Log::critical($e->getMessage());
return ['status_code' => 400, 'success_messages' => ['子の削除に失敗しました。']];
}
return ['status_code' => 200, 'success_messages' => ['子の削除に成功しました。']];
}
}

ファイルの表示

@ -271,7 +271,7 @@ class MeetingsController extends Controller {
return ['status_code' => 200, 'params' => $result];
}
public function listOfFavoriteofFather (Request $r) {
public function listOfFavoriteOfFather (Request $r) {
if (!isset($r->father_id)) {
return ['status_code' => 400];
}
@ -302,7 +302,7 @@ class MeetingsController extends Controller {
return ['status_code' => 200, 'params' => $result];
}
public function listOfNonFavoriteofFather (Request $r) {
public function listOfNonFavoriteOfFather (Request $r) {
if (!isset($r->father_id)) {
return ['status_code' => 400];
}