working perfectly well now
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user