50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
import uuid
|
|
from typing import List, Optional
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/courses")
|
|
async def create_course(
|
|
title: str,
|
|
description: str,
|
|
instructor_id: str,
|
|
price: float,
|
|
duration_weeks: int,
|
|
max_students: Optional[int] = None
|
|
):
|
|
"""Create a new course in the online school"""
|
|
course_id = str(uuid.uuid4())
|
|
|
|
if not fake_users_db.get(instructor_id):
|
|
raise HTTPException(status_code=400, detail="Instructor not found")
|
|
|
|
course = {
|
|
"id": course_id,
|
|
"title": title,
|
|
"description": description,
|
|
"instructor_id": instructor_id,
|
|
"price": price,
|
|
"duration_weeks": duration_weeks,
|
|
"max_students": max_students,
|
|
"enrolled_students": [],
|
|
"status": "active"
|
|
}
|
|
|
|
fake_users_db[course_id] = course
|
|
|
|
return {
|
|
"message": "Course created successfully",
|
|
"course_id": course_id,
|
|
"course_details": course,
|
|
"features": {
|
|
"enrollment_open": True,
|
|
"materials_ready": False
|
|
},
|
|
"next_steps": [
|
|
"Upload course materials",
|
|
"Set up course schedule",
|
|
"Invite students"
|
|
]
|
|
} |