Skip to content

Commit

Permalink
Merge pull request #398 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
Vehicle fuel consumption bff changes added
  • Loading branch information
YujithIsura authored Sep 10, 2024
2 parents a965f9d + e4223ff commit 2a19e17
Show file tree
Hide file tree
Showing 9 changed files with 1,150 additions and 112 deletions.
48 changes: 48 additions & 0 deletions campus/bffs/asset/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,52 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableYearlyReportResponse> check performDataBinding(graphqlResponse, GetConsumableYearlyReportResponse);
}

remote isolated function addVehicleFuelConsumption(VehicleFuelConsumption vehicleFuelConsumption) returns AddVehicleFuelConsumptionResponse|graphql:ClientError {
string query = string `mutation addVehicleFuelConsumption($vehicleFuelConsumption:VehicleFuelConsumption!) {add_vehicle_fuel_consumption(vehicle_fuel_consumption:$vehicleFuelConsumption) {id vehicle_id date_time reason_id starting_meter ending_meter distance comment}}`;
map<anydata> variables = {"vehicleFuelConsumption": vehicleFuelConsumption};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <AddVehicleFuelConsumptionResponse>check performDataBinding(graphqlResponse, AddVehicleFuelConsumptionResponse);
}
remote isolated function updateVehicleFuelConsumption(VehicleFuelConsumption vehicleFuelConsumption) returns UpdateVehicleFuelConsumptionResponse|graphql:ClientError {
string query = string `mutation updateVehicleFuelConsumption($vehicleFuelConsumption:VehicleFuelConsumption!) {update_vehicle_fuel_consumption(vehicle_fuel_consumption:$vehicleFuelConsumption) {id vehicle_id date_time reason_id starting_meter ending_meter distance comment}}`;
map<anydata> variables = {"vehicleFuelConsumption": vehicleFuelConsumption};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <UpdateVehicleFuelConsumptionResponse>check performDataBinding(graphqlResponse, UpdateVehicleFuelConsumptionResponse);
}

remote isolated function deleteVehicleFuelConsumptionById(int id) returns json|error {
string query = string `mutation deleteVehicleFuelConsumptionById($id: Int!) {delete_vehicle_fuel_consumption_by_id(id:$id)}`;
map<anydata> variables = {"id": id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
map<json> responseMap = <map<json>>graphqlResponse;
json responseData = responseMap.get("data");
json|error row_count = check responseData.delete_vehicle_fuel_consumption_by_id;
return row_count;
}
remote isolated function getVehicleFuelConsumptionByDate(string date, int organization_id) returns GetVehicleFuelConsumptionByDateResponse|graphql:ClientError {
string query = string `query getVehicleFuelConsumptionByDate($organization_id:Int!,$date:String!) {vehicle_fuel_consumption_by_date(organization_id:$organization_id,date:$date) {id vehicle {id vehicle_number} date_time reason {id reason} starting_meter ending_meter distance comment created updated}}`;
map<anydata> variables = {"date": date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehicleFuelConsumptionByDateResponse>check performDataBinding(graphqlResponse, GetVehicleFuelConsumptionByDateResponse);
}
remote isolated function getVehicleFuelConsumptionById(int id) returns GetVehicleFuelConsumptionByIdResponse|graphql:ClientError {
string query = string `query getVehicleFuelConsumptionById($id:Int!) {vehicle_fuel_consumption_by_id(id:$id) {id vehicle {id vehicle_number} date_time reason {id reason} starting_meter ending_meter distance comment created updated}}`;
map<anydata> variables = {"id": id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehicleFuelConsumptionByIdResponse>check performDataBinding(graphqlResponse, GetVehicleFuelConsumptionByIdResponse);
}
remote isolated function getVehicles(int organization_id) returns GetVehiclesResponse|graphql:ClientError {
string query = string `query getVehicles($organization_id:Int!) {vehicles(organization_id:$organization_id) {id vehicle_number person {id preferred_name digital_id}}}`;
map<anydata> variables = {"organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehiclesResponse>check performDataBinding(graphqlResponse, GetVehiclesResponse);
}
remote isolated function getVehicleReasons() returns GetVehicleReasonsResponse|graphql:ClientError {
string query = string `query getVehicleReasons {vehicle_reasons {id reason}}`;
map<anydata> variables = {};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehicleReasonsResponse>check performDataBinding(graphqlResponse, GetVehicleReasonsResponse);
}

}
43 changes: 43 additions & 0 deletions campus/bffs/asset/api/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -883,4 +883,47 @@ service / on new http:Listener(9094) {
":: Detail: " + getConsumableYearlyReportResponse.detail().toString());
}
}

resource function post add_vehicle_fuel_consumption(@http:Payload VehicleFuelConsumption vehicleFuelConsumption) returns VehicleFuelConsumption|error {
AddVehicleFuelConsumptionResponse|graphql:ClientError addVehicleFuelConsumption = globalDataClient->addVehicleFuelConsumption(vehicleFuelConsumption);
if (addVehicleFuelConsumption is AddVehicleFuelConsumptionResponse) {
VehicleFuelConsumption|error vehicle_fuel_consumption_record = addVehicleFuelConsumption.add_vehicle_fuel_consumption.cloneWithType(VehicleFuelConsumption);
if (vehicle_fuel_consumption_record is VehicleFuelConsumption) {
return vehicle_fuel_consumption_record;
} else {
log:printError("Error while processing Application record received", vehicle_fuel_consumption_record);
return error("Error while processing Application record received: " + vehicle_fuel_consumption_record.message() +
":: Detail: " + vehicle_fuel_consumption_record.detail().toString());
}
} else {
log:printError("Error while creating application", addVehicleFuelConsumption);
return error("Error while creating application: " + addVehicleFuelConsumption.message() +
":: Detail: " + addVehicleFuelConsumption.detail().toString());
}
}

resource function get vehicle_fuel_consumption_by_date/[int organization_id]/[string date]() returns VehicleFuelConsumption[]|error {
GetVehicleFuelConsumptionByDateResponse|graphql:ClientError getVehicleFuelConsumptionByDateResponse = globalDataClient->getVehicleFuelConsumptionByDate(date, organization_id);
if (getVehicleFuelConsumptionByDateResponse is GetVehicleFuelConsumptionByDateResponse) {
VehicleFuelConsumption[] vehicle_fuel_consumption_by_date_datas = [];
foreach var vehicle_fuel_consumption_by_data in getVehicleFuelConsumptionByDateResponse.vehicle_fuel_consumption_by_date {
VehicleFuelConsumption|error vehicle_fuel_consumption_by_data_record = vehicle_fuel_consumption_by_data.cloneWithType(VehicleFuelConsumption);
if (vehicle_fuel_consumption_by_data_record is VehicleFuelConsumption) {
vehicle_fuel_consumption_by_date_datas.push(vehicle_fuel_consumption_by_data_record);
} else {
log:printError("Error while processing Application record received", vehicle_fuel_consumption_by_data_record);
return error("Error while processing Application record received: " + vehicle_fuel_consumption_by_data_record.message() +
":: Detail: " + vehicle_fuel_consumption_by_data_record.detail().toString());
}
}

return vehicle_fuel_consumption_by_date_datas;

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

}
109 changes: 108 additions & 1 deletion campus/bffs/asset/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ public type Vacancy record {
string? record_type?;
};

public type VehicleFuelConsumption record {
string? date_time?;
string? distance?;
string? starting_meter?;
string? created?;
string? ending_meter?;
string? comment?;
int? id?;
int? vehicle_id?;
string? updated?;
string? record_type?;
int? reason_id?;
};

public type WorkExperience record {
string? end_date?;
int[]? evaluation_id?;
Expand Down Expand Up @@ -1171,4 +1185,97 @@ public type GetConsumableYearlyReportResponse record {|
string? value;
|}? resource_property;
|}[] consumable_yearly_report;
|};
|};

