Skip to content

Commit ea8f496

Browse files
committed
Refactor API schemas into modular route files
Split monolithic API route files into modular submodules for builds, deployments, instances, metrics, notifications, and permissions. Each resource now has dedicated files for CRUD operations and route registration, improving maintainability and clarity of the codebase.
1 parent 2f82a8e commit ea8f496

File tree

29 files changed

+1277
-1111
lines changed

29 files changed

+1277
-1111
lines changed

src/schemas/v1/api/builds/get.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::sync::Arc;
2+
use crate::DatabaseManager;
3+
use super::super::super::db::queries as db;
4+
use rocket::serde::json::{json, Json, Value};
5+
use rocket::{get, http::Status, State};
6+
7+
use libomni::types::db::v1 as types;
8+
use types::build::Build;
9+
10+
/// Get a specific build by ID.
11+
#[get("/platform/<platform_id>/builds/<build_id>")]
12+
pub async fn get_build(
13+
platform_id: i64,
14+
build_id: i64,
15+
db_manager: &State<Arc<DatabaseManager>>,
16+
) -> Result<Json<Build>, (Status, Json<Value>)> {
17+
// Get platform information
18+
let platform = match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
19+
Ok(platform) => platform,
20+
Err(_) => {
21+
return Err((
22+
Status::NotFound,
23+
Json(json!({
24+
"error": "Platform not found",
25+
"message": format!("Platform with ID {} does not exist", platform_id)
26+
}))
27+
));
28+
}
29+
};
30+
31+
// Get platform-specific database pool
32+
let pool = match db_manager.get_platform_pool(&platform.name, platform_id).await {
33+
Ok(pool) => pool,
34+
Err(_) => {
35+
return Err((
36+
Status::InternalServerError,
37+
Json(json!({
38+
"error": "Database error",
39+
"message": "Failed to connect to platform database"
40+
}))
41+
));
42+
}
43+
};
44+
45+
match db::build::get_build_by_id(&pool, build_id).await {
46+
Ok(build) => Ok(Json(build)),
47+
Err(_) => Err((
48+
Status::NotFound,
49+
Json(json!({
50+
"error": "Build not found",
51+
"message": format!("Build with ID {} could not be found", build_id)
52+
}))
53+
)),
54+
}
55+
}
Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::sync::Arc;
22
use crate::DatabaseManager;
3-
use super::super::db::queries as db;
4-
use rocket::serde::json::{self, json, Json, Value};
5-
use rocket::{delete, get, http::{ContentType, Status}, post, put, Data, State};
3+
use super::super::super::db::queries as db;
4+
use rocket::serde::json::{json, Json, Value};
5+
use rocket::{get, http::Status, State};
66

77
use libomni::types::db::v1 as types;
88
use types::build::Build;
@@ -139,51 +139,4 @@ pub async fn list_builds_for_app(
139139
}))
140140
)),
141141
}
142-
}
143-
144-
/// Get a specific build by ID.
145-
#[get("/platform/<platform_id>/builds/<build_id>")]
146-
pub async fn get_build(
147-
platform_id: i64,
148-
build_id: i64,
149-
db_manager: &State<Arc<DatabaseManager>>,
150-
) -> Result<Json<Build>, (Status, Json<Value>)> {
151-
// Get platform information
152-
let platform = match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
153-
Ok(platform) => platform,
154-
Err(_) => {
155-
return Err((
156-
Status::NotFound,
157-
Json(json!({
158-
"error": "Platform not found",
159-
"message": format!("Platform with ID {} does not exist", platform_id)
160-
}))
161-
));
162-
}
163-
};
164-
165-
// Get platform-specific database pool
166-
let pool = match db_manager.get_platform_pool(&platform.name, platform_id).await {
167-
Ok(pool) => pool,
168-
Err(_) => {
169-
return Err((
170-
Status::InternalServerError,
171-
Json(json!({
172-
"error": "Database error",
173-
"message": "Failed to connect to platform database"
174-
}))
175-
));
176-
}
177-
};
178-
179-
match db::build::get_build_by_id(&pool, build_id).await {
180-
Ok(build) => Ok(Json(build)),
181-
Err(_) => Err((
182-
Status::NotFound,
183-
Json(json!({
184-
"error": "Build not found",
185-
"message": format!("Build with ID {} could not be found", build_id)
186-
}))
187-
)),
188-
}
189142
}

src/schemas/v1/api/builds/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Build management module for handling build operations.
2+
//!
3+
//! This module provides a REST API for managing builds, including:
4+
//! - Listing builds with pagination
5+
//! - Getting build details
6+
//! - Listing builds for specific applications
7+
8+
// Import and re-export all route modules
9+
pub mod list;
10+
pub mod get;
11+
12+
// Re-export all route functions
13+
pub use list::{list_builds, list_builds_for_app};
14+
pub use get::get_build;

0 commit comments

Comments
 (0)