Skip to content

Commit

Permalink
IP-327: fix bug when a content-manager changes status of problem
Browse files Browse the repository at this point in the history
  • Loading branch information
papandrk committed Dec 17, 2024
1 parent 9a7349d commit c35c517
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/BusinessLogicLayer/Problem/ProblemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,23 @@ public function getCreateEditProblemViewModel(?int $id = null): CreateEditProble
}

public function storeProblem(array $attributes): int {
if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) {
$imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img');
}

$crowdSourcingProjectProblem = Problem::create([
'project_id' => $attributes['problem-owner-project'],
'user_creator_id' => Auth::id(),
'slug' => Str::random(16), // temporary - will be changed after record creation
'status_id' => $attributes['problem-status'],
'img_url' => $imgPath,
'default_language_id' => $attributes['problem-default-language'],
]);

$crowdSourcingProjectProblem->slug = Str::slug($attributes['problem-title'] . '-' . $crowdSourcingProjectProblem->id);
$crowdSourcingProjectProblem->save();

if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) {
$imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img');
$crowdSourcingProjectProblem->img_url = $imgPath;
$crowdSourcingProjectProblem->save();
}

$crowdSourcingProjectProblem->defaultTranslation()->create([
'title' => $attributes['problem-title'],
'description' => $attributes['problem-description'],
Expand All @@ -104,15 +105,16 @@ public function storeProblem(array $attributes): int {
* @throws RepositoryException
*/
public function updateProblem(int $id, array $attributes) {
if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) {
$imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img');
}

$modelAttributes['project_id'] = $attributes['problem-owner-project'];
$modelAttributes['slug'] = $attributes['problem-slug'];
$modelAttributes['status_id'] = $attributes['problem-status'];
$modelAttributes['img_url'] = $imgPath;
$modelAttributes['default_language_id'] = $attributes['problem-default-language'];

if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) {
$imgPath = FileHandler::uploadAndGetPath($attributes['problem-image'], 'problem_img');
$modelAttributes['img_url'] = $imgPath;
}

$this->problemRepository->update($modelAttributes, $id);

$defaultTranslation = [
Expand Down

0 comments on commit c35c517

Please sign in to comment.