Skip to content

Commit

Permalink
IP-307: implemented fetching all the solutions the user has acess to
Browse files Browse the repository at this point in the history
  • Loading branch information
papandrk committed Nov 29, 2024
1 parent d7df06a commit 710edab
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/BusinessLogicLayer/Solution/SolutionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Repository\Solution\SolutionRepository;
use App\Utils\FileHandler;
use App\ViewModels\Solution\CreateEditSolution;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -134,4 +135,8 @@ public function updateSolution(int $id, array $attributes) {
$this->solutionTranslationManager
->updateSolutionTranslations($id, $defaultTranslation, $extraTranslations);
}

public function getSolutionsForCrowdSourcingProjectForManagement(?int $projectId): Collection {
return $this->solutionRepository->getSolutionsForCrowdSourcingProjectForManagement($projectId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,8 @@ public function clone(Request $request): RedirectResponse {
public function getCrowdSourcingProjectsForProblems(): JsonResponse {
return response()->json($this->crowdSourcingProjectManager->getCrowdSourcingProjectsForProblems());
}

public function getCrowdSourcingProjectsForSolutions(): JsonResponse {
return $this->getCrowdSourcingProjectsForProblems();
}
}
9 changes: 9 additions & 0 deletions app/Http/Controllers/Solution/SolutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\BusinessLogicLayer\Solution\SolutionManager;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -129,4 +130,12 @@ public function update(Request $request, string $locale, int $id) {
public function destroy(string $locale, int $id) {
//
}

public function getSolutionsForCrowdSourcingProjectForManagement(): JsonResponse {
$this->validate(request(), [
'projectId' => 'nullable|numeric|exists:crowd_sourcing_projects,id',
]);

return response()->json($this->solutionManager->getSolutionsForCrowdSourcingProjectForManagement(request('projectId')));
}
}
24 changes: 24 additions & 0 deletions app/Repository/Solution/SolutionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@
namespace App\Repository\Solution;

use App\Models\Solution\Solution;
use App\Repository\Problem\ProblemRepository;
use App\Repository\Repository;
use Illuminate\Support\Collection;

class SolutionRepository extends Repository {
protected ProblemRepository $problemRepository;

public function __construct(ProblemRepository $problemRepository) {
$this->problemRepository = $problemRepository;
}

/**
* {@inheritDoc}
*/
public function getModelClassName() {
return Solution::class;
}

public function getSolutionsForCrowdSourcingProjectForManagement(?int $projectId): Collection {
if (!$projectId) {
// return Solution::all();
return Solution::with(['problem'])->get(); // bookmark4 - do we need/want with each solution's problem?
}

$problemIdsBelongingToProject = $this->problemRepository->getProblemsForCrowdSourcingProjectForManagement($projectId)->pluck('id');
$finalSolutionsCollection = new Collection;
foreach ($problemIdsBelongingToProject as $problem_id) {
// $finalSolutionsCollection = $finalSolutionsCollection->merge(Solution::where('problem_id', $problem_id)->get());
$finalSolutionsCollection = $finalSolutionsCollection->merge(Solution::where('problem_id', $problem_id)->with(['problem'])->get()); // bookmark4 - do we need/want with each solution's problem?
}

return $finalSolutionsCollection;
}
}
2 changes: 1 addition & 1 deletion resources/assets/js/problem/manage-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ app.mount("#app");
};

const checkURLAndActivateTranslationsTab = function () {
// should check the URL for a `translations=1` variable and if set and if true, it should activate the tab. SEE DESCR
// should check the URL for a `translations=1` variable and if set and if true, it should activate the tab.
if (
window.location.search.indexOf("?translations=1") > -1 ||
window.location.search.indexOf("&translations=1") > -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
role="status"
aria-hidden="true"
></span
>In understand, Delete the problem
>I understand, Delete the problem
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
role="status"
aria-hidden="true"
></span
>In understand, Delete the problem
>I understand, Delete the problem
</button>
</div>
</div>
Expand Down Expand Up @@ -160,7 +160,7 @@ import axios from "axios";
import CommonModal from "../../../common/ModalComponent.vue";
export default {
name: "ProblemsManagement",
name: "SolutionsManagement",
components: { CommonModal },
data() {
return {
Expand Down Expand Up @@ -189,6 +189,7 @@ export default {
this.updateModal = new Modal(document.getElementById("updateModal"));
await this.getProblemStatusesForManagementPage();
await this.getCrowdSourcingProjectsForFiltering();
await this.getAllProjectSolutions();
await this.setUpDataTable();
},
methods: {
Expand Down Expand Up @@ -252,7 +253,7 @@ export default {
async getCrowdSourcingProjectsForFiltering() {
return this.get({
url: window.route("api.problems.projects.get"),
url: window.route("api.solutions.projects.get"),
data: {},
urlRelative: false,
})
Expand Down Expand Up @@ -291,6 +292,46 @@ export default {
}
},
getAllProjectSolutions() { // bookmark4
this.fetched = false;
this.problems = [];
this.post({
url: window.route("api.solutions.get-management"),
data: { projectId: 1 },
urlRelative: false,
})
.then((response) => {
this.problems = response.data;
this.fetched = true;
this.updateFilteredProblems();
this.updateDataTable();
})
.catch((error) => {
this.showErrorMessage(error);
});
},
getSingleProjectSolutions() { // bookmark4
if (this.selectedProjectId) {
this.fetched = false;
this.problems = [];
this.post({
url: window.route("api.solutions.get-management"),
data: { projectId: this.selectedProjectId },
urlRelative: false,
})
.then((response) => {
this.problems = response.data;
this.fetched = true;
this.updateFilteredProblems();
this.updateDataTable();
})
.catch((error) => {
this.showErrorMessage(error);
});
}
},
toggleShowUnpublishedProblems() {
this.showUnpublishedProblemsOnly = !this.showUnpublishedProblemsOnly;
this.updateFilteredProblems();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
@extends('backoffice.layout')

@section('content')
{{-- bookmark4 - not working correctly --}}
{{--
<div class="container-fluid p-0 mb-5">
<div class="row p-0">
<div class="col">
<a href="{{ route('problems.create') }}" class="btn btn-primary">
<i class="fa fa-plus mr-2"></i>Create a new problem</a>
<a href="{{ route('solutions.create') }}" class="btn btn-primary">
<i class="fa fa-plus mr-2"></i>Create a new solution</a>
</div>
</div>
</div>
--}}

<solutions-management></solutions-management>
@endsection
Expand Down
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Http\Controllers\Questionnaire\QuestionnaireController;
use App\Http\Controllers\Questionnaire\QuestionnaireReportController;
use App\Http\Controllers\Questionnaire\QuestionnaireResponseController;
use App\Http\Controllers\Solution\SolutionController;
use App\Http\Controllers\User\UserController;

Route::middleware(['throttle:api-public'])->group(function () {
Expand Down Expand Up @@ -56,6 +57,8 @@
Route::get('/problems/management/projects', [CrowdSourcingProjectController::class, 'getCrowdSourcingProjectsForProblems'])->name('api.problems.projects.get');
Route::post('/problems/management', [ProblemController::class, 'getProblemsForCrowdSourcingProjectForManagement'])->name('api.problems.get-management');
Route::get('/problems/statuses/management', [ProblemController::class, 'getProblemStatusesForManagementPage'])->name('api.problems.statuses.management.get');
Route::get('/solutions/management/projects', [CrowdSourcingProjectController::class, 'getCrowdSourcingProjectsForSolutions'])->name('api.solutions.projects.get');
Route::post('/solutions/management', [SolutionController::class, 'getSolutionsForCrowdSourcingProjectForManagement'])->name('api.solutions.get-management');
});

Route::group(['middleware' => ['throttle:api-internal', 'auth', 'can:manage-users']], function () {
Expand Down

0 comments on commit 710edab

Please sign in to comment.