diff --git a/server/src/adresar/docs/example.txt b/server/src/adresar/docs/example.txt index 60c4797..8fff83f 100644 --- a/server/src/adresar/docs/example.txt +++ b/server/src/adresar/docs/example.txt @@ -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", diff --git a/server/src/adresar/docs/get_example.txt b/server/src/adresar/docs/get_example.txt index 5093a47..46df272 100644 --- a/server/src/adresar/docs/get_example.txt +++ b/server/src/adresar/docs/get_example.txt @@ -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 diff --git a/server/src/adresar/handlers/get_adresar.rs b/server/src/adresar/handlers/get_adresar.rs index ed9bddd..67195f7 100644 --- a/server/src/adresar/handlers/get_adresar.rs +++ b/server/src/adresar/handlers/get_adresar.rs @@ -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, diff --git a/server/tests/adresar/get_adresar_test.rs b/server/tests/adresar/get_adresar_test.rs index 4ba7b93..6fdec08 100644 --- a/server/tests/adresar/get_adresar_test.rs +++ b/server/tests/adresar/get_adresar_test.rs @@ -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]