public type AddVehicleFuelConsumptionResponse record {|
map<json?> __extensions?;
record {|
int? id;
int? vehicle_id;
string? date_time;
int? reason_id;
string? starting_meter;
string? ending_meter;
string? distance;
string? comment;
|}? add_vehicle_fuel_consumption;
|};

public type UpdateVehicleFuelConsumptionResponse record {|
map<json?> __extensions?;
record {|
int? id;
int? vehicle_id;
string? date_time;
int? reason_id;
string? starting_meter;
string? ending_meter;
string? distance;
string? comment;
|}? update_vehicle_fuel_consumption;
|};

public type GetVehicleFuelConsumptionByDateResponse record {|
map<json?> __extensions?;
record {|
int? id;
record {|
int? id;
string? vehicle_number;
|}? vehicle;
string? date_time;
record {|
int? id;
string? reason;
|}? reason;
string? starting_meter;
string? ending_meter;
string? distance;
string? comment;
string? created;
string? updated;
|}[] vehicle_fuel_consumption_by_date;
|};

public type GetVehicleFuelConsumptionByIdResponse record {|
map<json?> __extensions?;
record {|
int? id;
record {|
int? id;
string? vehicle_number;
|}? vehicle;
string? date_time;
record {|
int? id;
string? reason;
|}? reason;
string? starting_meter;
string? ending_meter;
string? distance;
string? comment;
string? created;
string? updated;
|}? vehicle_fuel_consumption_by_id;
|};

public type GetVehiclesResponse record {|
map<json?> __extensions?;
record {|
int? id;
string? vehicle_number;
record {|
int? id;
string? preferred_name;
string? digital_id;
|}? person;
|}[]? vehicles;
|};

public type GetVehicleReasonsResponse record {|
map<json?> __extensions?;
record {|
int? id;
string? reason;
|}[]? vehicle_reasons;
|};
89 changes: 88 additions & 1 deletion campus/bffs/asset/graphql_client/asset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -726,4 +726,91 @@ query getConsumableYearlyReport($organization_id: Int!,$consumable_id: Int!,$yea
value
}
}
}
}

