add created_at to ListItem

This commit is contained in:
mbecker20
2024-01-13 17:16:29 -08:00
parent 5cae0b99c7
commit a11aa5c751
4 changed files with 95 additions and 14 deletions

View File

@@ -195,8 +195,11 @@ impl StateResource<Server> for State {
) -> anyhow::Result<ServerListItem> {
let status = self.server_status_cache.get(&server.id).await;
Ok(ServerListItem {
id: server.id,
name: server.name,
created_at: ObjectId::from_str(&server.id)?
.timestamp()
.timestamp_millis(),
id: server.id,
tags: server.tags,
resource_type: ResourceTargetVariant::Server,
info: ServerListItemInfo {
@@ -245,8 +248,11 @@ impl StateResource<Deployment> for State {
DeploymentImage::Image { image } => (image, None),
};
Ok(DeploymentListItem {
id: deployment.id,
name: deployment.name,
created_at: ObjectId::from_str(&deployment.id)?
.timestamp()
.timestamp_millis(),
id: deployment.id,
tags: deployment.tags,
resource_type: ResourceTargetVariant::Deployment,
info: DeploymentListItemInfo {
@@ -282,8 +288,11 @@ impl StateResource<Build> for State {
build: Build,
) -> anyhow::Result<BuildListItem> {
Ok(BuildListItem {
id: build.id,
name: build.name,
created_at: ObjectId::from_str(&build.id)?
.timestamp()
.timestamp_millis(),
id: build.id,
tags: build.tags,
resource_type: ResourceTargetVariant::Build,
info: BuildListItemInfo {
@@ -311,8 +320,11 @@ impl StateResource<Repo> for State {
repo: Repo,
) -> anyhow::Result<RepoListItem> {
Ok(RepoListItem {
id: repo.id,
name: repo.name,
created_at: ObjectId::from_str(&repo.id)?
.timestamp()
.timestamp_millis(),
id: repo.id,
tags: repo.tags,
resource_type: ResourceTargetVariant::Repo,
info: RepoInfo {
@@ -348,8 +360,11 @@ impl StateResource<Builder> for State {
};
Ok(BuilderListItem {
id: builder.id,
name: builder.name,
created_at: ObjectId::from_str(&builder.id)?
.timestamp()
.timestamp_millis(),
id: builder.id,
tags: builder.tags,
resource_type: ResourceTargetVariant::Builder,
info: BuilderListItemInfo {
@@ -381,8 +396,11 @@ impl StateResource<Alerter> for State {
AlerterConfig::Slack(_) => "slack",
};
Ok(AlerterListItem {
id: alerter.id,
name: alerter.name,
created_at: ObjectId::from_str(&alerter.id)?
.timestamp()
.timestamp_millis(),
id: alerter.id,
tags: alerter.tags,
resource_type: ResourceTargetVariant::Alerter,
info: AlerterListItemInfo {
@@ -410,8 +428,11 @@ impl StateResource<Procedure> for State {
procedure: Procedure,
) -> anyhow::Result<ProcedureListItem> {
Ok(ProcedureListItem {
id: procedure.id,
name: procedure.name,
created_at: ObjectId::from_str(&procedure.id)?
.timestamp()
.timestamp_millis(),
id: procedure.id,
tags: procedure.tags,
resource_type: ResourceTargetVariant::Alerter,
info: ProcedureListItemInfo {

View File

@@ -1,3 +1,6 @@
use monitor_client::entities::deployment::{
DeploymentQuery, DeploymentQuerySpecifics,
};
use monitor_client::MonitorClient;
use monitor_client::{
api::{execute, read, write},
@@ -11,8 +14,6 @@ use monitor_client::{
pub async fn tests() -> anyhow::Result<()> {
dotenv::dotenv().ok();
// create_secret().await?;
let monitor = MonitorClient::new_from_env().await?;
// create_server(&monitor).await?;
@@ -29,9 +30,29 @@ pub async fn tests() -> anyhow::Result<()> {
// let updates = monitor.read(read::ListUpdates { query: None, page: 0 }).await?;
// println!("{updates:#?}");
let dep_summary =
monitor.read(read::GetDeploymentsSummary {}).await?;
println!("{dep_summary:#?}");
// let dep_summary =
// monitor.read(read::GetDeploymentsSummary {}).await?;
// println!("{dep_summary:#?}");
// let deps = monitor.read(read::ListDeployments::default()).await?;
// println!("{deps:#?}");
let deps = monitor
.read(read::ListDeployments {
query: DeploymentQuery {
names: vec![
String::from("haboda"),
String::from("actual_shit"),
],
specific: DeploymentQuerySpecifics {
server_ids: vec![String::from("64b4cb8c384ffd253e375ed2")],
},
..Default::default()
},
// query: Default::default(),
})
.await?;
println!("{deps:#?}");
Ok(())
}
@@ -76,8 +97,7 @@ async fn create_build(monitor: &MonitorClient) -> anyhow::Result<()> {
#[allow(unused)]
async fn create_repo(monitor: &MonitorClient) -> anyhow::Result<()> {
let mut res =
monitor.read(read::ListServers::default()).await?;
let mut res = monitor.read(read::ListServers::default()).await?;
let server_id = res.pop().unwrap().id;
let repo = monitor

View File

@@ -321,3 +321,4 @@ impl AddFilters for DeploymentQuerySpecifics {
}
}
}

View File

@@ -53,6 +53,7 @@ pub struct ResourceListItem<Info> {
#[serde(rename = "type")]
pub resource_type: ResourceTargetVariant,
pub name: String,
pub created_at: I64,
pub tags: Vec<String>,
pub info: Info,
}
@@ -86,3 +87,41 @@ impl<T: AddFilters> AddFilters for ResourceQuery<T> {
self.specific.add_filters(filters);
}
}
#[derive(Default)]
pub struct ResourceQueryBuilder<T> {
pub names: Option<Vec<String>>,
pub tags: Option<Vec<String>>,
pub specific: Option<T>,
}
impl<T: Default> ResourceQueryBuilder<T> {
pub fn build(self) -> ResourceQuery<T> {
ResourceQuery {
names: self.names.unwrap_or_default(),
tags: self.tags.unwrap_or_default(),
specific: self.specific.unwrap_or_default(),
}
}
pub fn names(
mut self,
names: impl Into<Vec<String>>,
) -> ResourceQueryBuilder<T> {
self.names = Some(names.into());
self
}
pub fn tags(
mut self,
tags: impl Into<Vec<String>>,
) -> ResourceQueryBuilder<T> {
self.tags = Some(tags.into());
self
}
pub fn specific(mut self, specific: T) -> ResourceQueryBuilder<T> {
self.specific = Some(specific);
self
}
}