use rocket::{http::Status, serde::json::Json};

use crate::model::course::Course;

#[get("/course")]
pub async fn get_all() -> (Status, Json<Vec<Course>>) {
    match Course::get_all().await {
        Ok(data) => (Status::Ok, Json(data)),
        Err(err) => {
            eprintln!("Error getting courses: {}", err);

            (Status::InternalServerError, Json(vec![]))
        }
    }
}