mutation addVehicleFuelConsumption($vehicleFuelConsumption: VehicleFuelConsumption!) {
add_vehicle_fuel_consumption(vehicle_fuel_consumption:$vehicleFuelConsumption) {
id
vehicle_id
date_time
reason_id
starting_meter
ending_meter
distance
comment
}
}

mutation updateVehicleFuelConsumption($vehicleFuelConsumption: VehicleFuelConsumption!) {
update_vehicle_fuel_consumption(vehicle_fuel_consumption:$vehicleFuelConsumption) {
id
vehicle_id
date_time
reason_id
starting_meter
ending_meter
distance
comment
}
}

query getVehicleFuelConsumptionByDate($organization_id: Int!,$date: String!) {
vehicle_fuel_consumption_by_date(organization_id: $organization_id,date: $date) {
id
vehicle{
id
vehicle_number
}
date_time
reason{
id
reason
}
starting_meter
ending_meter
distance
comment
created
updated
}
}

query getVehicleFuelConsumptionById($id: Int!) {
vehicle_fuel_consumption_by_id(id: $id) {
id
vehicle{
id
vehicle_number
}
date_time
reason{
id
reason
}
starting_meter
ending_meter
distance
comment
created
updated
}
}

query getVehicles($organization_id: Int!) {
vehicles(organization_id: $organization_id) {
id
vehicle_number
person{
id
preferred_name
digital_id
}
}
}

query getVehicleReasons {
vehicle_reasons {
id
reason
}
}
36 changes: 36 additions & 0 deletions campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,40 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetConsumableYearlyReportResponse> check performDataBinding(graphqlResponse, GetConsumableYearlyReportResponse);
}
remote isolated function addVehicleFuelConsumption(VehicleFuelConsumption vehicleFuelConsumption) returns AddVehicleFuelConsumptionResponse|graphql:ClientError {
string query = string `mutation addVehicleFuelConsumption($vehicleFuelConsumption:VehicleFuelConsumption!) {add_vehicle_fuel_consumption(vehicle_fuel_consumption:$vehicleFuelConsumption) {id vehicle_id date_time reason_id starting_meter ending_meter distance comment}}`;
map<anydata> variables = {"vehicleFuelConsumption": vehicleFuelConsumption};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <AddVehicleFuelConsumptionResponse> check performDataBinding(graphqlResponse, AddVehicleFuelConsumptionResponse);
}
remote isolated function updateVehicleFuelConsumption(VehicleFuelConsumption vehicleFuelConsumption) returns UpdateVehicleFuelConsumptionResponse|graphql:ClientError {
string query = string `mutation updateVehicleFuelConsumption($vehicleFuelConsumption:VehicleFuelConsumption!) {update_vehicle_fuel_consumption(vehicle_fuel_consumption:$vehicleFuelConsumption) {id vehicle_id date_time reason_id starting_meter ending_meter distance comment}}`;
map<anydata> variables = {"vehicleFuelConsumption": vehicleFuelConsumption};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <UpdateVehicleFuelConsumptionResponse> check performDataBinding(graphqlResponse, UpdateVehicleFuelConsumptionResponse);
}
remote isolated function getVehicleFuelConsumptionByDate(string date, int organization_id) returns GetVehicleFuelConsumptionByDateResponse|graphql:ClientError {
string query = string `query getVehicleFuelConsumptionByDate($organization_id:Int!,$date:String!) {vehicle_fuel_consumption_by_date(organization_id:$organization_id,date:$date) {id vehicle {id vehicle_number} date_time reason {id reason} starting_meter ending_meter distance comment created updated}}`;
map<anydata> variables = {"date": date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehicleFuelConsumptionByDateResponse> check performDataBinding(graphqlResponse, GetVehicleFuelConsumptionByDateResponse);
}
remote isolated function getVehicleFuelConsumptionById(int id) returns GetVehicleFuelConsumptionByIdResponse|graphql:ClientError {
string query = string `query getVehicleFuelConsumptionById($id:Int!) {vehicle_fuel_consumption_by_id(id:$id) {id vehicle {id vehicle_number} date_time reason {id reason} starting_meter ending_meter distance comment created updated}}`;
map<anydata> variables = {"id": id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehicleFuelConsumptionByIdResponse> check performDataBinding(graphqlResponse, GetVehicleFuelConsumptionByIdResponse);
}
remote isolated function getVehicles(int organization_id) returns GetVehiclesResponse|graphql:ClientError {
string query = string `query getVehicles($organization_id:Int!) {vehicles(organization_id:$organization_id) {id vehicle_number person {id preferred_name digital_id}}}`;
map<anydata> variables = {"organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehiclesResponse> check performDataBinding(graphqlResponse, GetVehiclesResponse);
}
remote isolated function getVehicleReasons() returns GetVehicleReasonsResponse|graphql:ClientError {
string query = string `query getVehicleReasons {vehicle_reasons {id reason}}`;
map<anydata> variables = {};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetVehicleReasonsResponse> check performDataBinding(graphqlResponse, GetVehicleReasonsResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/graphql;

# Client configuration details.
Expand Down
Loading

0 comments on commit 2a19e17

Please sign in to comment.