Skip to content

Commit

Permalink
Merge pull request #466 from avinyafoundation/main
Browse files Browse the repository at this point in the history
bug fixed in avinya type of student update
  • Loading branch information
YujithIsura authored Jan 6, 2025
2 parents b837c4f + da38831 commit 3a0fc0a
Show file tree
Hide file tree
Showing 20 changed files with 1,686 additions and 193 deletions.
12 changes: 10 additions & 2 deletions campus/bffs/enrollment/api/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ dependencies = [
{org = "ballerina", name = "graphql"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerinai", name = "observe"}
]
Expand Down Expand Up @@ -108,7 +110,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.10.17"
version = "2.10.19"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down Expand Up @@ -185,6 +187,9 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]
modules = [
{org = "ballerina", packageName = "lang.array", moduleName = "lang.array"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -274,6 +279,9 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.int"}
]
modules = [
{org = "ballerina", packageName = "mime", moduleName = "mime"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -357,7 +365,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "websocket"
version = "2.10.2"
version = "2.10.3"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "constraint"},
Expand Down
11 changes: 9 additions & 2 deletions campus/bffs/enrollment/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ public isolated client class GraphqlClient {
return <GetPersonsResponse>check performDataBinding(graphqlResponse, GetPersonsResponse);
}
remote isolated function getPersonById(int id) returns GetPersonByIdResponse|graphql:ClientError {
string query = string `query getPersonById($id:Int!) {person_by_id(id:$id) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email mailing_address {city {id name {name_en name_si name_ta} district {id name {name_en}}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
string query = string `query getPersonById($id:Int!) {person_by_id(id:$id) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email mailing_address {city {id name {name_en name_si name_ta} district {id name {name_en}}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job document_list {document document_type}}}`;
map<anydata> variables = {"id": id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetPersonByIdResponse>check performDataBinding(graphqlResponse, GetPersonByIdResponse);
}

remote isolated function updatePerson(Person person, City? permanent_address_city = (), Address? mailing_address = (), Address? permanent_address = (), City? mailing_address_city = ()) returns UpdatePersonResponse|graphql:ClientError {
string query = string `mutation updatePerson($person:Person!,$permanent_address:Address,$permanent_address_city:City,$mailing_address:Address,$mailing_address_city:City) {update_person(person:$person,permanent_address:$permanent_address,permanent_address_city:$permanent_address_city,mailing_address:$mailing_address,mailing_address_city:$mailing_address_city) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
map<anydata> variables = {"permanent_address_city": permanent_address_city, "mailing_address": mailing_address, "person": person, "permanent_address": permanent_address, "mailing_address_city": mailing_address_city};
Expand All @@ -65,9 +66,15 @@ public isolated client class GraphqlClient {
return <GetAllOrganizationsResponse>check performDataBinding(graphqlResponse, GetAllOrganizationsResponse);
}
remote isolated function insertPerson(Person person, Address? mailing_address = (), City? mailing_address_city = ()) returns InsertPersonResponse|graphql:ClientError {
string query = string `mutation insertPerson($person:Person!,$mailing_address:Address,$mailing_address_city:City) {insert_person(person:$person,mailing_address:$mailing_address,mailing_address_city:$mailing_address_city) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job}}`;
string query = string `mutation insertPerson($person:Person!,$mailing_address:Address,$mailing_address_city:City) {insert_person(person:$person,mailing_address:$mailing_address,mailing_address_city:$mailing_address_city) {id preferred_name full_name date_of_birth sex asgardeo_id jwt_sub_id created updated jwt_email permanent_address {city {id name {name_en name_si name_ta}} street_address phone id} mailing_address {city {id name {name_en name_si name_ta}} street_address phone id} phone organization {id description notes address {id} avinya_type {id name} name {name_en} parent_organizations {id name {name_en}}} avinya_type_id notes nic_no passport_no id_no email street_address digital_id avinya_phone bank_name bank_account_number bank_account_name academy_org_id bank_branch created_by updated_by current_job documents_id}}`;
map<anydata> variables = {"mailing_address": mailing_address, "person": person, "mailing_address_city": mailing_address_city};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <InsertPersonResponse>check performDataBinding(graphqlResponse, InsertPersonResponse);
}
remote isolated function uploadDocument(UserDocument user_document) returns UploadDocumentResponse|graphql:ClientError {
string query = string `mutation uploadDocument($user_document:UserDocument!) {upload_document(user_document:$user_document) {id folder_id nic_front_id nic_back_id birth_certificate_front_id birth_certificate_back_id ol_certificate_id al_certificate_id additional_certificate_01_id additional_certificate_02_id additional_certificate_03_id additional_certificate_04_id additional_certificate_05_id}}`;
map<anydata> variables = {"user_document": user_document};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <UploadDocumentResponse>check performDataBinding(graphqlResponse, UploadDocumentResponse);
}
}
168 changes: 161 additions & 7 deletions campus/bffs/enrollment/api/service.bal
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import ballerina/graphql;
import ballerina/http;
import ballerina/io;
import ballerina/lang.array;
import ballerina/log;
import ballerina/mime;

public function initClientConfig() returns ConnectionConfig {
ConnectionConfig _clientConig = {};
Expand Down Expand Up @@ -155,11 +158,11 @@ service / on new http:Listener(9095) {
City? permanent_address_city = permanent_address?.city;
City? mailing_address_city = mailing_address?.city;

if(permanent_address is Address){
if (permanent_address is Address) {
permanent_address.city = ();
}

if(mailing_address is Address){
if (mailing_address is Address) {
mailing_address.city = ();
}

Expand All @@ -183,7 +186,7 @@ service / on new http:Listener(9095) {
}
}

resource function post add_person(@http:Payload Person person) returns Person|error {
resource function post add_person(@http:Payload Person person) returns Person|ErrorDetail|error {

Address? mailing_address = person?.mailing_address;
City? mailing_address_city = mailing_address?.city;
Expand All @@ -201,13 +204,164 @@ service / on new http:Listener(9095) {
return person_record;
} else {
log:printError("Error while processing Application record received", person_record);
return error("Error while processing Application record received: " + person_record.message() +
":: Detail: " + person_record.detail().toString());
return {
"message": person_record.message().toString(),
"errorCode": "500"
};
}
} else {
log:printError("Error while creating application", addPersonResponse);
return error("Error while creating application: " + addPersonResponse.message() +
":: Detail: " + addPersonResponse.detail().toString());
return {
"message": addPersonResponse.message().toString(),
"errorCode": "500"
};
}
}
resource function post upload_document(http:Request req) returns UserDocument|ErrorDetail|error {

UserDocument document = {};
UserDocument document_details = {};
int document_row_id = 0;
string document_type = "";

if (req.getContentType().startsWith("multipart/form-data")) {

mime:Entity[] bodyParts = check req.getBodyParts();
string base64EncodedStringDocument = "";

foreach var part in bodyParts {
mime:ContentDisposition contentDisposition = part.getContentDisposition();

if (contentDisposition.name == "document_details") {

json document_details_in_json = check part.getJson();
document_details = check document_details_in_json.cloneWithType(UserDocument);
document_row_id = document_details?.id ?: 0;
document_type = document_details?.document_type ?: "";

} else if (contentDisposition.name == "document") {

stream<byte[], io:Error?>|mime:ParserError str = part.getByteStream();

if str is stream<byte[], io:Error?> {

byte[] allBytes = []; // Initialize an empty byte array

// Iterate through the stream and collect all chunks
error? e = str.forEach(function(byte[] chunk) {
array:push(allBytes, ...chunk); // Efficiently append all bytes from chunk
});

byte[] base64EncodedDocument = <byte[]>(check mime:base64Encode(allBytes));
base64EncodedStringDocument = check string:fromBytes(base64EncodedDocument);

}
}

}

document = {
id: document_row_id,
document_type: document_type,
document: base64EncodedStringDocument
};

}

UploadDocumentResponse|graphql:ClientError uploadDocumentResponse = globalDataClient->uploadDocument(document);
if (uploadDocumentResponse is UploadDocumentResponse) {
UserDocument|error document_record = uploadDocumentResponse.upload_document.cloneWithType(UserDocument);
if (document_record is UserDocument) {
return document_record;
} else {
log:printError("Error while processing Application record received", document_record);
return {
"message": document_record.message().toString(),
"errorCode": "500"
};
}
} else {
log:printError("Error while creating application", uploadDocumentResponse);
return {
"message": uploadDocumentResponse.message().toString(),
"errorCode": "500"
};
}
}
// resource function post add_person(http:Request req) returns Person|error {
// UserDocumentList[] documents = [];
// Person person = {};
// Address? mailing_address = {};
// City? mailing_address_city = {};

// if (req.getContentType().startsWith("multipart/form-data")) {
// mime:Entity[] bodyParts = check req.getBodyParts();

// foreach var part in bodyParts {
// mime:ContentDisposition contentDisposition = part.getContentDisposition();

// if (contentDisposition.name == "person") {
// // Extract JSON string and convert to Person record
// json personJson = check part.getJson();
// person = check personJson.cloneWithType(Person);
// mailing_address = person?.mailing_address;
// mailing_address_city = mailing_address?.city;

// if (mailing_address is Address) {
// mailing_address.city = ();
// }

// person.mailing_address = ();

// } else if (contentDisposition.name == "documents") {

// // Get the filename from Content-Disposition
// string? documentName = contentDisposition.fileName;

// stream<byte[], io:Error?>|mime:ParserError str = part.getByteStream();

// //Extract file name without extension
// string:RegExp r = re `\.`;
// string[] split_document_name = r.split(documentName ?: "");

// if str is stream<byte[], io:Error?> {

// byte[] allBytes = []; // Initialize an empty byte array

// // Iterate through the stream and collect all chunks
// error? e = str.forEach(function(byte[] chunk) {
// array:push(allBytes, ...chunk); // Efficiently append all bytes from chunk
// });

// byte[] base64EncodedDocument = <byte[]>(check mime:base64Encode(allBytes));
// string base64EncodedStringDocument = check string:fromBytes(base64EncodedDocument);

// UserDocumentList document = {
// document_name: split_document_name[0],
// document: base64EncodedStringDocument

// };
// //io:println(document);
// documents.push(document);
// }
// }

// }
// }
// InsertPersonResponse|graphql:ClientError addPersonResponse = globalDataClient->insertPerson(documents, person, mailing_address, mailing_address_city);
// if (addPersonResponse is InsertPersonResponse) {
// Person|error person_record = addPersonResponse.insert_person.cloneWithType(Person);
// if (person_record is Person) {
// return person_record;
// } else {
// log:printError("Error while processing Application record received", person_record);
// return error("Error while processing Application record received: " + person_record.message() +
// ":: Detail: " + person_record.detail().toString());
// }
// } else {
// log:printError("Error while creating application", addPersonResponse);
// return error("Error while creating application: " + addPersonResponse.message() +
// ":: Detail: " + addPersonResponse.detail().toString());
// }
// }
}
49 changes: 49 additions & 0 deletions campus/bffs/enrollment/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,42 @@ public type Person record {
string? full_name?;
string? nic_no?;
int? phone?;
UserDocument[]? documentList?;
int? organization_id?;
int? updated_by?;
string? academy_org_name?;
string? asgardeo_id?;
int? documents_id?;
string? updated?;
string? preferred_name?;
string? jwt_sub_id?;
int? academy_org_id?;
};

public type UserDocument record {
string? birth_certificate_back_id?;
string? additional_certificate_01_id?;
string? additional_certificate_02_id?;
string? nic_back_id?;
string? document?;
string? additional_certificate_05_id?;
string? additional_certificate_04_id?;
string? additional_certificate_03_id?;
string? record_type?;
string? al_certificate_id?;
string? nic_front_id?;
string? ol_certificate_id?;
string? birth_certificate_front_id?;
int? id?;
string? folder_id?;
string? document_type?;
};

public type ErrorDetail record {
string message;
int errorCode;
};

public type GetPersonsResponse record {|
map<json?> __extensions?;
record {|
Expand Down Expand Up @@ -267,6 +293,10 @@ public type GetPersonByIdResponse record {|
int? created_by;
int? updated_by;
string? current_job;
record {|
string? document;
string? document_type;
|}[]? document_list;
|}? person_by_id;
|};

Expand Down Expand Up @@ -488,5 +518,24 @@ public type InsertPersonResponse record {|
int? created_by;
int? updated_by;
string? current_job;
int? documents_id;
|}? insert_person;
|};
public type UploadDocumentResponse record {|
map<json?> __extensions?;
record {|
int? id;
string? folder_id;
string? nic_front_id;
string? nic_back_id;
string? birth_certificate_front_id;
string? birth_certificate_back_id;
string? ol_certificate_id;
string? al_certificate_id;
string? additional_certificate_01_id;
string? additional_certificate_02_id;
string? additional_certificate_03_id;
string? additional_certificate_04_id;
string? additional_certificate_05_id;
|}? upload_document;
|};
23 changes: 23 additions & 0 deletions campus/bffs/enrollment/graphql_client/enrollment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ query getPersonById($id: Int!) {
created_by
updated_by
current_job
document_list {
document
document_type
}
}
}

Expand Down Expand Up @@ -384,5 +388,24 @@ mutation insertPerson(
created_by
updated_by
current_job
documents_id
}
}

mutation uploadDocument($user_document: UserDocument!) {
upload_document(user_document: $user_document) {
id
folder_id
nic_front_id
nic_back_id
birth_certificate_front_id
birth_certificate_back_id
ol_certificate_id
al_certificate_id
additional_certificate_01_id
additional_certificate_02_id
additional_certificate_03_id
additional_certificate_04_id
additional_certificate_05_id
}
}
Loading

0 comments on commit 3a0fc0a

Please sign in to comment.