-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor/nanocld: cleaner event services with file separation
- Loading branch information
Showing
7 changed files
with
234 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
use nanocl_stubs::generic::{GenericCount, GenericListQuery}; | ||
|
||
use crate::{ | ||
models::{EventDb, SystemState}, | ||
repositories::generic::*, | ||
utils, | ||
}; | ||
|
||
/// Count events | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
get, | ||
tag = "Events", | ||
path = "/events/count", | ||
params( | ||
("filter" = Option<String>, Query, description = "Generic filter", example = "{ \"filter\": { \"where\": { \"kind\": { \"eq\": \"CPU\" } } } }"), | ||
), | ||
responses( | ||
(status = 200, description = "Count result", body = GenericCount), | ||
), | ||
))] | ||
#[web::get("/events/count")] | ||
pub async fn count_event( | ||
state: web::types::State<SystemState>, | ||
qs: web::types::Query<GenericListQuery>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let filter = utils::query_string::parse_qs_filter(&qs)?; | ||
let count = EventDb::count_by(&filter, &state.inner.pool).await?; | ||
Ok(web::HttpResponse::Ok().json(&GenericCount { count })) | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
|
||
use crate::{ | ||
models::{EventDb, SystemState}, | ||
repositories::generic::*, | ||
}; | ||
|
||
/// Get detailed information about an event | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
get, | ||
tag = "Events", | ||
path = "/events/{key}/inspect", | ||
params( | ||
("key" = String, Path, description = "Key of the event"), | ||
), | ||
responses( | ||
(status = 200, description = "Detailed information about the event", body = Event), | ||
), | ||
))] | ||
#[web::get("/events/{key}/inspect")] | ||
pub async fn inspect_event( | ||
state: web::types::State<SystemState>, | ||
path: web::types::Path<(String, String)>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let event = EventDb::transform_read_by_pk(&path.1, &state.inner.pool).await?; | ||
Ok(web::HttpResponse::Ok().json(&event)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
use nanocl_stubs::generic::GenericListQuery; | ||
|
||
use crate::{ | ||
models::{EventDb, SystemState}, | ||
repositories::generic::*, | ||
utils, | ||
}; | ||
|
||
/// List events with optional filter | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
get, | ||
tag = "Events", | ||
path = "/events", | ||
params( | ||
("filter" = Option<String>, Query, description = "Generic filter", example = "{ \"filter\": { \"where\": { \"kind\": { \"eq\": \"normal\" } } } }"), | ||
), | ||
responses( | ||
(status = 200, description = "List of events", body = Vec<Event>), | ||
), | ||
))] | ||
#[web::get("/events")] | ||
pub async fn list_event( | ||
state: web::types::State<SystemState>, | ||
qs: web::types::Query<GenericListQuery>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let filter = utils::query_string::parse_qs_filter(&qs)?; | ||
let events = EventDb::transform_read_by(&filter, &state.inner.pool).await?; | ||
Ok(web::HttpResponse::Ok().json(&events)) | ||
} |
Oops, something went wrong.