chore: fmt

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-27 19:57:16 +02:00
parent 43ed89d0d8
commit 86cfc18076
2 changed files with 51 additions and 24 deletions

View File

@@ -19,7 +19,7 @@ use churn_domain::{Agent, LeaseResp, LogEvent, ServerEnrollReq, ServerMonitorRes
use clap::{Args, Parser, Subcommand, ValueEnum};
use event::EventService;
use lease::LeaseService;
use serde::{Deserialize};
use serde::Deserialize;
use serde_json::json;
use crate::db::Db;
@@ -208,24 +208,33 @@ async fn logs(
}
}
let events = match cursor.cursor {
Some(c) => state.events.get_from_cursor(c).await,
None => state.events.get_from_beginning().await,
}
.map_err(AppError::Internal)?;
match cursor.cursor {
Some(c) => {
let events = state
.events
.get_from_cursor(c)
.await
.map_err(AppError::Internal)?;
if events.is_empty() {
return Ok(Json(ServerMonitorResp {
cursor: cursor.cursor,
logs: Vec::new(),
}));
}
Ok(Json(ServerMonitorResp {
cursor: events.last().map(|e| e.id),
logs: events
.iter()
.map(|e| format!("{}: {}", e.author, e.content))
.collect(),
}))
}
None => {
let cursor = state
.events
.get_latest_cursor()
.await
.map_err(AppError::Internal)?;
Ok(Json(ServerMonitorResp {
cursor: events.last().map(|e| e.id),
logs: events
.iter()
.map(|e| format!("{}: {}", e.author, e.content))
.collect(),
}))
return Ok(Json(ServerMonitorResp {
cursor: Some(cursor),
logs: Vec::new(),
}));
}
}
}