working perfectly well now

This commit is contained in:
filipriec
2025-02-21 14:58:52 +01:00
parent 7771299c81
commit 03e41eda9d
8 changed files with 82 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
// src/adresar/handlers/get_by_position.rs
// src/adresar/handlers/get_adresar_by_position.rs
use tonic::{Status};
use sqlx::PgPool;
use crate::proto::multieko2::{PositionRequest, AdresarResponse, GetAdresarRequest};
@@ -11,16 +11,24 @@ pub async fn get_adresar_by_position(
if request.position < 1 {
return Err(Status::invalid_argument("Position must be at least 1"));
}
let offset = request.position - 1;
// Find the ID of the Nth non-deleted record
let id: i64 = sqlx::query_scalar!(
"SELECT id FROM adresar ORDER BY id ASC OFFSET $1 LIMIT 1",
offset
r#"
SELECT id
FROM adresar
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_adresar function
get_adresar(db_pool, GetAdresarRequest { id }).await
}