Added admin method to agent
This commit is contained in:
parent
9341596265
commit
a11a35b767
9
sql/agent/fetch_all.sql
Normal file
9
sql/agent/fetch_all.sql
Normal file
@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
id,
|
||||
full_name,
|
||||
credential,
|
||||
credential_type as "credential_type: _",
|
||||
time_created,
|
||||
last_updated
|
||||
FROM agent
|
||||
ORDER BY time_created DESC;
|
@ -62,3 +62,9 @@ pub async fn delete_agent(
|
||||
.execute(tx)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn fetch_all(conn: &PgPool) -> Result<Vec<Agent>, sqlx::Error> {
|
||||
sqlx::query_file_as!(Agent, "sql/agent/fetch_all.sql")
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
use jl_types::{domain::{project::Project, project_state::ProjectState}, dto::filters::Filter};
|
||||
use jl_types::{
|
||||
domain::{project::Project, project_state::ProjectState},
|
||||
dto::filters::Filter,
|
||||
};
|
||||
use sqlx::{postgres::PgQueryResult, PgPool, Postgres, Transaction};
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -56,18 +59,24 @@ pub async fn update(
|
||||
project.media as _,
|
||||
project.last_updated,
|
||||
project.id
|
||||
).fetch_one(tx).await
|
||||
)
|
||||
.fetch_one(tx)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_with_id(conn: &PgPool, project_id: &Uuid) -> Result<Option<Project>, sqlx::Error> {
|
||||
sqlx::query_file_as!(Project, "sql/project/get_with_id.sql", project_id).fetch_optional(conn).await
|
||||
sqlx::query_file_as!(Project, "sql/project/get_with_id.sql", project_id)
|
||||
.fetch_optional(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn fetch_by_ids(
|
||||
conn: &PgPool,
|
||||
project_ids: &Vec<Uuid>,
|
||||
) -> Result<Vec<Project>, sqlx::Error> {
|
||||
sqlx::query_file_as!(Project, "sql/project/fetch_by_ids.sql", project_ids).fetch_all(conn).await
|
||||
sqlx::query_file_as!(Project, "sql/project/fetch_by_ids.sql", project_ids)
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn fetch_with_filters_paged(
|
||||
@ -81,23 +90,29 @@ pub async fn fetch_with_filters_paged(
|
||||
let mut project_type_filter = None;
|
||||
let mut project_state_filter = ProjectState::InConstruction;
|
||||
let mut project_condition_filter = None;
|
||||
|
||||
|
||||
for filter in filters {
|
||||
match filter {
|
||||
Filter::InCity(city) => city_filter = Some(city),
|
||||
Filter::InDistrict(district) => district_filter = Some(district),
|
||||
Filter::Finished => project_state_filter = ProjectState::InConstruction,
|
||||
Filter::ByProjectType(project_type) => project_type_filter = Some(project_type),
|
||||
Filter::ByProjectCondition(project_condition) => project_condition_filter = Some(project_condition),
|
||||
Filter::ByProjectCondition(project_condition) => {
|
||||
project_condition_filter = Some(project_condition)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sqlx::query_file_as!(Project, "sql/project/fetch_with_filters_paged.sql",
|
||||
sqlx::query_file_as!(
|
||||
Project,
|
||||
"sql/project/fetch_with_filters_paged.sql",
|
||||
city_filter,
|
||||
district_filter,
|
||||
project_type_filter as _,
|
||||
project_condition_filter as _,
|
||||
project_state_filter as _,
|
||||
offset
|
||||
).fetch_all(conn).await
|
||||
)
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user