Skip to content
Clone

refactor(repo): refresh extras file_contents handler

zhenyi committed
parent 4ce8f40 commit 67ffbb2 Browse files

1 file changed

+13 −12

Modified lib/repo/handler/extras/file_contents.rs View lib/repo/handler/extras/file_contents.rs
@@ -1,33 +1,34 @@
1use axum::Json;
21use axum::extract::{Path, State};
2use export::data::{AppRequest, AppRequestData, AppResponseData};
3
34use jwt::extractor::AuthUser;
45use uuid::Uuid;
56
67use crate::error::RepoResult;
78use crate::features::RepoService;
8use crate::features::contents::types::FilesResponse;
9use export::repo::contents::FilesResponse;
910use crate::features::extras::FileDeleteResponse;
1011
1112#[utoipa::path(
1213 get,
1314 path = "/repo/{channel_id}/{repo_id}/file-contents",
1415 tag = "repo",
15 responses((status = 200, description = "Batch read files", body = FilesResponse)),
16 responses((status = 200, description = "Batch read files", body = AppResponseData<FilesResponse>)),
1617 security(("bearer_auth" = []))
1718)]
1819pub(crate) async fn get_handler(
1920 State(svc): State<RepoService>,
2021 AuthUser { claims }: AuthUser,
2122 Path((_, repo_id)): Path<(Uuid, Uuid)>,
22) -> RepoResult<Json<FilesResponse>> {
23) -> RepoResult<AppResponseData<FilesResponse>> {
2324 let out = svc
2425 .get_file_contents(claims.sub, repo_id, Vec::new())
2526 .await?;
26 Ok(Json(FilesResponse {
27 Ok(AppResponseData::ok(FilesResponse {
2728 commit: None,
2829 files: out
2930 .into_iter()
30 .map(|v| crate::features::contents::types::ContentsResponse {
31 .map(|v| export::repo::contents::ContentsResponse {
3132 name: String::new(),
3233 path: String::new(),
3334 sha: String::new(),
@@ -57,18 +58,18 @@
5758 post,
5859 path = "/repo/{channel_id}/{repo_id}/file-contents",
5960 tag = "repo",
60 request_body = Vec<String>,
61 responses((status = 200, description = "Batch read files", body = FileDeleteResponse)),
61 request_body = AppRequestData<Vec<String>>,
62 responses((status = 200, description = "Batch read files", body = AppResponseData<FileDeleteResponse>)),
6263 security(("bearer_auth" = []))
6364)]
6465pub(crate) async fn post_handler(
6566 State(svc): State<RepoService>,
6667 AuthUser { claims }: AuthUser,
6768 Path((_, repo_id)): Path<(Uuid, Uuid)>,
68 Json(files): Json<Vec<String>>,
69) -> RepoResult<Json<FileDeleteResponse>> {
70 let out = svc.get_file_contents(claims.sub, repo_id, files).await?;
71 Ok(Json(FileDeleteResponse {
69 files: AppRequest<Vec<String>>,
70) -> RepoResult<AppResponseData<FileDeleteResponse>> {
71 let out = svc.get_file_contents(claims.sub, repo_id, files.into_inner()).await?;
72 Ok(AppResponseData::ok(FileDeleteResponse {
7273 commit: None,
7374 content: Some(serde_json::json!(out)),
7475 }))