visuddhinanda 1 سال پیش
والد
کامیت
151820a2d7
1فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 36 0
      api-v8/app/Http/Controllers/ProjectController.php

+ 36 - 0
api-v8/app/Http/Controllers/ProjectController.php

@@ -126,7 +126,43 @@ class ProjectController extends Controller
         return $this->ok(new ProjectResource($project));
     }
 
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\Project  $project
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Project $project)
+    {
+        //
+    }
+
+        $user = AuthApi::current($request);
+        if (!$user) {
+            return $this->error(__('auth.failed'), 401, 401);
+        }
+        if (!self::canEdit($user['user_uid'], $project->owner_id)) {
+            return $this->error(__('auth.failed'), 403, 403);
+        }
+
+        $project->title = $request->get('title');
+        $project->description = $request->get('description');
+        $project->parent_id = $request->get('parent_id');
+        $project->editor_id = $user['user_uid'];
+
 
+        if (Str::isUuid($request->get('parent_id'))) {
+            $parentPath = Project::where('uid', $request->get('parent_id'))->value('path');
+            $parentPath = json_decode($parentPath);
+            if (!is_array($parentPath)) {
+                $parentPath = array();
+            }
+            array_push($parentPath, $project->parent_id);
+            $project->path = json_encode($parentPath, JSON_UNESCAPED_UNICODE);
+        }
+        $project->save();
+
+        return $this->ok(new ProjectResource($project));
     /**
      * Update the specified resource in storage.
      *