use axum::extract::State;
use axum::routing::get;
use axum::{Json, Router};

use crate::app::AppState;
use crate::domain::genre::Genre;
use crate::error::AppResult;
use crate::repo;

pub fn routes() -> Router<AppState> {
    Router::new().route("/genres", get(list))
}

async fn list(State(state): State<AppState>) -> AppResult<Json<Vec<Genre>>> {
    Ok(Json(repo::genre::list_all(&state.db).await?))
}
