diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index c5b400a9..952a9441 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -4,6 +4,9 @@ use App\BusinessLogicLayer\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemManager; use App\Http\Controllers\Controller; +use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem; +use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation; +use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; @@ -33,4 +36,79 @@ public function showProblemsPage(Request $request) { abort(ResponseAlias::HTTP_NOT_FOUND); } } + + /** + * Display a listing of the resource. + */ + public function index() + { + $viewModel = []; + $viewModel['problems'] = CrowdSourcingProjectProblem::with('translations')->latest()->get(); + return view('loggedin-environment.management.problem.index', ['viewModel' => $viewModel]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $newProblem = new CrowdSourcingProjectProblem(); + $newProblem->default_language_id = 6; // @todo change with lookuptable value - bookmark2 + $newProblem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation()); // bookmark2 - is this an "empty" relationship? + $viewModel = new CreateEditProblem($newProblem); + return view('loggedin-environment.management.problem.create-edit.form-page'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + request()->validate([ // bookmark2 + 'problem-title' => ['required'], + 'problem-description' => ['required'], + 'problem-status' => ['required'], // bookmark2 + 'problem-default-language' => ['required'], // bookmark2 + ]); + + $crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([ + 'project_id' => '3', // bookmark2 + 'user_creator_id' => '2', // bookmark2 + 'slug' => 'test-slug-1', // bookmark2 + 'status_id' => request('problem-status'), // bookmark2 + 'img_url' => 'zxcv', // bookmark2 + 'default_language_id' => request('problem-default-language'), // bookmark2 - default or generally another translation language? + ]); + + $crowdSourcingProjectProblemTranslation = $crowdSourcingProjectProblem->defaultTranslation()->create([ // bookmark2 - default or regular translation? + 'title' => request('problem-title'), + 'description' => request('problem-description'), + ]); + + return redirect()->route('problems.index'); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } } diff --git a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php index 7182bb0f..9868472b 100644 --- a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php +++ b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php @@ -15,7 +15,7 @@ class CrowdSourcingProjectProblem extends Model { use SoftDeletes; protected $table = 'crowd_sourcing_project_problems'; - protected $fillable = ['id', 'project_id', 'slug', 'status_id', 'img_url', 'default_language_id']; + protected $fillable = ['id', 'project_id', 'user_creator_id', 'slug', 'status_id', 'img_url', 'default_language_id']; public function defaultTranslation(): HasOne { return $this->hasOne(CrowdSourcingProjectProblemTranslation::class, diff --git a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php new file mode 100644 index 00000000..4fef6f32 --- /dev/null +++ b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php @@ -0,0 +1,13 @@ +crowdSourcingProjectProblem = $crowdSourcingProjectProblem; + } + +} \ No newline at end of file diff --git a/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php b/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php index 8c0c78f2..e8135bc2 100644 --- a/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php +++ b/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php @@ -90,7 +90,7 @@