-
-
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 namespace services with file separation
- Loading branch information
Showing
7 changed files
with
249 additions
and
207 deletions.
There are no files selected for viewing
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::{NamespaceDb, SystemState}, | ||
repositories::generic::*, | ||
utils, | ||
}; | ||
|
||
/// Count namespaces | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
get, | ||
tag = "Namespaces", | ||
path = "/namespaces/count", | ||
params( | ||
("filter" = Option<String>, Query, description = "Generic filter", example = "{ \"filter\": { \"where\": { \"name\": { \"eq\": \"global\" } } } }"), | ||
), | ||
responses( | ||
(status = 200, description = "Count result", body = GenericCount), | ||
), | ||
))] | ||
#[web::get("/namespaces/count")] | ||
pub async fn count_namespace( | ||
state: web::types::State<SystemState>, | ||
qs: web::types::Query<GenericListQuery>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let filter = utils::query_string::parse_qs_filter(&qs)?; | ||
let count = NamespaceDb::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 nanocl_stubs::namespace::NamespacePartial; | ||
|
||
use crate::{ | ||
models::{NamespaceDb, SystemState}, | ||
objects::generic::*, | ||
}; | ||
|
||
/// Create a new namespace | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
post, | ||
request_body = NamespacePartial, | ||
tag = "Namespaces", | ||
path = "/namespaces", | ||
responses( | ||
(status = 200, description = "The created namespace", body = Namespace), | ||
(status = 409, description = "Namespace already exist", body = ApiError), | ||
), | ||
))] | ||
#[web::post("/namespaces")] | ||
pub async fn create_namespace( | ||
state: web::types::State<SystemState>, | ||
payload: web::types::Json<NamespacePartial>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let item = NamespaceDb::create_obj(&payload, &state).await?; | ||
Ok(web::HttpResponse::Created().json(&item)) | ||
} |
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,30 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
|
||
use crate::{ | ||
models::{NamespaceDb, SystemState}, | ||
objects::generic::*, | ||
}; | ||
|
||
/// Delete a namespace | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
delete, | ||
tag = "Namespaces", | ||
path = "/namespaces/{name}", | ||
params( | ||
("name" = String, Path, description = "Name of the namespace to delete") | ||
), | ||
responses( | ||
(status = 202, description = "Namespace have been deleted"), | ||
(status = 404, description = "Namespace is not existing", body = ApiError), | ||
), | ||
))] | ||
#[web::delete("/namespaces/{name}")] | ||
pub async fn delete_namespace( | ||
state: web::types::State<SystemState>, | ||
path: web::types::Path<(String, String)>, | ||
) -> HttpResult<web::HttpResponse> { | ||
NamespaceDb::del_obj_by_pk(&path.1, &(), &state).await?; | ||
Ok(web::HttpResponse::Accepted().into()) | ||
} |
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,30 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
|
||
use crate::{ | ||
models::{NamespaceDb, SystemState}, | ||
objects::generic::*, | ||
}; | ||
|
||
/// Get detailed information about a namespace | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
get, | ||
tag = "Namespaces", | ||
path = "/namespaces/{name}/inspect", | ||
params( | ||
("name" = String, Path, description = "The namespace name to inspect") | ||
), | ||
responses( | ||
(status = 200, description = "Detailed information about a namespace", body = [NamespaceInspect]), | ||
(status = 404, description = "Namespace is not existing", body = ApiError), | ||
), | ||
))] | ||
#[web::get("/namespaces/{name}/inspect")] | ||
pub async fn inspect_namespace( | ||
state: web::types::State<SystemState>, | ||
path: web::types::Path<(String, String)>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let namespace = NamespaceDb::inspect_obj_by_pk(&path.1, &state).await?; | ||
Ok(web::HttpResponse::Ok().json(&namespace)) | ||
} |
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,31 @@ | ||
use ntex::web; | ||
|
||
use nanocl_error::http::HttpResult; | ||
use nanocl_stubs::generic::GenericListQuery; | ||
|
||
use crate::{ | ||
models::{NamespaceDb, SystemState}, | ||
utils, | ||
}; | ||
|
||
/// List namespaces with optional filter | ||
#[cfg_attr(feature = "dev", utoipa::path( | ||
get, | ||
tag = "Namespaces", | ||
path = "/namespaces", | ||
params( | ||
("filter" = Option<String>, Query, description = "Generic filter", example = "{ \"filter\": { \"where\": { \"name\": { \"eq\": \"test\" } } } }"), | ||
), | ||
responses( | ||
(status = 200, description = "List of namespace", body = [NamespaceSummary]), | ||
), | ||
))] | ||
#[web::get("/namespaces")] | ||
pub async fn list_namespace( | ||
state: web::types::State<SystemState>, | ||
qs: web::types::Query<GenericListQuery>, | ||
) -> HttpResult<web::HttpResponse> { | ||
let filter = utils::query_string::parse_qs_filter(&qs)?; | ||
let items = NamespaceDb::list(&filter, &state).await?; | ||
Ok(web::HttpResponse::Ok().json(&items)) | ||
} |
Oops, something went wrong.