34 lines
873 B
Rust
34 lines
873 B
Rust
use std::sync::Arc;
|
|
|
|
use axum::{response::IntoResponse, routing::get, Json, Router};
|
|
|
|
use crate::{
|
|
content::site::SiteRepository,
|
|
database::Database,
|
|
http::{error::ApiError, session::RequireUser},
|
|
state::AppState,
|
|
};
|
|
|
|
/// List sites owned by user
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/users/{name}/sites",
|
|
params(
|
|
("name" = String, Path, description = "User name")
|
|
),
|
|
responses(
|
|
(status = 200, description = "List of sites fetched", body = [SiteShortInfo])
|
|
)
|
|
)]
|
|
pub(super) async fn get_user_sites<Repo: SiteRepository>(
|
|
repository: Repo,
|
|
RequireUser(user): RequireUser,
|
|
) -> Result<impl IntoResponse, ApiError<'static>> {
|
|
let results = repository.get_sites_by_owner(&user.id).await?;
|
|
Ok(Json(results))
|
|
}
|
|
|
|
pub(super) fn router() -> Router<Arc<AppState>> {
|
|
Router::new().route("/@current/sites", get(get_user_sites::<Database>))
|
|
}
|