diff --git a/Modules/Exam/app/Services/ExamResourceService.php b/Modules/Exam/app/Services/ExamResourceService.php new file mode 100644 index 00000000..81b75b86 --- /dev/null +++ b/Modules/Exam/app/Services/ExamResourceService.php @@ -0,0 +1,66 @@ +uploaderService = config('filesystems.default') === 's3' ? new S3MultipartUploadService() : new LocalFileUploadService(); + } + + function sortSectionLessons(array $sortedData): bool + { + foreach ($sortedData as $value) { + SectionLesson::where('id', $value['id'])->update([ + 'sort' => $value['sort'] + ]); + } + + return true; + } + + public function resourceStore(array $data): LessonResource + { + if ($data['type'] === 'link') { + $resource = LessonResource::create($data); + } else { + $resource = LessonResource::create([...$data, 'resource' => $data['resource_url']]); + } + + return $resource; + } + + public function resourceUpdate(LessonResource $resource, array $data): bool + { + if ($data['type'] === 'link') { + $resource->update($data); + } else { + $chunkedUpload = ChunkedUpload::where('file_url', $data['resource'])->first(); + $chunkedUpload && $this->uploaderService->deleteFile($chunkedUpload); + + $resource->update([...$data, 'resource' => $data['resource_url']]); + } + + return true; + } + + public function resourceDelete(LessonResource $resource): bool + { + $chunkedUpload = ChunkedUpload::where('file_url', $resource->resource)->first(); + $chunkedUpload && $this->uploaderService->deleteFile($chunkedUpload); + + $resource->delete(); + + return true; + } +} \ No newline at end of file