Skip to main content

docbox_http/models/
admin.rs

1use axum::http::StatusCode;
2use docbox_core::database::models::document_box::DocumentBox;
3use garde::Validate;
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6use utoipa::ToSchema;
7
8use crate::error::HttpError;
9
10#[derive(Default, Debug, Validate, Deserialize, Serialize, ToSchema)]
11#[serde(default)]
12pub struct TenantDocumentBoxesRequest {
13    /// Optional query to search document boxes by
14    #[garde(skip)]
15    pub query: Option<String>,
16
17    /// Number of items to include in the response
18    #[garde(skip)]
19    pub size: Option<u16>,
20
21    /// Offset to start results from
22    #[garde(skip)]
23    pub offset: Option<u64>,
24}
25
26#[derive(Debug, Serialize, ToSchema)]
27pub struct TenantDocumentBoxesResponse {
28    /// The document boxes
29    pub results: Vec<DocumentBox>,
30    /// The total number of document boxes available to query
31    pub total: i64,
32}
33
34#[derive(Debug, Serialize, ToSchema)]
35pub struct TenantStatsResponse {
36    /// Total number of files within the document box
37    pub total_files: i64,
38    /// Total number of links within the document box
39    pub total_links: i64,
40    /// Total number of folders within the document box
41    pub total_folders: i64,
42    /// Total size of all files within the tenant
43    pub file_size: i64,
44}
45
46#[derive(Debug, Error)]
47pub enum HttpAdminError {
48    #[error("user not found")]
49    UnknownUser,
50    #[error(
51        "user is attached to resources, all resources must be deleted or detached before the user can be deleted"
52    )]
53    UserResourcesAttached,
54}
55
56impl HttpError for HttpAdminError {
57    fn status(&self) -> axum::http::StatusCode {
58        match self {
59            HttpAdminError::UnknownUser => StatusCode::NOT_FOUND,
60            HttpAdminError::UserResourcesAttached => StatusCode::BAD_REQUEST,
61        }
62    }
63}