pinakes-server: add utoipa annotations to all routes; fix tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
This commit is contained in:
parent
67b8322705
commit
9d58927cb4
60 changed files with 3493 additions and 242 deletions
|
|
@ -6,14 +6,14 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::{error::ApiError, state::AppState};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateSavedSearchRequest {
|
||||
pub name: String,
|
||||
pub query: String,
|
||||
pub sort_order: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[derive(Debug, Serialize, utoipa::ToSchema)]
|
||||
pub struct SavedSearchResponse {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
|
|
@ -31,6 +31,19 @@ const VALID_SORT_ORDERS: &[&str] = &[
|
|||
"size_desc",
|
||||
];
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/searches",
|
||||
tag = "saved_searches",
|
||||
request_body = CreateSavedSearchRequest,
|
||||
responses(
|
||||
(status = 200, description = "Search saved", body = SavedSearchResponse),
|
||||
(status = 400, description = "Bad request"),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 500, description = "Internal server error"),
|
||||
),
|
||||
security(("bearer_auth" = []))
|
||||
)]
|
||||
pub async fn create_saved_search(
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<CreateSavedSearchRequest>,
|
||||
|
|
@ -76,6 +89,17 @@ pub async fn create_saved_search(
|
|||
}))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/searches",
|
||||
tag = "saved_searches",
|
||||
responses(
|
||||
(status = 200, description = "List of saved searches", body = Vec<SavedSearchResponse>),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 500, description = "Internal server error"),
|
||||
),
|
||||
security(("bearer_auth" = []))
|
||||
)]
|
||||
pub async fn list_saved_searches(
|
||||
State(state): State<AppState>,
|
||||
) -> Result<Json<Vec<SavedSearchResponse>>, ApiError> {
|
||||
|
|
@ -100,6 +124,19 @@ pub async fn list_saved_searches(
|
|||
))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/v1/searches/{id}",
|
||||
tag = "saved_searches",
|
||||
params(("id" = uuid::Uuid, Path, description = "Saved search ID")),
|
||||
responses(
|
||||
(status = 200, description = "Saved search deleted"),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 404, description = "Not found"),
|
||||
(status = 500, description = "Internal server error"),
|
||||
),
|
||||
security(("bearer_auth" = []))
|
||||
)]
|
||||
pub async fn delete_saved_search(
|
||||
State(state): State<AppState>,
|
||||
Path(id): Path<uuid::Uuid>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue