From 343d1f4ccc572081963dbcef2cb7cc81c09459e2 Mon Sep 17 00:00:00 2001 From: "K.D.S. Akash" Date: Wed, 1 May 2024 16:50:56 +0530 Subject: [PATCH 1/3] Fix bugs in police check API --- PoliceCheckService/service.bal | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/PoliceCheckService/service.bal b/PoliceCheckService/service.bal index 09ada8a..2b48950 100644 --- a/PoliceCheckService/service.bal +++ b/PoliceCheckService/service.bal @@ -26,25 +26,34 @@ service / on new http:Listener(5050) { // Check if the NIC matches the pattern boolean isValidNIC = regex:matches(NIC, nicPattern); - string criminalStatus = ""; + // string criminalStatus = ""; if isValidNIC { - map filter_query = {"NIC": NIC}; - stream policeEntry = checkpanic mongoClient->find(collectionName = "police", filter = filter_query, 'limit = 1); + boolean valid = false; + map queryString = {"NIC": NIC}; + stream resultData = check mongoClient->find(collectionName = "police", filter = (queryString)); + + check resultData.forEach(function(PoliceEntry datas) { + + valid = true; - check policeEntry.forEach(function(PoliceEntry entry) { - criminalStatus = entry.criminalstatus; }); - if criminalStatus is "" { - criminalStatus = "clear"; - } + return valid; + // criminalStatus = entry.criminalstatus; + // }); + + // if criminalStatus is "" { + // criminalStatus = "clear"; + // } } else { - return false; + return { + body: { + errmsg: string `Invalid NIC: ${NIC}` + } + }; } - - return true; } } From 8709d5d3f3cc928b498b1d3725f9449cba1e676a Mon Sep 17 00:00:00 2001 From: "K.D.S. Akash" Date: Wed, 1 May 2024 16:56:32 +0530 Subject: [PATCH 2/3] Refactor code in Ballerina APIs --- GramaNiladhariCertificateService/service.bal | 11 ----------- PoliceCertificateService/service.bal | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/GramaNiladhariCertificateService/service.bal b/GramaNiladhariCertificateService/service.bal index bc907ef..a9b12bd 100644 --- a/GramaNiladhariCertificateService/service.bal +++ b/GramaNiladhariCertificateService/service.bal @@ -217,15 +217,4 @@ service / on new http:Listener(8080) { return resultData; } - - //Updating user request status to rejected - // resource function post statusReject/[string id]() returns int|error { - // map queryString = {"$set": {"status": "rejected"}}; - // map filter = {"id": id}; - - // int|error resultData = check mongoClient->update(queryString, "requests", filter = filter); - - // return resultData; - // } - } diff --git a/PoliceCertificateService/service.bal b/PoliceCertificateService/service.bal index 4082b5e..1e95458 100644 --- a/PoliceCertificateService/service.bal +++ b/PoliceCertificateService/service.bal @@ -211,15 +211,4 @@ service / on new http:Listener(4040) { return resultData; } - - //Updating user request status to rejected - // resource function post statusReject/[string id]() returns int|error { - // map queryString = {"$set": {"status": "rejected"}}; - // map filter = {"id": id}; - - // int|error resultData = check mongoClient->update(queryString, "requests", filter = filter); - - // return resultData; - // } - } From 2c91c90951c7280f3c6c378fe300e9545c610568 Mon Sep 17 00:00:00 2001 From: "K.D.S. Akash" Date: Wed, 1 May 2024 18:03:11 +0530 Subject: [PATCH 3/3] Add delete methods for grama niladhari and police APIs --- GramaNiladhariCertificateService/service.bal | 8 ++++++++ PoliceCertificateService/service.bal | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/GramaNiladhariCertificateService/service.bal b/GramaNiladhariCertificateService/service.bal index a9b12bd..1f2bf26 100644 --- a/GramaNiladhariCertificateService/service.bal +++ b/GramaNiladhariCertificateService/service.bal @@ -127,6 +127,14 @@ service / on new http:Listener(8080) { return allData; } + //Delete user request from the database using UUID + resource function delete deleteRequest/[string uuid]() returns int|error? { + map queryString = {"id": uuid}; + int|error? resultData = check mongoClient->delete(collectionName = "requests", filter = (queryString)); + + return resultData; + } + //Get a specific record (this is for search function which will be implemented in the future) resource function get getReqRecord/[string id]() returns requestData[]|error? { diff --git a/PoliceCertificateService/service.bal b/PoliceCertificateService/service.bal index 1e95458..cae9428 100644 --- a/PoliceCertificateService/service.bal +++ b/PoliceCertificateService/service.bal @@ -121,6 +121,14 @@ service / on new http:Listener(4040) { return allData; } + //Delete user request from the database using UUID + resource function delete deleteRequest/[string uuid]() returns int|error? { + map queryString = {"id": uuid}; + int|error? resultData = check mongoClient->delete(collectionName = "policeRequests", filter = (queryString)); + + return resultData; + } + //Get a specific record (this is for search function which will be implemented in the future) resource function get getReqRecord/[string id]() returns requestData[]|error? {