-
Notifications
You must be signed in to change notification settings - Fork 0
se creo el endpoint de ExplorerCourses #25
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| <?php | ||||||
|
|
||||||
| namespace App\Http\Controllers; | ||||||
|
|
||||||
| use App\Http\Services\ExplorerCourseService; | ||||||
| use Illuminate\Http\JsonResponse; | ||||||
| use Illuminate\Http\Request; | ||||||
| use Illuminate\Support\Facades\Log; | ||||||
|
|
||||||
| class CourseController extends Controller | ||||||
| { | ||||||
| public function getExplorerCourses(Request $request): JsonResponse | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Utilizar un request propio para definir que parametros va a pasar el frontend.
Suggested change
GetCoursesRequest: |
||||||
| { | ||||||
| try { | ||||||
| $courses = ExplorerCourseService::Execute($request); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No funciona si no es un metodo estatico, usar:
Suggested change
Y agregar al inicio del controlador el contructor: |
||||||
|
|
||||||
| return response()->json([ | ||||||
| 'status' => 'success', | ||||||
| 'data' => $courses | ||||||
| ], 200); | ||||||
| } catch (\Exception $e) { | ||||||
| Log::error("Error en ExplorerCourses: " . $e->getMessage()); | ||||||
| return response()->json([ | ||||||
| 'status' => 'error', | ||||||
| 'message' => 'Error al consultar los cursos' | ||||||
| ], 500); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Services; | ||
|
|
||
| use App\Models\Course; | ||
| use Illuminate\Database\Eloquent\Collection; | ||
|
|
||
| class ExplorerCourseService | ||
| { | ||
| public static function execute($request): Collection | ||
| { | ||
| return Course::with(['services']) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No existe una relacion de Curso a Services para usar eager loading |
||
| ->when($request->category, function ($query, $category) { | ||
| return $query->where('category_id', $category); | ||
| }) | ||
| ->when($request->subject, function ($query, $subject) { | ||
| return $query->where('subject_id', $subject); | ||
| }) | ||
| ->when($request->date, function ($query, $date) { | ||
| return $query->whereDate('created_at', $date); | ||
| }) | ||
| ->when($request->code, function ($query, $code) { | ||
| return $query->where('cou_code', 'LIKE', "%$code%"); | ||
| }) | ||
| ->get([ | ||
| 'cou_token', | ||
| 'cou_title', | ||
| 'cou_short_title', | ||
| 'cou_description', | ||
| 'cou_code', | ||
| 'cou_content', | ||
| 'cou_path_icon' | ||
| ]); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,12 @@ class Course extends Model | |
| ]; | ||
|
|
||
| public function lessons(): HasMany | ||
| { | ||
| return $this->hasMany(Lesson::class, 'fk_lessons_courses', 'cou_token'); | ||
| } | ||
|
|
||
| public function services(): HasMany | ||
| { | ||
| return $this->hasMany(Lesson::class, 'fk_lessons_courses', 'cou_token'); | ||
| return $this->hasMany(CourseService::class, 'fk_course_services_courses', 'cou_token'); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CourseService no es un modelo, es un servicio |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class CourseService extends Model | ||
| { | ||
|
|
||
| protected $table = 'course_services'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No existe la tabla course_services |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar formas de filtrar la consulta de Cursos, como por categoria, por asignatura, por fecha y por codigo