Make path params work with aide
This commit is contained in:
parent
461021cef1
commit
f9dafdfc88
5 changed files with 57 additions and 5 deletions
|
|
@ -7,6 +7,8 @@ use axum_extra::{
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::Deserialize;
|
||||||
use sync_lib::base64_to_bytes;
|
use sync_lib::base64_to_bytes;
|
||||||
|
|
||||||
use super::{auth::auth, requests::CreateDocumentVersion};
|
use super::{auth::auth, requests::CreateDocumentVersion};
|
||||||
|
|
@ -16,10 +18,16 @@ use crate::{
|
||||||
errors::{client_error, server_error, SyncServerError},
|
errors::{client_error, server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is required for aide to infer the path parameter types and names
|
||||||
|
#[derive(Deserialize, JsonSchema)]
|
||||||
|
pub struct PathParams {
|
||||||
|
vault_id: VaultId,
|
||||||
|
}
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
pub async fn create_document(
|
pub async fn create_document(
|
||||||
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
||||||
Path(vault_id): Path<VaultId>,
|
Path(PathParams { vault_id }): Path<PathParams>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Json(request): Json<CreateDocumentVersion>,
|
Json(request): Json<CreateDocumentVersion>,
|
||||||
) -> Result<Json<DocumentVersionWithoutContent>, SyncServerError> {
|
) -> Result<Json<DocumentVersionWithoutContent>, SyncServerError> {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use axum_extra::{
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::{auth::auth, requests::DeleteDocumentVersion};
|
use super::{auth::auth, requests::DeleteDocumentVersion};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -15,10 +17,20 @@ use crate::{
|
||||||
errors::{not_found_error, server_error, SyncServerError},
|
errors::{not_found_error, server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is required for aide to infer the path parameter types and names
|
||||||
|
#[derive(Deserialize, JsonSchema)]
|
||||||
|
pub struct PathParams {
|
||||||
|
vault_id: VaultId,
|
||||||
|
document_id: DocumentId,
|
||||||
|
}
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
pub async fn delete_document(
|
pub async fn delete_document(
|
||||||
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
||||||
Path((vault_id, document_id)): Path<(VaultId, DocumentId)>,
|
Path(PathParams {
|
||||||
|
vault_id,
|
||||||
|
document_id,
|
||||||
|
}): Path<PathParams>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Json(request): Json<DeleteDocumentVersion>,
|
Json(request): Json<DeleteDocumentVersion>,
|
||||||
) -> Result<(), SyncServerError> {
|
) -> Result<(), SyncServerError> {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use axum_extra::{
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::auth::auth;
|
use super::auth::auth;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -15,10 +17,20 @@ use crate::{
|
||||||
errors::{not_found_error, server_error, SyncServerError},
|
errors::{not_found_error, server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is required for aide to infer the path parameter types and names
|
||||||
|
#[derive(Deserialize, JsonSchema)]
|
||||||
|
pub struct PathParams {
|
||||||
|
vault_id: VaultId,
|
||||||
|
document_id: DocumentId,
|
||||||
|
}
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
pub async fn fetch_latest_document_version(
|
pub async fn fetch_latest_document_version(
|
||||||
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
||||||
Path((vault_id, document_id)): Path<(VaultId, DocumentId)>,
|
Path(PathParams {
|
||||||
|
vault_id,
|
||||||
|
document_id,
|
||||||
|
}): Path<PathParams>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
) -> Result<Json<DocumentVersion>, SyncServerError> {
|
) -> Result<Json<DocumentVersion>, SyncServerError> {
|
||||||
auth(&state, auth_header.token())?;
|
auth(&state, auth_header.token())?;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ use axum_extra::{
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::auth::auth;
|
use super::auth::auth;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -14,10 +16,16 @@ use crate::{
|
||||||
errors::{server_error, SyncServerError},
|
errors::{server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is required for aide to infer the path parameter types and names
|
||||||
|
#[derive(Deserialize, JsonSchema)]
|
||||||
|
pub struct PathParams {
|
||||||
|
vault_id: VaultId,
|
||||||
|
}
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
pub async fn fetch_latest_documents(
|
pub async fn fetch_latest_documents(
|
||||||
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
||||||
Path(vault_id): Path<VaultId>,
|
Path(PathParams { vault_id }): Path<PathParams>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
) -> Result<Json<Vec<DocumentVersionWithoutContent>>, SyncServerError> {
|
) -> Result<Json<Vec<DocumentVersionWithoutContent>>, SyncServerError> {
|
||||||
auth(&state, auth_header.token())?;
|
auth(&state, auth_header.token())?;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use axum_extra::{
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::Deserialize;
|
||||||
use sync_lib::{base64_to_bytes, base64_to_string};
|
use sync_lib::{base64_to_bytes, base64_to_string};
|
||||||
|
|
||||||
use super::{auth::auth, requests::UpdateDocumentVersion};
|
use super::{auth::auth, requests::UpdateDocumentVersion};
|
||||||
|
|
@ -16,10 +18,20 @@ use crate::{
|
||||||
errors::{client_error, not_found_error, server_error, SyncServerError},
|
errors::{client_error, not_found_error, server_error, SyncServerError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is required for aide to infer the path parameter types and names
|
||||||
|
#[derive(Deserialize, JsonSchema)]
|
||||||
|
pub struct PathParams {
|
||||||
|
vault_id: VaultId,
|
||||||
|
document_id: DocumentId,
|
||||||
|
}
|
||||||
|
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
pub async fn update_document(
|
pub async fn update_document(
|
||||||
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(auth_header): TypedHeader<Authorization<Bearer>>,
|
||||||
Path((vault_id, document_id)): Path<(VaultId, DocumentId)>,
|
Path(PathParams {
|
||||||
|
vault_id,
|
||||||
|
document_id,
|
||||||
|
}): Path<PathParams>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Json(request): Json<UpdateDocumentVersion>,
|
Json(request): Json<UpdateDocumentVersion>,
|
||||||
) -> Result<Json<DocumentVersionWithoutContent>, SyncServerError> {
|
) -> Result<Json<DocumentVersionWithoutContent>, SyncServerError> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue