Skip to content

Commit

Permalink
Merge pull request #377 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
consumable dashboard frontend changes added
  • Loading branch information
YujithIsura authored Aug 13, 2024
2 parents 28edf60 + 43efe3a commit bc77a40
Show file tree
Hide file tree
Showing 23 changed files with 1,491 additions and 18 deletions.
2 changes: 1 addition & 1 deletion campus/bffs/asset/api/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.5.0"
[[package]]
org = "avinyafoundation"
name = "asset_bff"
version = "0.1.0"
version = "1.1.0"
dependencies = [
{org = "ballerina", name = "graphql"},
{org = "ballerina", name = "http"},
Expand Down
9 changes: 8 additions & 1 deletion campus/bffs/asset/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public isolated client class GraphqlClient {
}

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}}`;
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 is_below_threshold 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);
Expand Down Expand Up @@ -372,4 +372,11 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableMonthlyReportResponse>check performDataBinding(graphqlResponse, GetConsumableMonthlyReportResponse);
}

remote isolated function getConsumableYearlyReport(int consumable_id, int year, int organization_id) returns GetConsumableYearlyReportResponse|graphql:ClientError {
string query = string `query getConsumableYearlyReport($organization_id:Int!,$consumable_id:Int!,$year:Int!) {consumable_yearly_report(organization_id:$organization_id,consumable_id:$consumable_id,year:$year) {consumable {id name} month_name quantity_in quantity_out resource_property {id property value}}}`;
map<anydata> variables = {"consumable_id": consumable_id, "year": year, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableYearlyReportResponse> check performDataBinding(graphqlResponse, GetConsumableYearlyReportResponse);
}
}
24 changes: 24 additions & 0 deletions campus/bffs/asset/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -859,4 +859,28 @@ service / on new http:Listener(9094) {
":: Detail: " + getConsumableMonthlyReportResponse.detail().toString());
}
}

resource function get consumable_yearly_report/[int organization_id]/[int consumable_id]/[int year]() returns Inventory[]|error {
GetConsumableYearlyReportResponse|graphql:ClientError getConsumableYearlyReportResponse = globalDataClient->getConsumableYearlyReport(consumable_id,year,organization_id);
if (getConsumableYearlyReportResponse is GetConsumableYearlyReportResponse) {
Inventory[] yearly_summary_consumable_datas = [];
foreach var yearly_summary_consumable_data in getConsumableYearlyReportResponse.consumable_yearly_report {
Inventory|error yearly_summary_consumable_data_record = yearly_summary_consumable_data.cloneWithType(Inventory);
if (yearly_summary_consumable_data_record is Inventory) {
yearly_summary_consumable_datas.push(yearly_summary_consumable_data_record);
} else {
log:printError("Error while processing Application record received", yearly_summary_consumable_data_record);
return error("Error while processing Application record received: " + yearly_summary_consumable_data_record.message() +
":: Detail: " + yearly_summary_consumable_data_record.detail().toString());
}
}

return yearly_summary_consumable_datas;

} else {
log:printError("Error while getting application", getConsumableYearlyReportResponse);
return error("Error while getting application: " + getConsumableYearlyReportResponse.message() +
":: Detail: " + getConsumableYearlyReportResponse.detail().toString());
}
}
}
22 changes: 22 additions & 0 deletions campus/bffs/asset/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public type Consumable record {
string? description?;
string? model?;
string? serial_number?;
anydata? threshold?;
int? id?;
string? updated?;
string? record_type?;
Expand Down Expand Up @@ -234,13 +235,15 @@ public type EvaluationMetadata record {
// int? person_id?;
// };
public type Inventory record {
string? month_name?;
int? consumable_id?;
anydata? quantity?;
string? created?;
anydata? prev_quantity?;
int? avinya_type_id?;
string? description?;
int? asset_id?;
int? is_below_threshold?;
string? record_type?;
string? manufacturer?;
anydata? quantity_out?;
Expand Down Expand Up @@ -1094,6 +1097,7 @@ public type GetInventoryDataByOrganizationResponse record {|
anydata? quantity_in;
anydata? quantity_out;
anydata? prev_quantity;
int? is_below_threshold;
record {|
int? id;
string? property;
Expand Down Expand Up @@ -1149,4 +1153,22 @@ public type GetConsumableMonthlyReportResponse record {|
string? value;
|}? resource_property;
|}[] consumable_monthly_report;
|};

public type GetConsumableYearlyReportResponse record {|
map<json?> __extensions?;
record {|
record {|
int? id;
string? name;
|}? consumable;
string? month_name;
anydata? quantity_in;
anydata? quantity_out;
record {|
int? id;
string? property;
string? value;
|}? resource_property;
|}[] consumable_yearly_report;
|};
18 changes: 18 additions & 0 deletions campus/bffs/asset/graphql_client/asset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ query getInventoryDataByOrganization($organization_id: Int!,$date: String!) {
quantity_in
quantity_out
prev_quantity
is_below_threshold
resource_property{
id
property
Expand Down Expand Up @@ -708,4 +709,21 @@ query getConsumableMonthlyReport($organization_id: Int!,$year: Int!,$month: Int!
value
}
}
}

query getConsumableYearlyReport($organization_id: Int!,$consumable_id: Int!,$year: Int!) {
consumable_yearly_report(organization_id: $organization_id,consumable_id: $consumable_id,year: $year) {
consumable{
id
name
}
month_name
quantity_in
quantity_out
resource_property{
id
property
value
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public isolated client class GraphqlClient {
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}}`;
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 is_below_threshold 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);
Expand All @@ -249,4 +249,10 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableMonthlyReportResponse> check performDataBinding(graphqlResponse, GetConsumableMonthlyReportResponse);
}
remote isolated function getConsumableYearlyReport(int consumable_id, int year, int organization_id) returns GetConsumableYearlyReportResponse|graphql:ClientError {
string query = string `query getConsumableYearlyReport($organization_id:Int!,$consumable_id:Int!,$year:Int!) {consumable_yearly_report(organization_id:$organization_id,consumable_id:$consumable_id,year:$year) {consumable {id name} month_name quantity_in quantity_out resource_property {id property value}}}`;
map<anydata> variables = {"consumable_id": consumable_id, "year": year, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableYearlyReportResponse> check performDataBinding(graphqlResponse, GetConsumableYearlyReportResponse);
}
}
24 changes: 23 additions & 1 deletion campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public type Consumable record {
string? description?;
string? model?;
string? serial_number?;
anydata? threshold?;
int? id?;
string? updated?;
string? record_type?;
Expand Down Expand Up @@ -238,13 +239,15 @@ public type EvaluationMetadata record {
};

public type Inventory record {
string? month_name?;
int? consumable_id?;
anydata? quantity?;
string? created?;
anydata? prev_quantity?;
int? avinya_type_id?;
string? description?;
int? asset_id?;
int? is_below_threshold?;
string? record_type?;
string? manufacturer?;
anydata? quantity_out?;
Expand Down Expand Up @@ -557,7 +560,7 @@ public type GetConsumablesResponse record {|
string? manufacturer;
string? model;
string? serial_number;
|}[] consumables;
|}[]? consumables;
|};

