omni_orchestrator/schemas/v1/api/apps/release.rs
1use super::super::super::db::queries as db;
2use rocket::http::{ContentType, Status};
3use rocket::{post, Data, State};
4use std::sync::Arc;
5
6use crate::DatabaseManager;
7
8/// Releases a new version of the target application by uploading an artifact.
9/// TODO: @tristanpoland Review if we actually need this or should drop in favor
10/// of using the deploy route.
11///
12/// # Arguments
13///
14/// * `platform_id` - Platform identifier
15/// * `app_id` - The ID of the application to release a new version for
16/// * `release_version` - The version tag for this release
17/// * `content_type` - The content type of the data being uploaded
18/// * `data` - The data stream of the artifact being uploaded
19/// * `db_manager` - Database manager for accessing platform-specific pools
20///
21/// # Returns
22///
23/// * `Status::Ok` - If the artifact is successfully uploaded and added to the build jobs list
24/// * `Status::BadRequest` - If there is an error in the upload process
25///
26/// # Details
27///
28/// This route handles the release of a new version of an application by:
29/// 1. Uploading the provided artifact to the build artifacts list.
30/// 2. Adding the artifact to the list of build jobs for the Forge instances to pick up and process.
31///
32/// The actual implementation of the release process is delegated to the `helpers::release::release`
33/// function, as it is quite extensive.
34#[post(
35 "/platform/<platform_id>/apps/<app_id>/releases/<release_version>/upload",
36 format = "multipart/form-data",
37 data = "<data>"
38)]
39pub async fn create_release(
40 platform_id: i64,
41 app_id: String,
42 release_version: String,
43 content_type: &ContentType,
44 data: Data<'_>,
45 db_manager: &State<Arc<DatabaseManager>>,
46) -> Result<Status, Status> {
47 // We need to modify the helper function to work with platform-specific DBs
48 // For now, we'll just pass the helper what it needs, but ideally the helper should be updated to use platform pools
49
50 // Get platform info and pass to helper
51 match db::platforms::get_platform_by_id(db_manager.get_main_pool(), platform_id).await {
52 Ok(_) => {
53 // We found the platform, proceed with release
54 super::super::helpers::release::release(app_id, release_version, content_type, data).await
55 },
56 Err(_) => {
57 // Platform not found
58 Err(Status::NotFound)
59 }
60 }
61}