[]]], parameters: [new OA\Parameter(name: 'course', in: 'path', required: true, schema: new OA\Schema(type: 'integer'))], responses: [new OA\Response(response: 200, description: 'Blok listesi')], )] public function index(Course $course): AnonymousResourceCollection { return CourseBlockResource::collection( $course->blocks()->orderBy('order_index')->get() ); } #[OA\Post( path: '/api/admin/courses/{course}/blocks', summary: 'Yeni eğitim bloğu oluştur', tags: ['Admin - Course Blocks'], security: [['sanctum' => []]], parameters: [new OA\Parameter(name: 'course', in: 'path', required: true, schema: new OA\Schema(type: 'integer'))], requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent( required: ['type', 'content'], properties: [ new OA\Property(property: 'type', type: 'string'), new OA\Property(property: 'content', type: 'object'), new OA\Property(property: 'order_index', type: 'integer'), new OA\Property(property: 'is_active', type: 'boolean'), ], )), responses: [ new OA\Response(response: 201, description: 'Blok oluşturuldu'), new OA\Response(response: 422, description: 'Validasyon hatası'), ], )] public function store(Request $request, Course $course): JsonResponse { $validated = $request->validate([ 'type' => ['required', 'string', 'max:50'], 'content' => ['present', 'array'], 'order_index' => ['sometimes', 'integer', 'min:0'], 'is_active' => ['sometimes', 'boolean'], ]); $validated['order_index'] ??= $course->blocks()->max('order_index') + 1; $block = $course->blocks()->create($validated); return response()->json(new CourseBlockResource($block), 201); } #[OA\Get( path: '/api/admin/courses/{course}/blocks/{block}', summary: 'Eğitim blok detayı', tags: ['Admin - Course Blocks'], security: [['sanctum' => []]], parameters: [ new OA\Parameter(name: 'course', in: 'path', required: true, schema: new OA\Schema(type: 'integer')), new OA\Parameter(name: 'block', in: 'path', required: true, schema: new OA\Schema(type: 'integer')), ], responses: [new OA\Response(response: 200, description: 'Blok detayı')], )] public function show(Course $course, CourseBlock $block): JsonResponse { return response()->json(new CourseBlockResource($block)); } #[OA\Put( path: '/api/admin/courses/{course}/blocks/{block}', summary: 'Eğitim bloğu güncelle', tags: ['Admin - Course Blocks'], security: [['sanctum' => []]], parameters: [ new OA\Parameter(name: 'course', in: 'path', required: true, schema: new OA\Schema(type: 'integer')), new OA\Parameter(name: 'block', in: 'path', required: true, schema: new OA\Schema(type: 'integer')), ], requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent( properties: [ new OA\Property(property: 'type', type: 'string'), new OA\Property(property: 'content', type: 'object'), new OA\Property(property: 'order_index', type: 'integer'), new OA\Property(property: 'is_active', type: 'boolean'), ], )), responses: [ new OA\Response(response: 200, description: 'Blok güncellendi'), new OA\Response(response: 422, description: 'Validasyon hatası'), ], )] public function update(Request $request, Course $course, CourseBlock $block): JsonResponse { $validated = $request->validate([ 'type' => ['sometimes', 'string', 'max:50'], 'content' => ['sometimes', 'array'], 'order_index' => ['sometimes', 'integer', 'min:0'], 'is_active' => ['sometimes', 'boolean'], ]); $block->update($validated); return response()->json(new CourseBlockResource($block->fresh())); } #[OA\Delete( path: '/api/admin/courses/{course}/blocks/{block}', summary: 'Eğitim bloğu sil', tags: ['Admin - Course Blocks'], security: [['sanctum' => []]], parameters: [ new OA\Parameter(name: 'course', in: 'path', required: true, schema: new OA\Schema(type: 'integer')), new OA\Parameter(name: 'block', in: 'path', required: true, schema: new OA\Schema(type: 'integer')), ], responses: [new OA\Response(response: 200, description: 'Blok silindi')], )] public function destroy(Course $course, CourseBlock $block): JsonResponse { $block->delete(); return response()->json(['message' => 'Blok silindi.']); } #[OA\Post( path: '/api/admin/courses/{course}/blocks/reorder', summary: 'Eğitim blok sıralamasını güncelle', tags: ['Admin - Course Blocks'], security: [['sanctum' => []]], parameters: [new OA\Parameter(name: 'course', in: 'path', required: true, schema: new OA\Schema(type: 'integer'))], requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent( required: ['items'], properties: [ new OA\Property(property: 'items', type: 'array', items: new OA\Items( properties: [ new OA\Property(property: 'id', type: 'integer'), new OA\Property(property: 'order_index', type: 'integer'), ], )), ], )), responses: [new OA\Response(response: 200, description: 'Sıralama güncellendi')], )] public function reorder(Request $request, Course $course): JsonResponse { $validated = $request->validate([ 'items' => ['required', 'array', 'min:1'], 'items.*.id' => ['required', 'integer', 'exists:course_blocks,id'], 'items.*.order_index' => ['required', 'integer', 'min:0'], ]); foreach ($validated['items'] as $item) { $course->blocks() ->where('id', $item['id']) ->update(['order_index' => $item['order_index']]); } return response()->json(['message' => 'Blok sıralaması güncellendi.']); } }