|
@@ -4,7 +4,9 @@ namespace App\Http\Controllers\API;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Http\Requests\API\Project\CreateOrUpdateRequest;
|
|
|
+use App\Http\Requests\API\Project\PostponeRequest;
|
|
|
use App\Http\Resources\API\ProjectResource;
|
|
|
+use App\Models\Enums\ProjectStatus;
|
|
|
use App\Models\Project;
|
|
|
use App\Models\ProjectAsset;
|
|
|
use App\Models\ProjectPlan;
|
|
@@ -76,9 +78,40 @@ class ProjectController extends Controller
|
|
|
/**
|
|
|
* Update the specified resource in storage.
|
|
|
*/
|
|
|
- public function update(Request $request, string $id)
|
|
|
+ public function update(CreateOrUpdateRequest $request, string $id)
|
|
|
{
|
|
|
- //
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->fill([
|
|
|
+ ...$request->all(),
|
|
|
+ 'whitelist' => $request->whitelist ? sprintf(",%s", implode(',', $request->whitelist)) : null,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $project->save();
|
|
|
+
|
|
|
+ if ($request->has("assets")) {
|
|
|
+ ProjectAsset::where('project_id', $project->id)->delete();
|
|
|
+
|
|
|
+ foreach ($request->get("assets", []) as $assetId) {
|
|
|
+ ProjectAsset::create([
|
|
|
+ 'project_id' => $project->id,
|
|
|
+ 'asset_id' => $assetId,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($request->has("plans")) {
|
|
|
+ ProjectPlan::where('project_id', $project->id)->delete();
|
|
|
+
|
|
|
+ foreach ($request->get("plans", []) as $planId) {
|
|
|
+ ProjectPlan::create([
|
|
|
+ 'project_id' => $project->id,
|
|
|
+ 'plan_id' => $planId,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -86,6 +119,52 @@ class ProjectController extends Controller
|
|
|
*/
|
|
|
public function destroy(string $id)
|
|
|
{
|
|
|
- //
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->delete();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function closed(string $id)
|
|
|
+ {
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->status = ProjectStatus::CLOSED->value;
|
|
|
+ $project->save();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function start(string $id)
|
|
|
+ {
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->status = ProjectStatus::DOING->value;
|
|
|
+ $project->save();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function pause(string $id)
|
|
|
+ {
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->status = ProjectStatus::PAUSE->value;
|
|
|
+ $project->save();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function postpone(PostponeRequest $request, string $id)
|
|
|
+ {
|
|
|
+ $project = Project::findOrFail($id);
|
|
|
+
|
|
|
+ $project->fill($request->only([
|
|
|
+ 'begin', 'end', 'available_days'
|
|
|
+ ]));
|
|
|
+ $project->save();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
}
|
|
|
}
|