Skip to content
Clone
a06673b
27 lines 897 B Rust
use axum::Json;
use axum::extract::{Path, State};
use axum::http::StatusCode;
use jwt::extractor::AuthUser;
use uuid::Uuid;
use crate::error::RepoResult;
use crate::features::RepoService;
use crate::features::contents::{ContentsResponse, CreateFileOption};
#[utoipa::path(
post,
path = "/repo/{channel_id}/{repo_id}/contents/{path}",
tag = "repo",
request_body = CreateFileOption,
responses((status = 201, description = "Create a file", body = ContentsResponse)),
security(("bearer_auth" = []))
)]
pub(crate) async fn handler(
State(svc): State<RepoService>,
AuthUser { claims }: AuthUser,
Path((_, repo_id, path)): Path<(Uuid, Uuid, String)>,
Json(input): Json<CreateFileOption>,
) -> RepoResult<(StatusCode, Json<ContentsResponse>)> {
let resp = svc.create_file(claims.sub, repo_id, &path, input).await?;
Ok((StatusCode::CREATED, Json(resp)))
}