Skip to content

Commit

Permalink
Merge pull request #376 from avinyafoundation/main
Browse files Browse the repository at this point in the history
consumable module completed
  • Loading branch information
YujithIsura authored Jul 24, 2024
2 parents 7789b86 + d26001c commit df60379
Show file tree
Hide file tree
Showing 40 changed files with 6,461 additions and 510 deletions.
4 changes: 2 additions & 2 deletions campus/bffs/asset/api/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
org = "avinyafoundation"
name = "asset_bff"
version = "0.1.0"
distribution = "2201.3.5"
version = "1.1.0"
distribution = "2201.5.0"

[build-options]
observabilityIncluded = true
2 changes: 1 addition & 1 deletion campus/bffs/asset/api/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.3"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down
141 changes: 141 additions & 0 deletions campus/bffs/asset/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,145 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetAvinyaTypesResponse> check performDataBinding(graphqlResponse, GetAvinyaTypesResponse);
}

remote isolated function getInventoryDataByOrganization(string date, int organization_id) returns GetInventoryDataByOrganizationResponse|graphql:ClientError {
string query = string `query getInventoryDataByOrganization($organization_id:Int!,$date:String!) {inventory_data_by_organization(organization_id:$organization_id,date:$date) {id avinya_type_id consumable_id consumable {id name} quantity quantity_in quantity_out prev_quantity resource_property {id property value} created updated}}`;
map<anydata> variables = {"date": date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetInventoryDataByOrganizationResponse>check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse);
}

remote isolated function consumableReplenishment(int person_id,int organization_id,string date,Inventory[] inventories) returns json|graphql:ClientError {
string query = string ` mutation consumableReplenishment(
$person_id: Int!,
$organization_id: Int!,
$date: String!,
$inventories: [Inventory!]!)
{
consumable_replenishment(
person_id:$person_id,
organization_id:$organization_id,
date:$date,
inventories:$inventories)
{
id
avinya_type_id
consumable_id
quantity
quantity_in
quantity_out
prev_quantity
created
updated
}
}`;

map<anydata> variables = {"person_id": person_id, "organization_id": organization_id, "date": date, "inventories": inventories};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return graphqlResponse;
}

remote isolated function consumableDepletion(int person_id,int organization_id,string date,Inventory[] inventories) returns json|graphql:ClientError {
string query = string ` mutation consumableDepletion(
$person_id: Int!,
$organization_id: Int!,
$date: String!,
$inventories: [Inventory!]!)
{
consumable_depletion(
person_id:$person_id,
organization_id:$organization_id,
date:$date,
inventories:$inventories)
{
id
avinya_type_id
consumable_id
quantity
quantity_in
quantity_out
prev_quantity
created
updated
}
}`;
map<anydata> variables = {"person_id": person_id, "organization_id": organization_id, "date": date, "inventories": inventories};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);

return graphqlResponse;
}

remote isolated function getConsumableWeeklyReport(string from_date, string to_date, int organization_id) returns GetConsumableWeeklyReportResponse|graphql:ClientError {
string query = string `query getConsumableWeeklyReport($organization_id:Int!,$from_date:String!,$to_date:String!) {consumable_weekly_report(organization_id:$organization_id,from_date:$from_date,to_date:$to_date) {id avinya_type {id global_type name} consumable {id name description manufacturer} prev_quantity quantity_in quantity_out resource_property {id property value} updated}}`;
map<anydata> variables = {"from_date": from_date, "to_date": to_date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableWeeklyReportResponse>check performDataBinding(graphqlResponse, GetConsumableWeeklyReportResponse);
}

remote isolated function updateConsumableReplenishment(Inventory[] inventories) returns json|graphql:ClientError {
string query = string `mutation updateConsumableReplenishment($inventories: [Inventory!]!)
{
update_consumable_replenishment(inventories:$inventories)
{
id
avinya_type{
id
global_type
name
}
consumable{
id
name
description
manufacturer
}
quantity
quantity_in
quantity_out
created
updated
}
}`;
map<anydata> variables = {"inventories": inventories};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);

return graphqlResponse;
}

