From bff916e78f4670db3a16bfa929417c369eacc4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Mon, 28 Oct 2024 12:25:01 +0100 Subject: [PATCH 1/4] Fix screen directory --- src/Dto/ConsultationDto.php | 4 ++-- src/Services/ConsultationService.php | 2 +- tests/APIs/ConsultationApiTest.php | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Dto/ConsultationDto.php b/src/Dto/ConsultationDto.php index 84d21c8..c2d8d71 100644 --- a/src/Dto/ConsultationDto.php +++ b/src/Dto/ConsultationDto.php @@ -38,7 +38,7 @@ public function toArray($filters = false): array public function getImagePath() { if ($this->imagePath !== false) { - return $this->imagePath === null ? '' : Str::after($this->imagePath, env('AWS_ACCESS_KEY_ID') . '/'); + return $this->imagePath === null ? '' : Str::after($this->imagePath, env('AWS_URL') . '/'); } return false; } @@ -47,7 +47,7 @@ public function getLogotypePath() { if ($this->logotypePath !== false) { if ($this->logotypePath) { - $logotypePath = Str::after($this->logotypePath, env('AWS_ACCESS_KEY_ID') . '/'); + $logotypePath = Str::after($this->logotypePath, env('AWS_URL') . '/'); return Str::startsWith($logotypePath, ConstantEnum::DIRECTORY) ? $logotypePath : ConstantEnum::DIRECTORY . '/' .$logotypePath; } return ''; diff --git a/src/Services/ConsultationService.php b/src/Services/ConsultationService.php index d2aa654..c930f8a 100644 --- a/src/Services/ConsultationService.php +++ b/src/Services/ConsultationService.php @@ -514,7 +514,7 @@ public function saveScreen(ConsultationSaveScreenDto $dto): void $termin = Carbon::make($consultationUser->executed_at); // consultation_id/term_start_timestamp/user_id/timestamp.jpg - $folder = "consultations/{$dto->getConsultationId()}/{$termin->getTimestamp()}/{$user->getKey()}"; + $folder = ConstantEnum::DIRECTORY . "/{$dto->getConsultationId()}/{$termin->getTimestamp()}/{$user->getKey()}"; $extension = $dto->getFile() instanceof UploadedFile ? $dto->getFile()->getClientOriginalExtension() : Str::between($dto->getFile(), 'data:image/', ';base64'); Storage::putFileAs($folder, $dto->getFile(), Carbon::make($dto->getTimestamp())->getTimestamp() . '.' . $extension); diff --git a/tests/APIs/ConsultationApiTest.php b/tests/APIs/ConsultationApiTest.php index 379a2ca..c241652 100644 --- a/tests/APIs/ConsultationApiTest.php +++ b/tests/APIs/ConsultationApiTest.php @@ -7,6 +7,7 @@ use EscolaLms\Auth\Services\Contracts\UserServiceContract; use EscolaLms\Categories\Models\Category; use EscolaLms\Consultations\Database\Seeders\ConsultationsPermissionSeeder; +use EscolaLms\Consultations\Enum\ConstantEnum; use EscolaLms\Consultations\Enum\ConsultationsPermissionsEnum; use EscolaLms\Consultations\Enum\ConsultationStatusEnum; use EscolaLms\Consultations\Enum\ConsultationTermStatusEnum; @@ -241,7 +242,7 @@ public function testConsultationSaveScreen(): void $term = Carbon::make($consultationUser->executed_at); // consultation_id/term_start_timestamp/user_id/timestamp.jpg - Storage::assertExists("consultations/{$consultation->getKey()}/{$term->getTimestamp()}/{$student->getKey()}/{$time->getTimestamp()}.jpg"); + Storage::assertExists(ConstantEnum::DIRECTORY . "/{$consultation->getKey()}/{$term->getTimestamp()}/{$student->getKey()}/{$time->getTimestamp()}.jpg"); $this->response = $this->json('POST', '/api/consultations/save-screen', [ 'consultation_id' => $consultation->getKey(), From b953b2b112389b2efb8346c2638d3957f53c0677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Mon, 28 Oct 2024 12:27:13 +0100 Subject: [PATCH 2/4] Fix --- src/Dto/ConsultationDto.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dto/ConsultationDto.php b/src/Dto/ConsultationDto.php index c2d8d71..1dc41b1 100644 --- a/src/Dto/ConsultationDto.php +++ b/src/Dto/ConsultationDto.php @@ -38,7 +38,7 @@ public function toArray($filters = false): array public function getImagePath() { if ($this->imagePath !== false) { - return $this->imagePath === null ? '' : Str::after($this->imagePath, env('AWS_URL') . '/'); + return $this->imagePath === null ? '' : Str::after($this->imagePath, Str::after(env('AWS_URL'), 'https://') . '/'); } return false; } @@ -47,7 +47,7 @@ public function getLogotypePath() { if ($this->logotypePath !== false) { if ($this->logotypePath) { - $logotypePath = Str::after($this->logotypePath, env('AWS_URL') . '/'); + $logotypePath = Str::after($this->logotypePath, Str::after(env('AWS_URL'), 'https://') . '/'); return Str::startsWith($logotypePath, ConstantEnum::DIRECTORY) ? $logotypePath : ConstantEnum::DIRECTORY . '/' .$logotypePath; } return ''; From 7b9ad5583b06c3288fc3a111e02bf65be1f468ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Tue, 29 Oct 2024 08:01:18 +0100 Subject: [PATCH 3/4] fix date --- src/Dto/ConsultationDto.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dto/ConsultationDto.php b/src/Dto/ConsultationDto.php index 1dc41b1..ba170eb 100644 --- a/src/Dto/ConsultationDto.php +++ b/src/Dto/ConsultationDto.php @@ -60,7 +60,7 @@ protected function setProposedTerms(array $proposedTerms): void $result = []; foreach ($proposedTerms as $term) { if (is_int($term)) { - $date = Carbon::parse((string) ($term/1000)); + $date = Carbon::parse($term/1000); } else { $date = Carbon::parse($term); } From c13c64e1767b1851159becf4325bd1a36e454c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wis=CC=81niewski?= Date: Tue, 29 Oct 2024 08:22:21 +0100 Subject: [PATCH 4/4] Fix style --- src/Dto/ConsultationDto.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Dto/ConsultationDto.php b/src/Dto/ConsultationDto.php index ba170eb..b7c7bd7 100644 --- a/src/Dto/ConsultationDto.php +++ b/src/Dto/ConsultationDto.php @@ -60,7 +60,8 @@ protected function setProposedTerms(array $proposedTerms): void $result = []; foreach ($proposedTerms as $term) { if (is_int($term)) { - $date = Carbon::parse($term/1000); + // @phpstan-ignore-next-line + $date = Carbon::parse($term / 1000); } else { $date = Carbon::parse($term); }