improving get method and its test

This commit is contained in:
filipriec
2025-02-24 20:27:18 +01:00
parent 7e45daff10
commit 7a98bcd72e
4 changed files with 34 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/GetAdresar
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{
"id": "1",
"firma": "Updated Firma",
@@ -17,7 +17,7 @@
"skladu": "Updated Skladu",
"fax": "Updated Fax"
}
grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.Adresar/GetAdresar
grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{
"id": "2",
"firma": "asdfasf",
@@ -36,15 +36,15 @@
"skladu": "f",
"fax": " "
}
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/DeleteAdresar
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/DeleteAdresar
{
"success": true
}
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/GetAdresar
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
ERROR:
Code: NotFound
Message: no rows returned by a query that expected to return at least one row
grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.Adresar/GetAdresar
grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{
"id": "2",
"firma": "asdfasf",
@@ -80,7 +80,7 @@ ERROR:
"telefon": "New Telefon",
"skladu": "New Skladu",
"fax": "New Fax"
}' localhost:50051 multieko2.Adresar/PostAdresar
}' localhost:50051 multieko2.adresar.Adresar/PostAdresar
{
"id": "43",
"firma": "New Firma",
@@ -116,7 +116,7 @@ ERROR:
"telefon": "Updated Telefon",
"skladu": "Updated Skladu",
"fax": "Updated Fax"
}' localhost:50051 multieko2.Adresar/PutAdresar
}' localhost:50051 multieko2.adresar.Adresar/PutAdresar
{
"id": "43",
"firma": "Updated Firma",
@@ -135,7 +135,7 @@ ERROR:
"skladu": "Updated Skladu",
"fax": "Updated Fax"
}
grpcurl -plaintext -d '{"id": 43}' localhost:50051 multieko2.Adresar/GetAdresar
grpcurl -plaintext -d '{"id": 43}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{
"id": "43",
"firma": "Updated Firma",

View File

@@ -1,31 +1,27 @@
# TOTAL items in the adresar
grpcurl -plaintext localhost:50051 multieko2.Adresar/GetAdresarCount
{
"count": "43"
}
# Item at this count. If there are 43 items, number 1 is the first item
grpcurl -plaintext -d '{"position": 1}' localhost:50051 multieko2.Adresar/GetAdresarByPosition
# TOTAL items in the adresar
grpcurl -plaintext localhost:50051 multieko2.adresar.Adresar/GetAdresarCount
{
"id": "2",
"firma": "asdfasf",
"kz": " ",
"drc": " ",
"ulica": " ",
"psc": "sdfasdf",
"count": "5"
}
# Item at this count. If there are 43 items, number 1 is the first item
grpcurl -plaintext -d '{"position": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresarByPosition
{
"id": "1",
"firma": "ks555",
"kz": "f",
"drc": "asdf",
"ulica": "as",
"psc": "f",
"mesto": "asf",
"stat": "as",
"banka": "df",
"ucet": "asf",
"skladm": "f",
"ico": "f",
"kontakt": "f",
"telefon": "f",
"skladu": "f",
"fax": " "
"banka": "fa",
"telefon": "a",
"skladu": "fd",
"fax": "asf"
}
# Item fetched by id. The first item was created and removed, therefore number 1 in ids doenst exists, since first to exist now has number 2
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/GetAdresar
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
ERROR:
Code: NotFound
Message: no rows returned by a query that expected to return at least one row

View File

@@ -30,13 +30,16 @@ pub async fn get_adresar(
skladu,
fax
FROM adresar
WHERE id = $1
WHERE id = $1 AND deleted = false
"#,
request.id
)
.fetch_one(db_pool)
.await
.map_err(|e| Status::not_found(e.to_string()))?;
.map_err(|e| match e {
sqlx::Error::RowNotFound => Status::not_found("Record not found"),
_ => Status::internal(format!("Database error: {}", e)),
})?;
Ok(AdresarResponse {
id: adresar.id,

View File

@@ -157,11 +157,10 @@ async fn test_get_deleted_record(
) {
let (pool, id) = existing_deleted_record.await;
let request = GetAdresarRequest { id };
let response = get_adresar(&pool, request).await.unwrap();
let result = get_adresar(&pool, request).await;
assert_eq!(response.firma, "Deleted Company");
assert_eq!(response.kz, "");
assert_eq!(response.drc, "");
assert!(result.is_err());
assert_eq!(result.unwrap_err().code(), tonic::Code::NotFound);
}
#[rstest]