remote isolated function updateConsumableDepletion(Inventory[] inventories) returns json|graphql:ClientError {
string query = string `mutation updateConsumableDepletion($inventories: [Inventory!]!)
{
update_consumable_depletion(inventories:$inventories)
{
id
avinya_type{
id
global_type
name
}
consumable{
id
name
description
manufacturer
}
quantity
quantity_in
quantity_out
created
updated
}
}`;
map<anydata> variables = {"inventories": inventories};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);

return graphqlResponse;
}

remote isolated function getConsumableMonthlyReport(int month, int year, int organization_id) returns GetConsumableMonthlyReportResponse|graphql:ClientError {
string query = string `query getConsumableMonthlyReport($organization_id:Int!,$year:Int!,$month:Int!) {consumable_monthly_report(organization_id:$organization_id,year:$year,month:$month) {consumable {id name description manufacturer} quantity quantity_in quantity_out resource_property {id property value}}}`;
map<anydata> variables = {"month": month, "year": year, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableMonthlyReportResponse>check performDataBinding(graphqlResponse, GetConsumableMonthlyReportResponse);
}
}
121 changes: 121 additions & 0 deletions campus/bffs/asset/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -733,5 +733,126 @@ service / on new http:Listener(9094) {
}
}

resource function get inventory_data_by_organization/[int organization_id]/[string date]() returns Inventory[]|error {
GetInventoryDataByOrganizationResponse|graphql:ClientError getInventoryDataByOrganizationResponse = globalDataClient->getInventoryDataByOrganization(date,organization_id);
if (getInventoryDataByOrganizationResponse is GetInventoryDataByOrganizationResponse) {
Inventory[] inventory_datas = [];
foreach var inventory_data in getInventoryDataByOrganizationResponse.inventory_data_by_organization {
Inventory|error inventory_data_record = inventory_data.cloneWithType(Inventory);
if (inventory_data_record is Inventory) {
inventory_datas.push(inventory_data_record);
} else {
log:printError("Error while processing Application record received", inventory_data_record);
return error("Error while processing Application record received: " + inventory_data_record.message() +
":: Detail: " + inventory_data_record.detail().toString());
}
}

return inventory_datas;

} else {
log:printError("Error while getting application", getInventoryDataByOrganizationResponse);
return error("Error while getting application: " + getInventoryDataByOrganizationResponse.message() +
":: Detail: " + getInventoryDataByOrganizationResponse.detail().toString());
}
}
resource function post consumable_replenishment/[int person_id]/[int organization_id]/[string date](@http:Payload Inventory[] inventories) returns json|error {

json|graphql:ClientError createInventoryResponse = globalDataClient->consumableReplenishment(person_id,organization_id,date,inventories);
if(createInventoryResponse is json) {
log:printInfo("Inventories created successfully: " + createInventoryResponse.toString());
return createInventoryResponse;
} else {
log:printError("Error while creating inventories", createInventoryResponse);
return error("Error while creating inventories: " + createInventoryResponse.message() +
":: Detail: " + createInventoryResponse.detail().toString());
}
}

resource function post consumable_depletion/[int person_id]/[int organization_id]/[string date](@http:Payload Inventory[] inventories) returns json|error {

json|graphql:ClientError inventoryDepletionResponse = globalDataClient->consumableDepletion(person_id,organization_id,date,inventories);
if(inventoryDepletionResponse is json) {
log:printInfo("Inventories depleted successfully: " + inventoryDepletionResponse.toString());
return inventoryDepletionResponse;
} else {
log:printError("Error while depletion inventories", inventoryDepletionResponse);
return error("Error while depletion inventories: " + inventoryDepletionResponse.message() +
":: Detail: " + inventoryDepletionResponse.detail().toString());
}
}

