Add total upstream count retrieval to UpstreamService
All checks were successful
Test / lint-frontend (pull_request) Successful in 28s
Test / test-frontend (pull_request) Successful in 27s
Test / frontend-build (pull_request) Successful in 30s
Verify / verify-generated-database-code (pull_request) Successful in 1m7s
Verify / verify-generated-agent-code (pull_request) Successful in 1m9s
Verify / verify-openapi-spec (pull_request) Successful in 1m8s
Verify / verify-frontend-api-client (pull_request) Successful in 20s
Test / test-crates (pull_request) Successful in 1m1s
Test / lint-crates (pull_request) Successful in 1m8s
All checks were successful
Test / lint-frontend (pull_request) Successful in 28s
Test / test-frontend (pull_request) Successful in 27s
Test / frontend-build (pull_request) Successful in 30s
Verify / verify-generated-database-code (pull_request) Successful in 1m7s
Verify / verify-generated-agent-code (pull_request) Successful in 1m9s
Verify / verify-openapi-spec (pull_request) Successful in 1m8s
Verify / verify-frontend-api-client (pull_request) Successful in 20s
Test / test-crates (pull_request) Successful in 1m1s
Test / lint-crates (pull_request) Successful in 1m8s
This commit is contained in:
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, ColumnTrait, DatabaseConnection, DatabaseTransaction, EntityTrait, ExprTrait,
|
||||
ModelTrait, QueryFilter, QuerySelect, QueryTrait, TransactionTrait,
|
||||
FromQueryResult, ModelTrait, QueryFilter, QuerySelect, QueryTrait, TransactionTrait,
|
||||
};
|
||||
|
||||
use database::generated::entities::{upstream, upstream_target};
|
||||
@@ -29,6 +29,11 @@ pub trait UpstreamService: Send + Sync {
|
||||
create_info: UpstreamCreateInfo,
|
||||
tx: Option<&mut DatabaseTransaction>,
|
||||
) -> Result<UpstreamInfo, ServiceError>;
|
||||
async fn get_total_upstreams(
|
||||
&self,
|
||||
options: Option<UpstreamTotalCountOptions>,
|
||||
tx: Option<&mut DatabaseTransaction>,
|
||||
) -> Result<u64, ServiceError>;
|
||||
async fn get_upstream(
|
||||
&self,
|
||||
upstream_id: uuid::Uuid,
|
||||
@@ -97,6 +102,9 @@ pub struct GetUpstreamOptions {
|
||||
pub filter_by_enabled: bool,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct UpstreamTotalCountOptions {}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GetUpstreamTargetOptions {
|
||||
pub include_upstream: bool,
|
||||
@@ -152,6 +160,27 @@ impl UpstreamService for UpstreamServiceImpl {
|
||||
Ok(r.into())
|
||||
}
|
||||
|
||||
async fn get_total_upstreams(
|
||||
&self,
|
||||
_options: Option<UpstreamTotalCountOptions>,
|
||||
tx: Option<&mut DatabaseTransaction>,
|
||||
) -> Result<u64, ServiceError> {
|
||||
#[derive(Debug, FromQueryResult)]
|
||||
struct CountResult {
|
||||
// The field name must match the column alias in the query
|
||||
count: i64,
|
||||
}
|
||||
let count_info = with_conn!(&*self.connection, tx, conn, {
|
||||
upstream::Entity::find()
|
||||
.select_only()
|
||||
.column_as(upstream::Column::Id, "count")
|
||||
.into_model::<CountResult>()
|
||||
.one(*conn)
|
||||
.await?
|
||||
});
|
||||
Ok(count_info.map_or(0, |c| c.count) as u64)
|
||||
}
|
||||
|
||||
async fn get_upstream(
|
||||
&self,
|
||||
upstream_id: uuid::Uuid,
|
||||
|
||||
Reference in New Issue
Block a user