Skip to content

Commit

Permalink
Merge pull request #361 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
Asset inventory add api function bff changes added
  • Loading branch information
YujithIsura authored Jun 12, 2024
2 parents 2c3f61a + 4292a97 commit 794a8d3
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 52 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 @@ -103,7 +103,7 @@ modules = [
[[package]]
org = "ballerina"
name = "http"
version = "2.8.6"
version = "2.8.7"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "cache"},
Expand Down
58 changes: 58 additions & 0 deletions campus/bffs/asset/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,62 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetInventoryDataByOrganizationResponse>check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse);
}

remote isolated function consumableReplenishment(Inventory[] inventories) returns json|graphql:ClientError {
string query = string `mutation consumableReplenishment($inventories: [Inventory!]!)
{
consumable_replenishment(inventories:$inventories)
{
id
avinya_type{
id
global_type
name
}
consumable{
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 consumableDepletion(Inventory[] inventories) returns json|graphql:ClientError {
string query = string ` mutation consumableDepletion($inventories: [Inventory!]!)
{
consumable_depletion(inventories:$inventories)
{
id
avinya_type{
id
global_type
name
}
consumable{
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;
}
}
25 changes: 24 additions & 1 deletion campus/bffs/asset/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,29 @@ service / on new http:Listener(9094) {
":: Detail: " + getInventoryDataByOrganizationResponse.detail().toString());
}
}
resource function post consumable_replenishment(@http:Payload Inventory[] inventories) returns json|error {

json|graphql:ClientError createInventoryResponse = globalDataClient->consumableReplenishment(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(@http:Payload Inventory[] inventories) returns json|error {

json|graphql:ClientError inventoryDepletionResponse = globalDataClient->consumableDepletion(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());
}
}
}
56 changes: 38 additions & 18 deletions campus/bffs/asset/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,37 @@ public type EvaluationMetadata record {
string? status?;
};

// public type Inventory record {
// int? consumable_id?;
// anydata? quantity?;
// string? created?;
// int? avinya_type_id?;
// string? description?;
// int? asset_id?;
// string? record_type?;
// string? manufacturer?;
// anydata? quantity_out?;
// int? resource_property_id?;
// anydata? quantity_in?;
// int? organization_id?;
// string? name?;
// int? id?;
// string? updated?;
// string? resource_property_value?;
// int? person_id?;
// };
public type Inventory record {
int? consumable_id?;
int? quantity?;
decimal? quantity?;
string? created?;
int? avinya_type_id?;
string? description?;
int? asset_id?;
string? record_type?;
string? manufacturer?;
int? quantity_out?;
decimal? quantity_out?;
int? resource_property_id?;
int? quantity_in?;
decimal? quantity_in?;
int? organization_id?;
string? name?;
int? id?;
Expand All @@ -234,6 +253,7 @@ public type Inventory record {
int? person_id?;
};


public type Organization record {
int[]? parent_organizations?;
string? notes?;
Expand Down Expand Up @@ -876,9 +896,9 @@ public type GetInventoryResponse record {|
string? name;
|}? avinya_type;
int? avinya_type_id;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}? inventory;
|};

Expand Down Expand Up @@ -909,9 +929,9 @@ public type GetInventoriesResponse record {|
string? name;
|}? avinya_type;
int? avinya_type_id;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}[] inventories;
|};

Expand All @@ -934,9 +954,9 @@ public type AddInventoryResponse record {|
record {|
int? id;
|}? avinya_type;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}? add_inventory;
|};

Expand All @@ -959,9 +979,9 @@ public type UpdateInventoryResponse record {|
record {|
int? id;
|}? avinya_type;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}? update_inventory;
|};

Expand Down Expand Up @@ -1071,9 +1091,9 @@ public type GetInventoryDataByOrganizationResponse record {|
string? name;
string? manufacturer;
string? description;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
record {|
int? id;
string? property;
Expand Down
36 changes: 18 additions & 18 deletions campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ public type EvaluationMetadata record {

public type Inventory record {
int? consumable_id?;
int? quantity?;
anydata? quantity?;
string? created?;
int? avinya_type_id?;
string? description?;
int? asset_id?;
string? record_type?;
string? manufacturer?;
int? quantity_out?;
anydata? quantity_out?;
int? resource_property_id?;
int? quantity_in?;
anydata? quantity_in?;
int? organization_id?;
string? name?;
int? id?;
Expand Down Expand Up @@ -902,9 +902,9 @@ public type GetInventoryResponse record {|
string? name;
|}? avinya_type;
int? avinya_type_id;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}? inventory;
|};

Expand Down Expand Up @@ -935,9 +935,9 @@ public type GetInventoriesResponse record {|
string? name;
|}? avinya_type;
int? avinya_type_id;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}[] inventories;
|};

Expand All @@ -960,9 +960,9 @@ public type AddInventoryResponse record {|
record {|
int? id;
|}? avinya_type;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}? add_inventory;
|};

Expand All @@ -985,9 +985,9 @@ public type UpdateInventoryResponse record {|
record {|
int? id;
|}? avinya_type;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
|}? update_inventory;
|};

Expand Down Expand Up @@ -1097,9 +1097,9 @@ public type GetInventoryDataByOrganizationResponse record {|
string? name;
string? manufacturer;
string? description;
int? quantity;
int? quantity_in;
int? quantity_out;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
record {|
int? id;
string? property;
Expand Down
14 changes: 8 additions & 6 deletions campus/bffs/asset/graphql_client/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ input Inventory {
manufacturer: String
organization_id: Int
person_id: Int
quantity: Int
quantity_in: Int
quantity_out: Int
quantity: Decimal
quantity_in: Decimal
quantity_out: Decimal
resource_property_id: Int
resource_property_value: String
created: String
Expand All @@ -568,9 +568,9 @@ type InventoryData {
consumable: ConsumableData
organization: OrganizationData
person: PersonData
quantity: Int
quantity_in: Int
quantity_out: Int
quantity: Decimal
quantity_in: Decimal
quantity_out: Decimal
resource_property: ResourcePropertyData
name: String
description: String
Expand Down Expand Up @@ -639,6 +639,8 @@ type Mutation {
update_duty_rotation_metadata(duty_rotation: DutyRotationMetaDetails!): DutyRotationMetaData
add_duty_attendance(duty_attendance: ActivityParticipantAttendance!): ActivityParticipantAttendanceData
add_duty_evaluation(duty_evaluation: Evaluation!): EvaluationData
consumable_replenishment(inventories: [Inventory!]!): [InventoryData!]
consumable_depletion(inventories: [Inventory!]!): [InventoryData!]
}

input Organization {
Expand Down
Loading

0 comments on commit 794a8d3

Please sign in to comment.