|
| 1 | +use crate::error::AppError; |
| 2 | +use crate::http::ui::models::aws; |
| 3 | +use crate::http::ui::models::database; |
| 4 | +use crate::http::ui::models::storage_profile; |
| 5 | +use crate::http::ui::models::table::Statistics; |
| 6 | +use crate::http::ui::models::warehouse; |
| 7 | +use crate::state::AppState; |
| 8 | +use axum::{extract::Path, extract::State, Json}; |
| 9 | +use swagger; |
| 10 | +use utoipa::OpenApi; |
| 11 | +use uuid::Uuid; |
| 12 | + |
| 13 | +#[derive(OpenApi)] |
| 14 | +#[openapi( |
| 15 | + paths( |
| 16 | + create_database, |
| 17 | + delete_database, |
| 18 | + get_database, |
| 19 | + ), |
| 20 | + components( |
| 21 | + schemas( |
| 22 | + database::CreateDatabasePayload, |
| 23 | + database::Database |
| 24 | + ) |
| 25 | + ), |
| 26 | + tags( |
| 27 | + (name = "Databases", description = "Databases management endpoints.") |
| 28 | + ) |
| 29 | +)] |
| 30 | +pub struct ApiDoc; |
| 31 | + |
| 32 | +#[utoipa::path( |
| 33 | + post, |
| 34 | + path = "/ui/warehouses/{warehouseId}/databases", |
| 35 | + operation_id = "webCreateDatabase", |
| 36 | + responses( |
| 37 | + (status = 200, description = "Successful Response", body = database::Database), |
| 38 | + (status = 400, description = "Bad request"), |
| 39 | + (status = 500, description = "Internal server error") |
| 40 | + ) |
| 41 | +)] |
| 42 | +pub async fn create_database( |
| 43 | + State(state): State<AppState>, |
| 44 | + Path(payload): Path<database::CreateDatabasePayload>, |
| 45 | +) -> Result<Json<database::Database>, AppError> { |
| 46 | + Ok(Json(database::Database { |
| 47 | + name: "".to_string(), |
| 48 | + properties: None, |
| 49 | + id: Default::default(), |
| 50 | + warehouse_id: Default::default(), |
| 51 | + })) |
| 52 | +} |
| 53 | + |
| 54 | +#[utoipa::path( |
| 55 | + delete, |
| 56 | + path = "/ui/warehouses/{warehouseId}/databases/{databaseName}", |
| 57 | + operation_id = "webDeleteDatabase", |
| 58 | + responses( |
| 59 | + (status = 204, description = "Successful Response"), |
| 60 | + (status = 404, description = "Database not found") |
| 61 | + ) |
| 62 | +)] |
| 63 | +pub async fn delete_database( |
| 64 | + State(state): State<AppState>, |
| 65 | + Path((warehouse_id, database_name)): Path<(Uuid, String)>, |
| 66 | +) -> Result<(), AppError> { |
| 67 | + Ok(()) |
| 68 | +} |
| 69 | + |
| 70 | +#[utoipa::path( |
| 71 | + get, |
| 72 | + path = "/ui/warehouses/{warehouseId}/databases/{databaseName}", |
| 73 | + operation_id = "webDatabaseDashboard", |
| 74 | + responses( |
| 75 | + (status = 200, description = "Successful Response", body = database::DatabaseDashboard), |
| 76 | + (status = 204, description = "Successful Response"), |
| 77 | + (status = 404, description = "Database not found") |
| 78 | + ) |
| 79 | +)] |
| 80 | +pub async fn get_database( |
| 81 | + State(state): State<AppState>, |
| 82 | + Path((warehouse_id, database_name)): Path<(Uuid, String)>, |
| 83 | +) -> Result<Json<database::DatabaseDashboard>, AppError> { |
| 84 | + Ok(Json(database::DatabaseDashboard { |
| 85 | + name: "".to_string(), |
| 86 | + properties: None, |
| 87 | + id: Default::default(), |
| 88 | + warehouse_id: Default::default(), |
| 89 | + warehouse: warehouse::WarehouseEntity { |
| 90 | + name: "".to_string(), |
| 91 | + storage_profile_id: Default::default(), |
| 92 | + key_prefix: "".to_string(), |
| 93 | + id: Default::default(), |
| 94 | + external_id: Default::default(), |
| 95 | + location: "".to_string(), |
| 96 | + created_at: Default::default(), |
| 97 | + updated_at: Default::default(), |
| 98 | + storage_profile: storage_profile::StorageProfile { |
| 99 | + r#type: aws::CloudProvider::S3, |
| 100 | + region: "".to_string(), |
| 101 | + bucket: "".to_string(), |
| 102 | + credentials: Default::default(), |
| 103 | + sts_role_arn: None, |
| 104 | + endpoint: None, |
| 105 | + id: Default::default(), |
| 106 | + created_at: Default::default(), |
| 107 | + updated_at: Default::default(), |
| 108 | + }, |
| 109 | + }, |
| 110 | + tables: vec![], |
| 111 | + statistics: Statistics { |
| 112 | + commit_count: 0, |
| 113 | + op_append_count: 0, |
| 114 | + op_overwrite_count: 0, |
| 115 | + op_delete_count: 0, |
| 116 | + op_replace_count: 0, |
| 117 | + total_bytes: 0, |
| 118 | + bytes_added: 0, |
| 119 | + bytes_removed: 0, |
| 120 | + total_rows: 0, |
| 121 | + rows_added: 0, |
| 122 | + rows_deleted: 0, |
| 123 | + table_count: None, |
| 124 | + database_count: None, |
| 125 | + }, |
| 126 | + compaction_summary: None, |
| 127 | + })) |
| 128 | +} |
0 commit comments