Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
oestradiol committed Apr 25, 2024
1 parent f6e03bd commit 967c192
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/business/repositories/deployments/find_by_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use axum::http::StatusCode;
use mongodb::bson::{doc, oid::ObjectId};
use tracing::{event, Level};

pub async fn find_by_id(id: String) -> Result<Deployment, VoyagerError> {
pub async fn find_by_id(id: &str) -> Result<Deployment, VoyagerError> {
event!(
Level::DEBUG,
"Finding deployment with id {} in database",
&id
);

let oid = ObjectId::from_str(id.as_str())
.map_err(|e| VoyagerError::invalid_find_id(Box::new(e), &id))?;
let oid = ObjectId::from_str(id)
.map_err(|e| VoyagerError::invalid_find_id(Box::new(e), id))?;

let result = REPOSITORIES_RUNTIME
.spawn_handled(
Expand All @@ -27,8 +27,8 @@ pub async fn find_by_id(id: String) -> Result<Deployment, VoyagerError> {
.await?;

let result = result.map_or_else(
|e| Err(VoyagerError::find_mongo_id(Box::new(e), &id)),
|r| r.ok_or_else(|| VoyagerError::find_null_id(&id)),
|e| Err(VoyagerError::find_mongo_id(Box::new(e), id)),
|r| r.ok_or_else(|| VoyagerError::find_null_id(id)),
)?;

event!(Level::DEBUG, "Done finding deployment");
Expand Down
9 changes: 4 additions & 5 deletions src/business/repositories/deployments/retrieve_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ pub async fn retrieve_all(
repo_url: Option<String>,
branch: Option<String>,
) -> Result<Vec<Deployment>, VoyagerError> {
let repo_and_branch = branch.clone().map_or(String::new(), |b| format!("@{b}"));
let repo_and_branch = repo_url
.clone()
let repo_and_branch = branch.as_ref().map_or(String::new(), |b| format!("@{b}"));
let repo_and_branch = repo_url.as_ref()
.map_or(String::new(), |r| format!("{r}{repo_and_branch}"));

event!(
Expand All @@ -24,8 +23,8 @@ pub async fn retrieve_all(
let future = async move {
let document = repo_url
.map_or_else(|| doc! { }, |repo_url|
branch.map_or_else(|| doc! {"repo_url": repo_url.clone()}, |branch|
doc! {"repo_url": repo_url.clone(), "branch": branch}
branch.map_or_else(|| doc! {"repo_url": &repo_url}, |branch|
doc! {"repo_url": &repo_url, "branch": branch}
)
);

Expand Down
5 changes: 3 additions & 2 deletions src/business/services/deployments/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::types::other::voyager_error::VoyagerError;
use crate::utils::runtime_helpers::RuntimeSpawnHandled;

pub async fn check(
host: String,
host: &str,
mode: Mode,
repo_url: String,
branch: Option<String>,
Expand All @@ -24,8 +24,9 @@ pub async fn check(
}
event!(Level::INFO, log);

let host = host.replace('.', "-");
let future = async move {
let result = repositories::deployments::find_by_name(host.replace('.', "-")).await?;
let result = repositories::deployments::find_by_name(host).await?;
match result {
Some(_) => Err(VoyagerError::new(
format!("Deployment at this subdomain already exists!"),
Expand Down
2 changes: 1 addition & 1 deletion src/business/services/deployments/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn delete(deployment_id: String) -> Result<(), VoyagerError> {
event!(Level::INFO, "Deleting deployment: {}", &deployment_id);

let future = async move {
let deployment = repositories::deployments::find_by_id(deployment_id.clone()).await?;
let deployment = repositories::deployments::find_by_id(&deployment_id).await?;
let name = deployment.container_name;

if is_container_running(name.clone()).await? {
Expand Down
4 changes: 2 additions & 2 deletions src/business/services/deployments/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub async fn list(
branch: Option<String>,
) -> Result<Vec<Deployment>, VoyagerError> {
let mut log = "Retrieving deployments".to_string();
if let Some(repo) = repo_url.clone() {
if let Some(repo) = repo_url.as_ref() {
log = format!("{log}. Repo: {repo}");
}
if let Some(branch) = branch.clone() {
if let Some(branch) = branch.as_ref() {
log = format!("{log}. Branch: {branch}");
}
event!(Level::INFO, log);
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/deployments/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn create(Query(queries): Query<HashMap<String, String>>) -> impl Into
let branch = split.get(1).map(std::string::ToString::to_string);

match async {
deployments::check(host.clone(), mode, repo_url.clone(), branch.clone()).await?;
deployments::check(&host, mode, repo_url.clone(), branch.clone()).await?;
deployments::new(host, mode, repo_url, branch).await
}.await {
Ok(deployment_id) => (
Expand Down

0 comments on commit 967c192

Please sign in to comment.