complete redesign
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// src/uctovnictvo/handlers/get_uctovnictvo_by_position.rs
|
||||
use tonic::Status;
|
||||
use sqlx::PgPool;
|
||||
use common::proto::multieko2::common::PositionRequest;
|
||||
use super::get_uctovnictvo;
|
||||
|
||||
pub async fn get_uctovnictvo_by_position(
|
||||
db_pool: &PgPool,
|
||||
request: PositionRequest,
|
||||
) -> Result<common::proto::multieko2::uctovnictvo::UctovnictvoResponse, Status> {
|
||||
if request.position < 1 {
|
||||
return Err(Status::invalid_argument("Position must be at least 1"));
|
||||
}
|
||||
|
||||
// Find the ID of the Nth non-deleted record
|
||||
let id: i64 = sqlx::query_scalar!(
|
||||
r#"
|
||||
SELECT id
|
||||
FROM uctovnictvo
|
||||
WHERE deleted = FALSE
|
||||
ORDER BY id ASC
|
||||
OFFSET $1
|
||||
LIMIT 1
|
||||
"#,
|
||||
request.position - 1
|
||||
)
|
||||
.fetch_optional(db_pool)
|
||||
.await
|
||||
.map_err(|e| Status::internal(e.to_string()))?
|
||||
.ok_or_else(|| Status::not_found("Position out of bounds"))?;
|
||||
|
||||
// Now fetch the complete record using the existing get_uctovnictvo function
|
||||
get_uctovnictvo(db_pool, common::proto::multieko2::uctovnictvo::GetUctovnictvoRequest { id }).await
|
||||
}
|
||||
Reference in New Issue
Block a user