public function update($projectId, $fileId, $file, array $data)
 {
     try {
         if (is_null($file)) {
             $this->validator->setRules(['name' => 'required|max:255', 'description' => 'required']);
             $this->validator->with($data)->passesOrFail();
             $fileUpdate = $this->repository->findWhere(['project_id' => $projectId, 'id' => $fileId])->first();
             $fileUpdate->update($data, $fileId);
             return $this->find($projectId, $fileUpdate->id);
         }
         $this->validator->with($data)->passesOrFail();
         $fileUpdate = $this->repository->findWhere(['project_id' => $projectId, 'id' => $fileId])->first();
         $data['extension'] = $file->getClientOriginalExtension();
         $data['file'] = md5(date('Y-m-d H:i:s')) . "." . $data['extension'];
         $this->storage->put($data['file'], $this->filesystem->get($file));
         if ($this->storage->exists($fileUpdate->file)) {
             $this->storage->delete($fileUpdate->file);
         }
         $fileUpdate->update($data, $fileId);
         return $this->find($projectId, $fileUpdate->id);
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     } catch (\Exception $e) {
         return ['error' => true, 'message' => $e->getMessage()];
     }
 }
Ejemplo n.º 2
0
 public function update(array $data, $id)
 {
     try {
         $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE);
         return $this->repository->update($data, $id);
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
Ejemplo n.º 3
0
 public function createFile(array $data)
 {
     // name
     // description
     // extension
     // file
     try {
         //dd($data);
         //dd($data['file']);
         if (!empty($data['file'])) {
             $data['extension'] = $data['file']->getClientOriginalExtension();
         }
         $this->validatorProjectFile->with($data)->passesOrFail();
         // sem transformers
         $project = $this->repository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         //$this->storage->put($data['name'] . '.' . $data['extension'], $this->filesystem->get($data['file']));
         $r = $this->storage->put($projectFile->id . '.' . $data['extension'], $this->filesystem->get($data['file']));
         if ($r) {
             return ['error' => false];
         }
     } catch (ValidatorException $e) {
         //dd($e->getMessageBag()->getMessages());
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
 public function createFile(array $data)
 {
     try {
         $this->filevalidator->with($data)->passesOrFail(ValidatorInterface::RULE_CREATE);
         $project = $this->projectRepository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         $this->storage->disk('local')->put($projectFile->getFileName(), $this->filesystem->get($data['file']));
         return ['error' => false, 'success' => true];
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
 public function store(Request $request)
 {
     $rules = array('file' => 'required');
     $file = $request->file('file');
     $validator = Validator::make(array('file' => $file), $rules);
     if ($validator->fails()) {
         return response()->json(['error' => true, 'message' => "Arquivo não selecionado"]);
     } elseif ($validator->passes()) {
         $extension = $file->getClientOriginalExtension();
         $data['file'] = $file;
         $data['extension'] = $extension;
         $data['name'] = $request->name;
         $data['project_id'] = $request->project_id;
         $data['description'] = $request->description;
         try {
             $this->validator->with($data)->passesOrFail();
             $this->service->createFile($data);
         } catch (ValidatorException $e) {
             return response()->json(['error' => true, 'message' => $e->getMessageBag()]);
         }
     }
 }
Ejemplo n.º 6
0
 public function createFile(array $data)
 {
     try {
         $this->validator->with($data)->passesOrFail();
         $project = Project::find($data['project_id']);
         if (is_null($project)) {
             return Errors::invalidId($data['project_id']);
         }
         $user_id = \Authorizer::getResourceOwnerId();
         if (!$this->projectRepository->isMember($data['project_id'], $user_id)) {
             return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.');
         }
         $data['extension'] = $data['file']->getClientOriginalExtension();
         $projectFile = $this->repository->create($data);
         $nome = $projectFile->id . "." . $data['extension'];
         $arquivo = $this->filesystem->get($data['file']);
         $this->storage->put($nome, $arquivo);
         return ['message' => 'Arquivo criado'];
     } catch (ValidatorException $e) {
         return Errors::basic($e->getMessageBag());
     }
 }
Ejemplo n.º 7
0
 public function createFile(array $data)
 {
     //name, description, extension, file.
     try {
         $this->validatorFile->with($data)->passesOrFail();
         $extension = $data['file']->getClientOriginalExtension();
         $data['extension'] = $extension;
         $project = $this->repository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file']));
         return ['error' => false, 'message' => "File created"];
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
Ejemplo n.º 8
0
 public function createFile(Request $request, $project_id)
 {
     try {
         $info = $request->all();
         $info['project_id'] = $project_id;
         $this->fileValidator->with($info)->passesOrFail();
         $file = $request->file('file');
         $extension = $file->getClientOriginalExtension();
         $data['file'] = $file;
         $data['extension'] = $extension;
         $data['name'] = $request->name;
         $data['project_id'] = $project_id;
         $data['description'] = $request->description;
         $project = $this->repository->skipPresenter()->find($data['project_id']);
         $projectFile = $project->files()->create($data);
         $this->storage->put($projectFile->id . "." . $data['extension'], $this->filesystem->get($data['file']));
         return ['error' => false, 'message' => 'success'];
     } catch (ValidatorException $e) {
         return ['error' => true, 'message' => $e->getMessageBag()];
     }
 }
 public function update(array $data, $file_id)
 {
     $file = ProjectFile::find($file_id);
     if (is_null($file)) {
         return Errors::invalidId($file_id);
     }
     try {
         $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE);
         if ($data['project_id'] != $file->project_id) {
             return Errors::basic('Você não pode alterar o projeto do arquivo.');
         }
         if ($data['extension'] != $file->extension) {
             return Errors::basic('Você não pode alterar a extensão do arquivo.');
         }
         $user_id = \Authorizer::getResourceOwnerId();
         if (!$this->projectRepository->isMember($file->project_id, $user_id)) {
             return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.');
         }
         return $this->repository->update($data, $file_id);
     } catch (ValidatorException $e) {
         return Errors::basic($e->getMessageBag());
     }
 }