From 561bbd920a15cc26fe551ad9b85af8af55e7ea84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=82=AF=E3=83=8B=E3=82=AB=E3=83=AB=E8=AB=8F?= =?UTF-8?q?=E8=A8=AA=E5=AD=90?= Date: Thu, 4 Nov 2021 13:28:58 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AE=8B=E3=82=8A=E8=A6=AA=E3=81=AEAPI?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0=E5=8F=88=E3=81=AF=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/FatherRelationsController.php | 49 ++++++++++++++++++- .../Controllers/Api/MeetingsController.php | 4 +- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/backend/app/Http/Controllers/Api/FatherRelationsController.php b/backend/app/Http/Controllers/Api/FatherRelationsController.php index 4bf46133..bef293de 100644 --- a/backend/app/Http/Controllers/Api/FatherRelationsController.php +++ b/backend/app/Http/Controllers/Api/FatherRelationsController.php @@ -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' => ['子の削除に成功しました。']]; + } } diff --git a/backend/app/Http/Controllers/Api/MeetingsController.php b/backend/app/Http/Controllers/Api/MeetingsController.php index 0733fa6d..90c159e1 100644 --- a/backend/app/Http/Controllers/Api/MeetingsController.php +++ b/backend/app/Http/Controllers/Api/MeetingsController.php @@ -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]; }