Skip to content

Commit

Permalink
Merge pull request #17 from SachinAkash01/main
Browse files Browse the repository at this point in the history
Refactor Ballerina Service Endpoints
  • Loading branch information
SachinAkash01 authored May 1, 2024
2 parents aea82db + 2c91c90 commit c7d4a5a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
19 changes: 8 additions & 11 deletions GramaNiladhariCertificateService/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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<json> 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? {

Expand Down Expand Up @@ -217,15 +225,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<json> queryString = {"$set": {"status": "rejected"}};
// map<json> filter = {"id": id};

// int|error resultData = check mongoClient->update(queryString, "requests", filter = filter);

// return resultData;
// }

}
19 changes: 8 additions & 11 deletions PoliceCertificateService/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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<json> 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? {

Expand Down Expand Up @@ -211,15 +219,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<json> queryString = {"$set": {"status": "rejected"}};
// map<json> filter = {"id": id};

// int|error resultData = check mongoClient->update(queryString, "requests", filter = filter);

// return resultData;
// }

}
31 changes: 20 additions & 11 deletions PoliceCheckService/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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<json> filter_query = {"NIC": NIC};
stream<PoliceEntry, error?> policeEntry = checkpanic mongoClient->find(collectionName = "police", filter = filter_query, 'limit = 1);
boolean valid = false;
map<json> queryString = {"NIC": NIC};
stream<PoliceEntry, error?> 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;
}
}

Expand Down

0 comments on commit c7d4a5a

Please sign in to comment.