rustploy 0.1.36

Rustploy PaaS daemon — lightweight self-hosted deployment platform
//! `Command::DeployRollback`: acha o deploy Live anterior de um serviço (só
//! consulta; não redeploya).

use crate::bootstrap::state::AppState;
use shared::Response as RpResponse;

pub async fn handle(state: AppState, service_id: String) -> RpResponse {
    match crate::store::deployments::list_for_service(&state.db, &service_id, 10).await {
        Ok(history) => {
            let prev = history
                .iter()
                .skip(1)
                .find(|d| d.state == shared::DeployState::Live);
            match prev {
                Some(d) => RpResponse::Deployment(Box::new(d.clone())),
                None => RpResponse::err("NotFound", "no previous successful deploy"),
            }
        }
        Err(e) => RpResponse::err("DatabaseError", e.to_string()),
    }
}