resource function get consumable_weekly_report/[int organization_id]/[string from_date]/[string to_date]() returns Inventory[]|error {
GetConsumableWeeklyReportResponse|graphql:ClientError getConsumableWeeklyReportResponse = globalDataClient->getConsumableWeeklyReport(from_date,to_date,organization_id);
if (getConsumableWeeklyReportResponse is GetConsumableWeeklyReportResponse) {
Inventory[] weekly_summary_inventory_datas = [];
foreach var weekly_summary_inventory_data in getConsumableWeeklyReportResponse.consumable_weekly_report {
Inventory|error weekly_summary_inventory_data_record = weekly_summary_inventory_data.cloneWithType(Inventory);
if (weekly_summary_inventory_data_record is Inventory) {
weekly_summary_inventory_datas.push(weekly_summary_inventory_data_record);
} else {
log:printError("Error while processing Application record received", weekly_summary_inventory_data_record);
return error("Error while processing Application record received: " + weekly_summary_inventory_data_record.message() +
":: Detail: " + weekly_summary_inventory_data_record.detail().toString());
}
}

return weekly_summary_inventory_datas;

} else {
log:printError("Error while getting application", getConsumableWeeklyReportResponse);
return error("Error while getting application: " + getConsumableWeeklyReportResponse.message() +
":: Detail: " + getConsumableWeeklyReportResponse.detail().toString());
}
}

resource function put consumable_replenishment(@http:Payload Inventory[] inventories) returns json|error {

json|graphql:ClientError updateConsumableReplenishmentResponse = globalDataClient->updateConsumableReplenishment(inventories);
if (updateConsumableReplenishmentResponse is json) {
log:printInfo("Consumables updated successfully: " + updateConsumableReplenishmentResponse.toString());
return updateConsumableReplenishmentResponse;
} else {
log:printError("Error while updating consumbales", updateConsumableReplenishmentResponse);
return error("Error while updating consumbales: " + updateConsumableReplenishmentResponse.message() +
":: Detail: " + updateConsumableReplenishmentResponse.detail().toString());
}
}

resource function put consumable_depletion(@http:Payload Inventory[] inventories) returns json|error {

json|graphql:ClientError updateConsumableDepletionResponse = globalDataClient->updateConsumableDepletion(inventories);
if (updateConsumableDepletionResponse is json) {
log:printInfo("Consumables updated successfully: " + updateConsumableDepletionResponse.toString());
return updateConsumableDepletionResponse;
} else {
log:printError("Error while updating consumbales", updateConsumableDepletionResponse);
return error("Error while updating consumbales: " + updateConsumableDepletionResponse.message() +
":: Detail: " + updateConsumableDepletionResponse.detail().toString());
}
}

resource function get consumable_monthly_report/[int organization_id]/[int year]/[int month]() returns Inventory[]|error {
GetConsumableMonthlyReportResponse|graphql:ClientError getConsumableMonthlyReportResponse = globalDataClient->getConsumableMonthlyReport(month,year,organization_id);
if (getConsumableMonthlyReportResponse is GetConsumableMonthlyReportResponse) {
Inventory[] monthly_summary_consumable_datas = [];
foreach var monthly_summary_consumable_data in getConsumableMonthlyReportResponse.consumable_monthly_report {
Inventory|error monthly_summary_consumable_data_record = monthly_summary_consumable_data.cloneWithType(Inventory);
if (monthly_summary_consumable_data_record is Inventory) {
monthly_summary_consumable_datas.push(monthly_summary_consumable_data_record);
} else {
log:printError("Error while processing Application record received", monthly_summary_consumable_data_record);
return error("Error while processing Application record received: " + monthly_summary_consumable_data_record.message() +
":: Detail: " + monthly_summary_consumable_data_record.detail().toString());
}
}

return monthly_summary_consumable_datas;

} else {
log:printError("Error while getting application", getConsumableMonthlyReportResponse);
return error("Error while getting application: " + getConsumableMonthlyReportResponse.message() +
":: Detail: " + getConsumableMonthlyReportResponse.detail().toString());
}
}
}
Loading

0 comments on commit df60379

Please sign in to comment.