From bcfab2f988bf3818b77c8ed675fa35a2d2fe8a0c Mon Sep 17 00:00:00 2001 From: Maciej Rymarz <59456825+mako321@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:38:47 +0100 Subject: [PATCH] Add userId to saveScreen (#126) --- src/Dto/ConsultationSaveScreenDto.php | 8 +++++++- .../Controllers/Swagger/ConsultationAPISwagger.php | 6 ++++++ src/Http/Requests/ConsultationScreenSaveRequest.php | 3 ++- src/Services/ConsultationService.php | 10 ++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Dto/ConsultationSaveScreenDto.php b/src/Dto/ConsultationSaveScreenDto.php index 8163ae8..713bbf1 100644 --- a/src/Dto/ConsultationSaveScreenDto.php +++ b/src/Dto/ConsultationSaveScreenDto.php @@ -8,9 +8,10 @@ class ConsultationSaveScreenDto extends BaseDto { protected int $consultationId; protected int $userTerminId; - protected string $userEmail; protected string $executedAt; protected array $files; + protected ?string $userEmail = null; + protected ?int $userId = null; public function getConsultationId(): int { @@ -32,6 +33,11 @@ public function getExecutedAt(): string return $this->executedAt; } + public function getUserId(): ?int + { + return $this->userId; + } + public function setFiles(array $files): void { $this->files = $files; diff --git a/src/Http/Controllers/Swagger/ConsultationAPISwagger.php b/src/Http/Controllers/Swagger/ConsultationAPISwagger.php index d65d9c2..102a189 100644 --- a/src/Http/Controllers/Swagger/ConsultationAPISwagger.php +++ b/src/Http/Controllers/Swagger/ConsultationAPISwagger.php @@ -638,9 +638,15 @@ public function schedule(ScheduleConsultationAPIRequest $scheduleConsultationAPI * ), * @OA\Property( * property="user_email", + * description="required_without:user_id", * type="string" * ), * @OA\Property( + * property="user_id", + * description="required_without:user_email", + * type="integer" + * ), + * @OA\Property( * property="timestamp", * type="string", * example="2024-10-04 12:02:12" diff --git a/src/Http/Requests/ConsultationScreenSaveRequest.php b/src/Http/Requests/ConsultationScreenSaveRequest.php index af7db04..582954a 100644 --- a/src/Http/Requests/ConsultationScreenSaveRequest.php +++ b/src/Http/Requests/ConsultationScreenSaveRequest.php @@ -11,7 +11,8 @@ public function rules(): array return [ 'consultation_id' => ['required', 'integer'], 'user_termin_id' => ['required', 'integer'], - 'user_email' => ['required', 'email'], + 'user_email' => ['required_without:user_id', 'email'], + 'user_id' => ['required_without:user_email', 'integer'], 'executed_at' => ['required'], 'files' => ['array', 'min:1'], 'files.*.file' => ['required'], diff --git a/src/Services/ConsultationService.php b/src/Services/ConsultationService.php index 3078f34..cc116b8 100644 --- a/src/Services/ConsultationService.php +++ b/src/Services/ConsultationService.php @@ -594,10 +594,16 @@ private function getReminderData(string $reminderStatus): Collection public function saveScreen(ConsultationSaveScreenDto $dto): void { - $user = User::query()->where('email', '=', $dto->getUserEmail())->firstOrFail(); + $userId = $dto->getUserId() + ?? User::query() + ->select(['id']) + ->where('email', '=', $dto->getUserEmail()) + ->firstOrFail() + ->getKey(); + $term = Carbon::make($dto->getExecutedAt()); // consultation_id/term_start_timestamp/user_id/timestamp.jpg - $folder = ConstantEnum::DIRECTORY . "/{$dto->getConsultationId()}/{$term->getTimestamp()}/{$user->getKey()}"; + $folder = ConstantEnum::DIRECTORY . "/{$dto->getConsultationId()}/{$term->getTimestamp()}/{$userId}"; foreach ($dto->getFiles() as $file) { $screen = $file['file'];