feat: enhance UpstreamTargetInfo with upstream details and refactor imports
This commit is contained in:
@@ -4,7 +4,7 @@ use optfield::optfield;
|
|||||||
use sea_orm::ActiveValue::{Set, Unchanged};
|
use sea_orm::ActiveValue::{Set, Unchanged};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use database::generated::entities::upstream_target;
|
use database::generated::entities::{upstream, upstream_target};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
services::nginx::{builder::NginxConfigProvider, traits::indentable::Indentable},
|
services::nginx::{builder::NginxConfigProvider, traits::indentable::Indentable},
|
||||||
@@ -24,6 +24,17 @@ pub struct UpstreamTargetInfo {
|
|||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
//
|
//
|
||||||
pub upstream_id: uuid::Uuid,
|
pub upstream_id: uuid::Uuid,
|
||||||
|
pub upstream: Option<UpstreamBasicInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct UpstreamBasicInfo {
|
||||||
|
pub id: uuid::Uuid,
|
||||||
|
pub name: String,
|
||||||
|
pub protocol: String,
|
||||||
|
//
|
||||||
|
pub created_at: DateTime<Utc>,
|
||||||
|
pub updated_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UpstreamTargetCreateInfo {
|
pub struct UpstreamTargetCreateInfo {
|
||||||
@@ -48,6 +59,31 @@ impl From<upstream_target::Model> for UpstreamTargetInfo {
|
|||||||
created_at: model.created_at,
|
created_at: model.created_at,
|
||||||
updated_at: model.updated_at,
|
updated_at: model.updated_at,
|
||||||
upstream_id: model.upstream_id,
|
upstream_id: model.upstream_id,
|
||||||
|
upstream: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(upstream_target::Model, upstream::Model)> for UpstreamTargetInfo {
|
||||||
|
fn from(data: (upstream_target::Model, upstream::Model)) -> Self {
|
||||||
|
let (target_model, up_model) = data;
|
||||||
|
Self {
|
||||||
|
id: target_model.id,
|
||||||
|
target_host: target_model.target_host,
|
||||||
|
target_port: target_model.target_port,
|
||||||
|
weight: target_model.weight,
|
||||||
|
is_backup: target_model.is_backup,
|
||||||
|
enabled: target_model.enabled,
|
||||||
|
created_at: target_model.created_at,
|
||||||
|
updated_at: target_model.updated_at,
|
||||||
|
upstream_id: target_model.upstream_id,
|
||||||
|
upstream: Some(UpstreamBasicInfo {
|
||||||
|
id: up_model.id,
|
||||||
|
name: up_model.name,
|
||||||
|
protocol: up_model.protocol,
|
||||||
|
created_at: up_model.created_at,
|
||||||
|
updated_at: up_model.updated_at,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user