Option<T> represents a value that may be present or absent. In the course API, it models fields that database records or client payloads do not have to provide. section 6.2.1
Use optional fields when different application boundaries impose different requirements:
- Course stores optional description, format, structure, duration, price, language, level, and posted time values. section 6.2.1
- CreateCourse keeps client-supplied fields optional while requiring tutor_id and course_name. section 6.2.1
- UpdateCourse makes every editable course field optional, allowing partial updates. section 6.2.1
- Database columns corresponding to optional fields omit NOT NULL, preserving the same absence model. section 6.2.1 section 6.4
Course model
A course can require identity fields while permitting absent metadata: course_id, tutor_id, and course_name are mandatory, whereas course_description and course_price use Option<T>. Serialization and sqlx::FromRow then support API output and database-record conversion. section 6.2.1
#[derive(Serialize, Debug, Clone, sqlx::FromRow)]
pub struct Course {
pub course_id: i32,
pub tutor_id: i32,
pub course_name: String,
pub course_description: Option<String>,
pub course_format: Option<String>,
pub course_structure: Option<String>,
pub course_duration: Option<String>,
pub course_price: Option<i32>,
pub course_language: Option<String>,
pub course_level: Option<String>,
pub posted_time: Option<NaiveDateTime>,
}
Inspect the complete Course struct and its Option<T> fields alongside the required fields. section 6.2.1