public type AddConsumableResponse record {|
Expand Down Expand Up @@ -1100,6 +1103,7 @@ public type GetInventoryDataByOrganizationResponse record {|
anydata? quantity_in;
anydata? quantity_out;
anydata? prev_quantity;
int? is_below_threshold;
record {|
int? id;
string? property;
Expand Down Expand Up @@ -1156,3 +1160,21 @@ public type GetConsumableMonthlyReportResponse record {|
|}? resource_property;
|}[]? consumable_monthly_report;
|};

public type GetConsumableYearlyReportResponse record {|
map<json?> __extensions?;
record {|
record {|
int? id;
string? name;
|}? consumable;
string? month_name;
anydata? quantity_in;
anydata? quantity_out;
record {|
int? id;
string? property;
string? value;
|}? resource_property;
|}[]? consumable_yearly_report;
|};
9 changes: 8 additions & 1 deletion campus/bffs/asset/graphql_client/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ input Consumable {
manufacturer: String
model: String
serial_number: String
threshold: Decimal
created: String
updated: String
}
Expand All @@ -339,6 +340,7 @@ type ConsumableData {
manufacturer: String
model: String
serial_number: String
threshold: Decimal
created: String
updated: String
}
Expand Down Expand Up @@ -547,6 +549,7 @@ input Inventory {
asset_id: Int
consumable_id: Int
name: String
month_name: String
description: String
manufacturer: String
organization_id: Int
Expand All @@ -557,6 +560,7 @@ input Inventory {
prev_quantity: Decimal
resource_property_id: Int
resource_property_value: String
is_below_threshold: Int
created: String
updated: String
}
Expand All @@ -576,8 +580,10 @@ type InventoryData {
prev_quantity: Decimal
resource_property: ResourcePropertyData
name: String
month_name: String
description: String
manufacturer: String
is_below_threshold: Int
created: String
updated: String
}
Expand Down Expand Up @@ -872,7 +878,7 @@ type Query {
suppliers: [SupplierData!]!
consumable(id: Int!): ConsumableData
consumableByUpdate(updated: String, avinya_type_id: Int): [ConsumableData!]
consumables: [ConsumableData!]!
consumables: [ConsumableData!]
activeActivityInstance: [ActivityInstanceData!]!
resource_property(id: Int!): ResourcePropertyData
resource_properties: [ResourcePropertyData!]!
Expand All @@ -899,6 +905,7 @@ type Query {
inventory_data_by_organization(organization_id: Int, date: String = ""): [InventoryData!]
consumable_weekly_report(organization_id: Int, from_date: String = "", to_date: String = ""): [InventoryData!]
consumable_monthly_report(organization_id: Int, year: Int, month: Int): [InventoryData!]
consumable_yearly_report(organization_id: Int, consumable_id: Int, year: Int): [InventoryData!]
}

input ResourceAllocation {
Expand Down
Loading

0 comments on commit bc77a40

Please sign in to comment.