Skip to content

Course: Refactor course creation service #5302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

christianbeeznest
Copy link
Contributor

No description provided.

@@ -207,4 +207,27 @@ public function getSubscribedUsersByStatus(Course $course, int $status)

return $queryBuilder;
}

public function courseCodeExists(string $code): bool
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing function doc comment

return (int) $qb->getSingleScalarResult() > 0;
}

public function findCourseAsArray($id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing function doc comment

Copy link

codeclimate bot commented Mar 27, 2024

Code Climate has analyzed commit 576b2a4 and detected 69 issues on this pull request.

Here's the issue category breakdown:

Category Count
Style 51
Clarity 14
Complexity 2
Bug Risk 2

View more on Code Climate.

@chamilo chamilo deleted a comment from codeclimate bot Mar 27, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mejor moverlo a src/CoreBundle/ServiceHelper/EventLoggerHelper

public function addEvent(
string $eventType,
string $valueType,
$value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El tipado podría ser mixed $value

Comment on lines +60 to +62
if (empty($params['title'])) {
throw new \InvalidArgumentException('The course title cannot be empty.');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto está validado en la misma entidad como Assert\NotBlank

} else {
console.error(tempResponse.message)
}
const response = await courseService.createCourse(formData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este servicio que hace la llamada ajax a createCourse, tiene que ser a través de api-platform

if ($course) {
return new JsonResponse([
'success' => true,
'message' => $translator->trans('Course created successfully.'),
'courseId' => $course->getId(),
]);
}
} catch (\Exception $e) {

return new JsonResponse([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aquí se debería lanzar una exception en lugar de devolver una respuesta con json

}
}

public function sendEmailToAdmin(Course $course): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El correo debería enviarse en un EventListener después de crear el curso

$entityManager->flush();
}

private function insertCourseSettings(Course $course): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

También debería hacerse en un entity o event listener

return $gradebookCategory;
}

private function insertExampleContent(Course $course, GradebookCategory $gradebook): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este método podría ser un servicio a parte, como el de CreateDefaultPages

$this->createExampleGradebookContent($course, $gradebook, $exercise->id);
}

private function createExampleGradebookContent(Course $course, GradebookCategory $parentCategory, int $refId): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este método podría ser un servicio a parte, como el de CreateDefaultPages

@@ -730,43 +731,47 @@ public function searchCourseTemplates(
}

#[Route('/create', name: 'chamilo_core_course_create')]
public function createCourse(Request $request, TranslatorInterface $translator): JsonResponse
{
public function createCourse(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debería estar en un StateProcessor de ApiPlatform para tener un solo endpoint de creación de curso

@christianbeeznest christianbeeznest merged commit dd6ecf8 into chamilo:master Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants