#P1694
GET /v2/academy/course/steps/view
Academy: View Course Steps
این اندپوینت اطلاعات کامل یک دوره آموزشی بههمراه تمام مراحل (steps) آن را برمیگرداند. همچنین وضعیت پیشرفت کاربر (current_step و completed) را بهروزرسانی و بازگردانی میکند. منطق این API بر اساس آخرین مرحله (آخرین رکورد step) داده دریافت شده بنا شده است و اطلاعات دوره نیز عمداً از همان آخرین step استخراج میشود (طبق رفتار فعلی سیستم).
URL:
/v2/academy/course/steps/viewMethod: GET
Controller: AcademyController@viewStepsCourse
Middleware: authWithJwt
Auth: JWT Required
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| course_id | integer | yes | شناسه دورهای که میخواهید مراحل آن را مشاهده کنید |
| step_id | integer | no | اگر ارسال شود فقط یک مرحله خاص فیلتر میشود |
| current_step | integer | no | مرحله جدیدی که کاربر به آن رسیده؛ اگر برابر total_steps باشد → مقدار completed یک افزایش مییابد |
Controller Logic
// 1. Fetch all steps of this course (optional filtering by step_id)
// 2. LEFT JOIN course + category info inside each step row
// 3. Load or create progress record in academy_course_completed
// 4. Update progress (completed / current_step)
// 5. Build steps[]
// 6. Build final course object based on the LAST step (intentional behavior)
$resultCourseSteps = DB::table('academy_course_steps')
->select([... course + step + category fields ...])
->where('academy_course_steps.course', $request->get('course_id'))
->where(function ($q) {
if ($request->has('step_id')) $q->where('academy_course_steps.id', $request->get('step_id'));
})
->leftJoin("academy_courses", ...)
->leftJoin("academy_categories", ...)
->orderBy('order')->orderBy('id')
->get();
$resultStep = DB::table('academy_course_completed')
->where('course', $request->get('course_id'))
->where('student', $request->get('operator')->id)
->first();
$courseCount = total number of steps in academy_course_steps;
// Progress Update Logic
if (!$resultStep) create new record with defaults;
else update based on current_step rules;
// Build steps[]
foreach (... each step ...) { ... }
// IMPORTANT: course info is taken from LAST step (as user confirmed)
$return = [
"id" => $step->course_id,
...
"steps" => $steps
];
return [...];
Step Object Structure
| Field | Type | Description |
|---|---|---|
| id | integer | شناسه مرحله |
| title.fa | string | عنوان فارسی مرحله |
| title.en | string | عنوان انگلیسی مرحله |
| subtitle.fa | string | زیرعنوان فارسی |
| subtitle.en | string | زیرعنوان انگلیسی |
| content | string | محتوای مرحله (HTML / Markdown) |
| order | integer | ترتیب نمایش مرحله |
| status | integer | وضعیت فعال/غیرفعال |
| created_at | datetime | تاریخ ساخت |
| updated_at | datetime | آخرین بهروزرسانی |
Course Object Structure (Extracted From Last Step)
| Field | Type | Description |
|---|---|---|
| id | integer | شناسه دوره (از آخرین step) |
| slug | string | اسلاگ دوره |
| branch | integer | false | شناسه شعبه یا false |
| price | integer | "free" | قیمت دوره |
| necessary | array | false | پیشنیازها |
| title.fa | string | عنوان فارسی دوره |
| title.en | string | عنوان انگلیسی دوره |
| category.* | object | اطلاعات دستهبندی |
| progress.current_step | integer | مرحله فعلی |
| progress.completed | integer | تعداد مراحل تکمیلشده |
| duration | integer | مدت زمان دوره |
| total_steps | integer | تعداد کل مراحل |
| featured | integer | 1 اگر دوره ویژه است |
| created_at | datetime | تاریخ ساخت |
| updated_at | datetime | آخرین تغییر |
| steps | array | آرایهی تمام مراحل |
Important Note
اطلاعات دوره از **آخرین step** استخراج میشود. این رفتار در کد وجود دارد و توسط کاربر (علیرضا) تأیید شدهاست. اگر steps خالی باشد، `$step` undefined شده و سیستم خطا خواهد داد.
Example Response
Status: 200 OK
{
"status": true,
"time": 1730000000,
"data": {
"id": 21,
"slug": "advanced-react",
"branch": false,
"price": "free",
"necessary": false,
"title": { "fa": "ریاکت پیشرفته", "en": "Advanced React" },
"category": {
"id": 3,
"flag": "frontend",
"title": { "fa": "فرانتاند", "en": "Frontend" }
},
"progress": { "current_step": 2, "completed": 1 },
"total_steps": 12,
"duration": 180,
"featured": 1,
"created_at": "2024-04-02 11:30:00",
"updated_at": "2024-04-20 19:12:00",
"status": 1,
"steps": [
{
"id": 10,
"title": { "fa": "آشنایی", "en": "Introduction" },
"subtitle": { "fa": "مقدمه", "en": "Intro" },
"content": "...",
"order": 1,
"status": 1,
"created_at": "2024-04-02 11:30:00",
"updated_at": "2024-04-02 11:30:00"
},
...
]
}
}
Flowchart
Validate JWT (operator)
↓
Fetch steps (JOIN course + category)
↓
Load or create progress record
↓
Update current_step / completed
↓
Build steps[]
↓
Extract course info from LAST step
↓
Return final structured course object