このリポジトリは2023-09-09にアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュ、イシューの作成、プルリクエストはできません。
kikikan/backend/app/Http/Controllers/Api/MeetingApprovalsController.php

119 行
4.0 KiB
PHP
Raw 通常表示 履歴

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
2021-10-15 10:37:47 +09:00
use Illuminate\Support\Facades\Log;
use App\Models\Child;
use App\Models\Meeting;
use App\Models\MeetingApprovals;
2021-10-15 10:37:47 +09:00
use App\Models\FatherRelation;
class MeetingApprovalsController extends Controller {
2021-10-06 14:50:13 +09:00
public function registerApproval (Request $r) {
if (!isset($r->meeting_id) || !isset($r->child_id)) {
return ['status' => 400, 'error_messages' => ['承認に失敗しました。']];
}
if (MeetingApprovals::where('id', $r->meeting_id)->where('child_id', $r->child_id)->first()) {
return ['status_code' => 200, 'success_messages' => ['承認しました。']];
}
return ['status_code' => 400, 'error_messages' => ['承認に失敗しました。']];
}
public function listChildrenOfMeeting (Request $r) {
if (!isset($r->meeting_id) || !isset($r->child_id)) {
return ['status' => 400, 'error_messages' => ['承認に失敗しました。']];
}
$meeting_approvals_select = ['id', 'child_id', 'approval_at'];
$update = ['hire_at' => date('Y-m-d H:i:s', strtotime($r->hire_at))];
if ($params = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', $r->meeting_id)->where('child_id', $r->child_id)->get()) {
if (FatherRelation::where('child_id', $r->child_id)->update($update)) {
return ['status' => 200, 'success_messages' => ['承認しました。']];
}
}
// エラーの場合
return ['status' => 400, 'error_messages' => ['承認に失敗しました。']];
}
2021-10-06 14:50:13 +09:00
public function listChildrenOfApprovel (Request $r) {
if (!isset($r->meeting_id)) {
return ['status_code' => 400];
}
2021-10-06 14:50:13 +09:00
$meeting_approvals_select = ['id', 'child_id', 'approval_at'];
$child_select = ['id', 'image', 'last_name', 'first_name'];
2021-10-07 13:51:53 +09:00
if (null === ($params = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', $r->meeting_id)->whereNotNull('approval_at')->get())) {
// エラーの場合
return ['status' => 400];
}
2021-10-07 13:51:53 +09:00
foreach ($params as $p) {
if (null === ($p->child_id = Child::select($child_select)->where('id', $p->child_id)->first())) {
return ['status' => 400];
}
}
2021-10-07 13:51:53 +09:00
return ['status' => 200, 'params' => $params];
}
2021-10-06 14:50:13 +09:00
public function listChildrenOfUnapprovel (Request $r) {
if (!isset($r->meeting_id)) {
return ['status_code' => 400];
}
$meeting_select = ['id', 'child_id', 'approval_at'];
$child_select = ['id', 'image', 'last_name', 'first_name'];
2021-10-07 13:51:53 +09:00
if (null === ($params = MeetingApprovals::select($meeting_select)->where('meeting_id', $r->meeting_id)->whereNull('approval_at')->get())) {
// エラーの場合
return ['status' => 400];
}
2021-10-07 13:51:53 +09:00
foreach ($params as $p) {
if (null === ($p->child_id = Child::select($child_select)->where('id', $p->child_id)->first())) {
return ['status' => 400];
}
}
2021-10-07 13:51:53 +09:00
return ['status' => 200, 'params' => $params];
}
2021-10-06 14:50:13 +09:00
public function deleteRelationMeeting ($meeting_id) {
if (!isset($meeting_id)) {
return ['status_code' => 400];
}
2021-10-07 13:51:53 +09:00
try {
MeetingApprovals::where('meeting_id', $meeting_id)->delete();
} catch (\Throwable $e) {
Log::critical($e->getMessage());
return ['status_code' => 400];
2021-10-06 14:50:13 +09:00
}
2021-10-07 13:51:53 +09:00
return ['status_code' => 200];
2021-10-06 14:50:13 +09:00
}
2021-10-06 14:50:13 +09:00
public function deleteRelationChild ($child_id) {
if (!isset($child_id)) {
return ['status_code' => 400];
}
2021-10-07 13:51:53 +09:00
try {
MeetingApprovals::where('child_id', $child_id)->delete();
} catch (\Throwable $e) {
Log::critical($e->getMessage());
return ['status_code' => 400];
2021-10-06 14:50:13 +09:00
}
2021-10-07 13:51:53 +09:00
return ['status_code' => 200];
2021-10-06 14:50:13 +09:00
}
}